Skip to content

Instantly share code, notes, and snippets.

View jasonjckn's full-sized avatar

Jason Jackson jasonjckn

View GitHub Profile
(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))
{-# 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
(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})))
(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 ")"))
(defun blah64 () (interactive)
(slime-eval `(swank:eval-and-grab-output
"(def foo 99)")
(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
(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)))
(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)))
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.
(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 %)]]]