Skip to content

Instantly share code, notes, and snippets.

user=> (ns there)
nil
there=> (defmulti ^:private doit identity)
#'there/doit
there=> (defmethod doit 1 [x] x)
#<MultiFn clojure.lang.MultiFn@d2de489>
there=> (doit 1)
1
there=> (in-ns 'user)
#<Namespace user>
@alandipert
alandipert / index.cljs.hl
Last active August 29, 2015 14:04
Hoplon contacts example
(page "index.html"
(:require [clojure.string :as string]))
(def my-contacts
(cell #{{:first "Ben" :last "Bitdiddle" :email "benb@mit.edu"}
{:first "Alyssa" :middle-initial "P" :last "Hacker" :email "aphacker@mit.edu"}
{:first "Eva" :middle "Lu" :last "Ator" :email "eval@mit.edu"}
{:first "Louis" :last "Reasoner" :email "prolog@mit.edu"}
{:first "Cy" :middle-initial "D" :last "Effect" :email "bugs@mit.edu"}
{:first "Lem" :middle-initial "E" :last "Tweakit" :email "morebugs@mit.edu"}}))
@alandipert
alandipert / rot13.cljs.hl
Created July 21, 2014 21:29
Hoplon rot13
(page "rot13.html")
(defn make-rot13 [start]
(->> (for [from (range 27),
:let [to (mod (+ 13 from) 26)]]
[(char (+ start from)) (char (+ start to))])
(into {})))
(let [table (merge (make-rot13 97) (make-rot13 65))]
(defn rot13 [s]
(page "index.html")
(defn class! [elem c]
(let [asetc (cell= (aset elem "className" c))]
(specify! elem cljs.core/IMeta (-meta [_] asetc))))
(defn declass! [elem]
(destroy-cell! (meta elem)))
(defc the-class "foo")
@alandipert
alandipert / index.cljs.hl
Created August 2, 2014 22:41
Hatfield-McCoy selector wizard
(page "index.html")
(def people (cell {"Hatfield"
#{{:first "William" :gender :male}
{:first "Victoria" :gender :female}
{:first "Henry" :gender :male}
{:first "Elliott" :gender :male}
{:first "Elizabeth" :gender :female}}
"McCoy"
#{{:first "Randolph" :gender :male}
(defc c1 1)
(defc c2 2)
(defc c3 3)
(defc= show (print c1 c2 c3))
;;; show happens once with initial values 1 2 3
(doseq [c [c1 c2 c3]]
(set! (.-state c) (inc (.-state c))))
(page "index.html")
(defc c1 10)
(defc c2 20)
(defc c3 30)
(defn inc-c1c2! [also]
(dosync
(also)
(swap! c1 inc)
/* %% ['/home/alan/projects/snippets/lispfl.pl']. */
:- use_module(library(clpfd)).
%% functional forms
ff(def).
ff(const).
ff(comp).
ff(juxt).
(page "index.html"
(:require
[tailrecursion.hoplon.reload :refer [reload-all]]))
(reload-all 1000)
(defn register! [fname lname email pass pass2]
(println "register! called with:" fname lname email "***" "***"))
(with-init!
;;; list todos
(fn get-todos (shortcode)
(let [list-id (code2id shortcode)
s "SELECT todo, state FROM todos t INNER JOIN lists l ON t.list_id = l.id WHERE l.id=? ORDER BY t.id"
stmt (-> *conn* (prepare s))]
(-> stmt (bind_param "i" list-id))
(-> stmt (execute))
(fn fetch (arr)
(-> stmt (bind_result todo state))