This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Copyright (c) Rich Hickey. All rights reserved. | |
; The use and distribution terms for this software are covered by the | |
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
; which can be found in the file epl-v10.html at the root of this distribution. | |
; By using this software in any fashion, you are agreeing to be bound by | |
; the terms of this license. | |
; You must not remove this notice, or any other, from this software. | |
(set! *warn-on-reflection* true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns fj | |
(:import [java.util.concurrent RecursiveTask | |
ForkJoinPool])) | |
(set! *warn-on-reflection* true) | |
;; ----------------------------------------------- | |
;; Helpers to provide an idiomatic interface to FJ | |
(defprotocol IFJTask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns dcg | |
(:refer-clojure :exclude [reify == inc]) | |
(:use (clojure.core.logic minikanren prelude))) | |
(declare sentence noun-phrase verb-phrase det noun verb) | |
(defn sentence [s1 s3] | |
(exist [s2] | |
(noun-phrase s1 s2) | |
(verb-phrase s2 s3))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns logic.y | |
(:refer-clojure :exclude [== reify inc]) | |
(:use [clojure.core.logic minikanren prelude | |
nonrel match])) | |
(defna findo [x l o] | |
([_ [[?y :- o] . _] _] | |
(project [x ?y] (== (= x ?y) true))) | |
([_ [_ . ?c] _] (findo x ?c o))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def denoms [2000 1000 500 100 25 10 5 1]) | |
(defn make-change | |
([amt] (make-change amt denoms {})) | |
([amt denoms r] | |
(if (zero? amt) | |
r | |
(let [[f :as denoms] (drop-while #(> % amt) denoms) | |
[n amt] ((juxt quot rem) amt f)] | |
(recur amt denoms (assoc-in r [f] n)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; (match [x y z] | |
;; [_ f# t#] 1 | |
;; [f# t# _ ] 2 | |
;; [_ _ f#] 3 | |
;; [_ _ t#] 4) | |
(def pm2 (pattern-matrix [(pattern-row [wildcard (pattern false) (pattern true)] :a1) | |
(pattern-row [(pattern false) (pattern true) wildcard] :a2) | |
(pattern-row [wildcard wildcard (pattern false)] :a3) | |
(pattern-row [wildcard wildcard (pattern true)] :a4)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defne assoco [m k v o] | |
([[] _ _ [[k v]]]) | |
([[[k v] . _] _ _ m]) | |
([[[k ?v] . ?r] _ _ [[k v] . ?r]] | |
(!= m o)) | |
([[[?j v]] _ _ [[?j v] [k v]]] | |
(!= ?j k)) | |
([[[?j ?u] . ?r] _ _ [[?j ?u] . ?o]] | |
(!= ?j k) | |
(!= m o) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns clojure.core.logic.assoco | |
(:refer-clojure :exclude [== reify inc not]) | |
(:use [clojure.core.logic minikanren prelude match disequality])) | |
;; defining assoc as a pure relation | |
;; a good example of the non-overlapping | |
;; clauses property. A given map can match | |
;; only one of the these clauses. | |
(defne assoco [m k v o] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package demo | |
class Coder(words: List[String]) { | |
private val mnemonics = Map( | |
'2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL", | |
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ") | |
private val charCode: Map[Char, Char] = | |
for ((digit, str) <- mnemonics; letter <- str) yield letter -> digit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(deftyped | |
addInteger | |
[Integer :> [Integer :> Integer]] | |
[x y] | |
(+ x y)) | |
(deftyped | |
addDouble | |
[Double :> [Double :> Double]] |
OlderNewer