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 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 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-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 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-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 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
d 'html' -> | |
d 'head' -> | |
d 'title' -> | |
d.text 'Hello, world!' | |
d 'body' -> | |
d 'p' -> | |
d.text 'Hello, world!' |
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 entire library is contained in the class XMLWriter. | |
== USAGE == | |
Say we wanted to produce the following XML: | |
======== | |
<?xml version="1.0" encoding="UTF-8"?> | |
<compiler-settings> | |
<speed>3</speed> | |
<safety>0</safety> | |
<debug foo="bar">0</debug> |
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
#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]) |
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
;;; 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 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 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 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
(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 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
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) |
NewerOlder