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
(defn kvmap [fun hash] | |
(into {} (map (fn [[k v]] [k (fun k v)]) | |
(seq hash)))) | |
(kvmap (fn [k v] (str v "/" k)) {"host" "http://localhost" "most" "umph"}) | |
;; => {"most" "umph/most", "host" "http://localhost/host"} | |
(defn kvmpa [fun hs] | |
(reduce-kv (fn [all k v] |
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
;; Playing around with Joy in Clojure | |
;; http://en.wikipedia.org/wiki/Joy_%28programming_language%29 | |
;; The code is partly based on Joy in Scheme by John Cowan | |
;; http://home.ccil.org/~cowan/ | |
(defn get-var [var env] (@env var)) | |
(defn set-var! [var val env] (swap! env conj {var val})) | |
(def global-env (atom {})) | |
(def joy-stack (atom [])) |
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
rows = 3 | |
glasses = [ | |
0.0, | |
0.0, 0.0, | |
0.0, 0.0, 0.0, | |
0.0, 0.0, 0.0, 0.0 ] | |
def index(i, j): | |
"ith glass in the jth row" | |
return i + sum(range(1, j+1)) | |
def dist(v, i, j): |
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
(loop [foo (seq []) | |
bar [1 2 3]] | |
(if (empty? bar) | |
foo | |
(recur (conj foo (first bar)) (next bar)))) |
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
(defn book [state owner] | |
(prn state) | |
(om/component | |
(dom/div nil (dom/h2 nil (:author state))))) | |
;;=> | |
{:author "Richard K. Morgan", :book "Altered Carbon"} core.cljs:55 | |
Uncaught TypeError: Cannot read property 'string' of undefined core.cljs:110 | |
;; Manual creation of a cursor giving the same behaviour | |
;; Inserted this snippet inside an om/component |
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
f x = (42-x)^2 | |
impr = [(x, f x) | x <- [0, 0.1 ..]] | |
opt goal = head $ dropWhile (\(x, err) -> err >= goal) impr |
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
;; Updated tutorial code for Om 0.1.6, 2014-01-16 | |
;; http://www.lexicallyscoped.com/2013/12/25/slice-of-reactjs-and-cljs.html | |
;; See comments below for details on the changes. | |
(def app-state | |
(atom {:comments [{:author "Pete Hunt" :text "This is a comment."} | |
{:author "Jordan Walke" :text "This is *another* coment"}]})) | |
(defn comment [{:keys [author text]} owner] | |
(om/component |
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
(ns om-table.core | |
(:require [om.core :as om :include-macros true] | |
[om.dom :as dom :include-macros true])) | |
(enable-console-print!) | |
(extend-type string | |
ICloneable | |
(-clone [n] (js/String. n))) | |
(def app-state (atom {:table ["very" "undefined" "such" "parentNode"]})) |
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
-- Arne Andersson - Balanced Search Trees Made Simple | |
-- Original article: http://user.it.uu.se/~arnea/ps/simp.pdf | |
-- Wikipedia entry: http://en.wikipedia.org/wiki/AA_tree | |
data AATree a = E | T a (AATree a) (AATree a) Int deriving (Show, Eq) | |
insert E x = T x E E 1 | |
insert (T y left right level) x | |
| x < y = balance $ T y (insert left x) right level | |
| otherwise = balance $ T y left (insert right x) level |
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
var comments = [ | |
{author: "Pete Hunt", text: "This is a text"}, | |
{author: "Suvash", text: "This is *another* comment"} | |
]; | |
// Data is local to components, | |
// passed down from the parent | |
// this.props - immutable |