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
#lang typed/racket | |
(: stx Syntax) | |
(define stx #'bar) | |
(syntax-case stx () | |
[foo (identifier? #'foo) (symbol=? 'bar (syntax-e #'foo))] | |
[_ (error 'whoops)]) |
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
;; Evolving a logic programming language | |
;; Based on sketches at https://github.com/frenchy64/Logic-Starter/blob/master/src/logic_introduction/decl_model.clj | |
;; A logic statement reduces to true or false. | |
true | |
;=> true | |
false | |
;=> false |
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
(def-->e verb [v] | |
([[:v 'eats]] '[eats])) | |
(def-->e noun [n] | |
([[:n 'bat]] '[bat]) | |
([[:n 'cat]] '[cat])) | |
(def-->e det [d] | |
([[:d 'the]] '[the]) | |
([[:d 'a]] '[a])) |
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 geto [k m v] | |
([_ [[k :- v] . _] _]) | |
([_ [_ . ?r] _] (geto k ?r v))) | |
(defn typedo [c x t] | |
(conde | |
((geto x c t)) | |
((matche [c x t] | |
([_ [:apply ?a ?b] _] | |
(exist [s nc] |
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
(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 test) | |
(defn try-times | |
"Try executing a thunk `retries` times." | |
[retries thunk] | |
(if-let [res (try | |
[(thunk)] | |
(catch Exception e ; can be any exception | |
(when (zero? retries) | |
(throw e))))] |
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
(use ' clojure.contrib.reflect) | |
(defn- gf [obj field] | |
[(keyword (.getName field)) (get-field (class obj) (.getName field) obj)]) | |
(defn get-all-fields [obj] | |
(into (sorted-map) (map (partial gf obj) (.getDeclaredFields (class obj))))) | |
;; user=> (def a (memoize (partial (comp inc last concat) [2]))) | |
;; #'user/a |
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 propagator.spreadsheet ; see http://gitweb.adaptive.cs.unm.edu/propagator.git | |
(use propagator)) | |
(def xrange 10) (def yrange 10) | |
(def spreadsheet | |
(map (fn [_] (map (fn [_] | |
(let [c (gensym)] (eval `(defcell ~c nil)) c)) | |
(range xrange))) | |
(range yrange))) |