Skip to content

Instantly share code, notes, and snippets.

View danlentz's full-sized avatar

Dan Lentz danlentz

View GitHub Profile
@danlentz
danlentz / fn.clj
Created September 9, 2013 00:14 — forked from ifesdjeen/fn.clj
;; 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>
@danlentz
danlentz / pprint.clj
Created September 9, 2013 00:12 — forked from ifesdjeen/pprint.clj
(require '[clojure.reflect :as r])
(use '[clojure.pprint :only [print-table]])
(print-table (:members (r/reflect"foo")))
(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)))
'()))
;; 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]
;; 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)
@hsjunnesson
hsjunnesson / log
Created September 5, 2013 21:28
Update: I've made a more thorough example of embedding Clojure logic in an iPhone app. Toes, a tic-tac-toe game in clojure on the iPhone. https://github.com/hsjunnesson/toes
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
;;; 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)
;;;
@stuartsierra
stuartsierra / spellcheck.clj
Created July 9, 2013 01:47
Example implementation of Norvig's Spellchecker in Clojure, using core.async
;; 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
@bpsm
bpsm / edn.wsn
Last active January 1, 2022 16:22
Proposed formal syntax for Extensible Data Notation
(* 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 *)
(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