Skip to content

Instantly share code, notes, and snippets.

Verifying that +andrewwilcox is my openname (Bitcoin username). https://onename.io/andrewwilcox
@awwx
awwx / gist:1019335
Created June 10, 2011 17:42
stab at caching compiles
(use arc runtime)
(pr "load ac ")
(time (= r0 (runtime '(ac))))
(pr "load arc ")
(time (r0!use-load 'arc))
(= r1 (runtime '(ac)))
diff --git a/arc.arc b/arc.arc
index c824eb3..c3218ef 100644
--- a/arc.arc
+++ b/arc.arc
@@ -1047,6 +1047,28 @@
(car args)
`(let it ,(car args) (and it (aand ,@(cdr args))))))
+(def ar-fnil (x)
+ (and (ar-tnil x) x))
@awwx
awwx / gist:974935
Created May 16, 2011 17:40
respond in srv-misc1
(def respond (req)
(iflet f (srvops* req!op)
(if (redirector* req!op)
(do (prn rdheader*)
(prn "Location: " (f req!str req))
(prn))
(do (prn header*)
...
@awwx
awwx / gist:974932
Created May 16, 2011 17:39
build-response in srv-misc1
(def build-response (str op args cooks ip headers)
(w/stdout str
(respond (inst 'request 'args args 'cooks cooks 'ip ip 'op op 'str str 'headers headers))))
@awwx
awwx / gist:974928
Created May 16, 2011 17:35
respond in Arc 3.1
(def respond (str op args cooks ip)
(w/stdout str
(iflet f (srvops* op)
(let req (inst 'request 'args args 'cooks cooks 'ip ip)
(if (redirector* op)
(do (prn rdheader*)
(prn "Location: " (f str req))
(prn))
(do (prn header*)
...
(defop foo req
(foo req))
arc> (= other (new-arc))
#hash((racket-namespace* . #<namespace:0>))
arc> (aload other "arc.arc")
#<void>
arc> (eval '(mac bar () `(prn "yo, this is macro bar")) other)
#(tagged mac #<procedure>)
arc> (eval '(mac foo () `(do (prn "this is macro foo expanding into bar") (,bar))) other)
#(tagged mac #<procedure>)
arc> (namespace-set (this-namespace) 'foo (namespace-get other 'foo))
nil
(define (mac? x)
(and (tagged? x)
(eq? (arc-type x) 'mac)))
(ac-def ac-macro? (fn)
(cond ((mac? fn)
(ar-rep fn))
((symbol? fn)
(let ((v (get-default arc fn (lambda () 'nil))))
(if (mac? v)
arc> (= other (new-arc))
#hash((racket-namespace* . #<namespace:0>))
arc> (aload other "arc.arc")
#<void>
arc> (eval '(def bar () (prn "hi, this is bar")) other)
#<procedure:g2864>
arc> (eval '(mac foo () `(do (prn "this is macro foo expanding into bar") (,bar))) other)
#(tagged mac #<procedure>)
arc> (namespace-set (this-namespace) 'foo (namespace-get other 'foo))
nil