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 om-tut.core | |
(:require [om.core :as om :include-macros true] | |
[om.dom :as dom :include-macros true])) | |
(enable-console-print!) | |
(def app-state (atom {:text "Works", :data [{:text "Doesn't"}]})) | |
(defn handle-change | |
[e data edit-key owner] |
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 om-tut.core | |
(:require [om.core :as om :include-macros true] | |
[om.dom :as dom :include-macros true])) | |
(enable-console-print!) | |
(def app-state (atom {:text "Works", :data {:text "Doesn't"}})) | |
(defn liker | |
[data owner] |
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.core | |
(:require [om.core :as om :include-macros true] | |
[om.dom :as dom :include-macros true])) | |
(enable-console-print!) | |
(def app-state (atom {:a 1})) | |
(defn demo | |
[app owner] |
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 destructors) | |
(defprotocol Disposable | |
(dispose [obj] "Dispose obj")) | |
(declare *registered-objects*) | |
(defn to-dispose | |
[obj] | |
(swap! *registered-objects* conj obj) |
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
(defn convert-alist | |
[alist] | |
(let [size (apply max (map first alist))] | |
(reduce (fn [v [i o]] (assoc v (dec i) o)) | |
(vec (repeat size nil)) | |
alist))) |
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
user=> (import 'java.util.ArrayList) | |
java.util.ArrayList | |
user=> (defn foo ^ArrayList [^double n] (doto (ArrayList.) (.add (* n 2)))) | |
#'user/foo | |
user=> (defn bar [x] (let [al (foo x)] (+ x (.get al 0)))) | |
#'user/bar | |
user=> (bar 5) | |
AbstractMethodError user$foo.invokePrim(D)Ljava/lang/Object; user/bar (NO_SOURCE_FILE:5) |
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
(defsyntax-rules plet | |
(plet [& var rhs] & body) | |
((fn [& var] & body) & rhs)) | |
(plet [a 1 b 2] (+ a b)) ;=> 3 | |
;;; Implementation of defsyntax-rules | |
; Using defmacro: | |
(defmacro defsyntax-rules | |
[name & rt-pairs] |
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
(defn merge-colls | |
[input] | |
(lazy-seq | |
(let [biggest (first (apply max-key #(first (second %)) input)) | |
new-input (update-in input [biggest] next)] | |
(cons biggest (merge-colls new-input))))) |
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
;;; Almost complete opinionated defn implementation | |
;;; Does not put the arg vector on the metadata | |
(defsyntax-class distinct-argument-vector [] | |
"distinct argument vector" | |
[] | |
[var ...] | |
:fail-when (check-duplicate (syntax (var ...))) "duplicate binding form") | |
(defsyntax-class docstring [] | |
"docstring" |
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
#ruby | |
[1,2,3,4].select{ |x| x.even? } | |
#python | |
[x for x in [1,2,3,4] if not x%2] | |
#or, more norvingly | |
filter(lambda x: not x%2, [1,2,3,4]) | |
#clojure | |
(filter even? [1 2 3 4]) |
OlderNewer