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
(let [{:keys [a b] :or {a :a b :b}} +] [a b]) ; [:a :b] |
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=> ((let [a :a] a) {:a :foo}) | |
:foo |
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=> (defn foo [& children] children) | |
#'user/foo | |
user=> (defn bar [f & children] (println children) (f children)) | |
#'user/bar | |
user=> (bar foo 'first 'second 'third) | |
(first second third) | |
((first second third)) | |
user=> |
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 mock [& {:keys [value delay log? wrap throw-after-count]}] | |
{:pre [(not (and value wrap))]} | |
(let [state (ref {:call-count 0 | |
:call-args '()})] | |
(with-meta (fn [& args] | |
(do | |
(if log? | |
(log/info "Calling mock " (inc (:call-count @state)) | |
" with " args)) | |
(dosync |
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 line-parser [] | |
(let [re #" \[(\S+)\] (\S+) " | |
formatter (tformat/formatter "dd/MMM/YYYY:HH:mm:ss.SSS") | |
coercers [#(int (coerce/to-epoch (tformat/parse formatter %))) | |
identity] | |
fields [:time :frontend-name]] | |
(fn [line] | |
(apply assoc nil (interleave | |
fields | |
(map #(%1 %2) |
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
faust.core> ((parser "resources/parsing-rules") "a") | |
Parse error at line 1, column 1: | |
a | |
^ | |
Expected: | |
#"[0-9]+" (followed by end-of-string) | |
faust.core> ((parser "resources/parsing-rules") "1") | |
[:NUMBER "1"] | |
faust.core> |
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
(deftest parsing-chars | |
(testing "can parse valid chars for identifiers" | |
(is (= [:SCHAR "@"] (parser "@"))) | |
(is (= [:SCHAR "#"] (parser "#"))))) | |
(deftest ignore-leading-spaces | |
(testing "leading space doesn't break the things" | |
(is (= [:SCHAR "#"] (parser " #"))))) |
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
faust.core> (parse "a") | |
[:SEXP [:ATOM [:LETTER "a"]]] | |
faust.core> (parse "\"a\"") | |
[:SEXP [:STRING "\"a\""]] | |
faust.core> (parse "1") | |
[:SEXP [:NUMBER [:DIGIT "1"]]] | |
faust.core> (parse "!") | |
[:SEXP [:ATOM [:SYMBOL "!"]]] | |
faust.core> |
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
faust.core> ((comp type second) (parse "atoms!")) | |
clojure.lang.Symbol | |
faust.core> ((comp type second) (parse "42")) | |
java.lang.Long | |
faust.core> ((comp type second) (parse "\"ohai\"")) | |
java.lang.String | |
faust.core> |
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
SEXP = SPACE* (ATOM | STRING | NUMBER) | |
STRING = #"\"(\\\"|[^\"])*\"" | |
ATOM = (LETTER | SYMBOL)+ (LETTER | DIGIT | SYMBOL)* | |
NUMBER = (DIGIT+) DIGIT* | |
<LETTER> = (#"[a-zA-z]")* | |
<SYMBOL> = (#"[!$%&|*+-/:<=?>@^_~#]+")* | |
<DIGIT> = #"[0-9]+" | |
<SPACE> = <#"[ ]*"> |
OlderNewer