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 xform [body [ns v]] | |
| (postwalk (fn [f] | |
| (if (= f ~(symbol v)) | |
| `(var ~f) | |
| f) | |
| ) body)) | |
| (defmacro defparser [name & body] | |
| (try | |
| (eval `(def ~name ~@body)) |
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
| {-# LANGUAGE RecordWildCards #-} | |
| module Parser | |
| ( LValue(..) | |
| , parseScheme | |
| , Env | |
| , VarMap | |
| ) where | |
| import Text.ParserCombinators.Parsec | |
| import Text.ParserCombinators.Parsec.Language | |
| import qualified Text.ParserCombinators.Parsec.Token as T |
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 arrows [p] (between (symb "<") (symb ">") p)) | |
| (def open-tag (arrows identifier)) | |
| (defn close-tag [tag-name] (arrows (symb (str "/" tag-name)))) | |
| (defn open-close [p] | |
| (let-bind [tag-name open-tag | |
| contents p | |
| _ (close-tag tag-name)] | |
| (result {(keyword tag-name) contents}))) |
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
| (defun blah53 () (interactive) | |
| (save-excursion | |
| (setq part1 (thing-at-point 'sexp)) | |
| (forward-thing 'sexp) | |
| (forward-thing 'sexp) | |
| (setq part2 (thing-at-point 'sexp)) | |
| (setq part3 (concat "(def " part1 " " part2 ")")) |
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
| (defun blah64 () (interactive) | |
| (slime-eval `(swank:eval-and-grab-output | |
| "(def foo 99)") |
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
| (defun blah () (interactive) | |
| (save-excursion | |
| (setq part1 (thing-at-point 'sexp)) | |
| (forward-thing 'sexp) | |
| (forward-thing 'sexp) | |
| (setq part2 (thing-at-point 'sexp)) | |
| (setq part3 (concat "(def " part1 " " part2 ")")) | |
| (slime-eval `(swank:eval-and-grab-output |
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 handler [chi cho] | |
| (let [parse (fn-match ([["GETT" ?gid ?uid]] | |
| (if-let [v ((data gid) uid)] | |
| (str v) | |
| (str "ERROR_" gid "_" uid))) | |
| ([["STOP_SESSION"]] (close chi)) | |
| ([["STOP"]] (System/exit 0)))] | |
| #_ (receive-all chi #(enqueue cho (str "You said: " % "\r\n"))) | |
| (siphon (map* #(parse (re-seq #"\S+" %)) chi) cho))) |
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 handler [chi cho] | |
| (let [parse (fn-match ([["GET" ?gid ?uid]] | |
| (if-let [v ((data gid) uid)] | |
| (str v) | |
| (str "ERROR_" gid "_" uid))) | |
| ([["STOP_SESSION"]] (close chi)) | |
| ([["STOP"]] (System/exit 0)))] | |
| #_ (receive-all chi #(enqueue cho (str "You said: " % "\r\n"))) | |
| (siphon (map* #(parse (re-seq #"\S+" %)) chi) cho))) |
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
| I want to call the server handler in a unit test: | |
| (defn handler [ch _] (receive-all ch print) (enqueue ch "hi")) | |
| calling (handler (channel 1 2 3)) causes output: 123hi | |
| passing in pair-channel causes exception. |
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 calc (:gen-class)) | |
| (defmulti calc (fn [t] (if (seq? t) (first t) :num))) | |
| (defn def-prefix-op [sym f] | |
| (defmethod calc sym [[op & args]] (apply f (map calc args)))) | |
| (doseq [[sym op] [['+ +] ['- -] | |
| ['* *] ['/ /] | |
| ['sin #(Math/sin %)]]] |