This file contains hidden or 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
| ;; Declare a function | |
| (defn fun1 [] (println 1)) | |
| ;; And a hash that would capture that function | |
| (def h {:key fun1}) | |
| ;; => {:key #<user$fun1 user$fun1@5e540696>} | |
| ;; Now, check out the value of the key | |
| (:key h) | |
| ;; => #<user$fun1 user$fun1@5e540696> |
This file contains hidden or 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
| (require '[clojure.reflect :as r]) | |
| (use '[clojure.pprint :only [print-table]]) | |
| (print-table (:members (r/reflect"foo"))) |
This file contains hidden or 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
| (defun nrepl-interactive-eval-print-comment-handler (buffer) | |
| (nrepl-make-response-handler buffer | |
| (lambda (buffer value) | |
| (with-current-buffer buffer | |
| (insert (format " ;; %s" value)))) | |
| '() | |
| (lambda (buffer err) | |
| (message (format " ;; %s" err))) | |
| '())) |
This file contains hidden or 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
| ;; The Datomic schema is made up of Datomic data, so you manipulate it | |
| ;; with ordinary queries and transactions -- and with ordinary code | |
| ;; in Java or Clojure. | |
| ;; query rule that finds attributes in schema whose names start with ?prefix | |
| ;; note the Java interop call to .startsWith | |
| ;; you could create a similar rule for namespace prefixes | |
| (def rules '[[[attr-starts-with ?prefix ?attr] | |
| [?e :db/valueType] | |
| [?e :db/ident ?attr] |
This file contains hidden or 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
| ;; Datomic example code | |
| ;; | |
| ;; The extent of entity ?x is all datoms that are about ?x. | |
| ;; Drop this into your rules. | |
| ;; | |
| ;; Demonstrates | |
| ;; | |
| ;; 1. recursive query (extent calls itself) | |
| ;; 2. disjunction (different extent bodies are ORed) | |
| ;; 3. component attributes (e.g. your arm is a component, your brother isn't) |
This file contains hidden or 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
| 2013-09-05 23:24:37.777 Prime[4204:c07] 1 | |
| 2013-09-05 23:24:37.779 Prime[4204:c07] 0.732028842267092 | |
| 2013-09-05 23:24:37.780 Prime[4204:c07] 0.2530017011838238 | |
| 2013-09-05 23:24:37.781 Prime[4204:c07] 0.22892546997679017 | |
| 2013-09-05 23:24:37.781 Prime[4204:c07] 0.5423003204364027 | |
| 2013-09-05 23:24:37.782 Prime[4204:c07] 0.6065306597126334 | |
| 2013-09-05 23:24:37.783 Prime[4204:c07] 0.44399788140114904 | |
| 2013-09-05 23:24:37.783 Prime[4204:c07] 0.15345314921321815 | |
| 2013-09-05 23:24:37.784 Prime[4204:c07] 0.13885046809469812 | |
| 2013-09-05 23:24:37.784 Prime[4204:c07] 0.32892187595578626 |
This file contains hidden or 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
| ;;; Binding Block -- This is a binding construct that supports a programming style | |
| ;;; that allows deeply nested bindings without having the code crawl off the right | |
| ;;; side of the screen. The syntax is: | |
| ;;; | |
| ;;; (binding-block [binding-spec|form]* form) | |
| ;;; | |
| ;;; or | |
| ;;; | |
| ;;; (bb [binding-spec|form]* form) | |
| ;;; |
This file contains hidden or 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
| ;; Example implementation of Norvig's Spellchecker in Clojure, | |
| ;; using core.async | |
| ;; | |
| ;; There are probably some bugs in this. | |
| ;; | |
| ;; Original problem: https://github.com/ericnormand/spelling-jam | |
| ;; from Lambda Jam, Chicago, 2013: http://lambdajam.com/ | |
| ;; | |
| ;; Clojure core.async introduction: | |
| ;; http://clojure.com/blog/2013/06/28/clojure-core-async-channels.html |
This file contains hidden or 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
| (* Syntax of Extensible Data Notation -- http://github.com/edn-format/edn | |
| See https://github.com/edn-format/edn/issues/56 | |
| This grammar is written in slightly extended version of Wirth Syntax | |
| Notation. A description is appended to the end of this document. *) | |
| (* start *) |
This file contains hidden or 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
| (in-package :nisp.mop) | |
| (defun class-slot-name-value-alist (instance) | |
| "Return slot names and values of INSTANCE. | |
| The alist looks something like: ((slot-name . slot-value) ...)." | |
| (mapcar (lambda (slot) | |
| (cons (closer-mop:slot-definition-name slot) | |
| (closer-mop:slot-value-using-class (class-of instance) | |
| instance |