Arc Forumnew | comments | leaders | submitlogin
3 points by sjs 6161 days ago | link | parent

The first each loop does change srvops, it adds a redirect from "path" to "dest" (literally).

Macros are expanded prior to evaluation. This seems strange while typing into the repl because we tend to think of macros as functions most of the time. macex and macex1 are useful.

  (each (path dest) redirects* (defopr path req dest))
expands to: [via (macex1 '(defopr path req dest))]

  (each (path dest) redirects* (do (t! (redirectors* (quote path))) (defop-raw path (gs2429 req) dest))
which expands to:

  arc> (macex1 '(defop-raw path (gs2431 req) dest))
  (= (srvops* (quote path)) (fn (gs2431 req) (let gs2433 (msec) (do1 (do dest) (save-optime (quote path) (- (msec) gs2433))))))
Every iteration of the loop performs the same defopr.

I've come across this problem of wanting to run macros at runtime in order to evaluate the args first, but I think it is due to a misunderstanding of macros. This works, but it's an ugly hack:

  (each (path dest) redirs* (eval:apply defopr (list path 'req dest)))
I think what's really needed is a function that does what defopr expands to, which can be called at macro expansion time and runtime alike.

On Lisp[1][2] and PCL[3] are useful here.

[1] http://www.bookshelf.jp/texi/onlisp/onlisp_8.html

[2] http://www.bookshelf.jp/texi/onlisp/onlisp_9.html

[3] http://www.gigamonkeys.com/book/macros-defining-your-own.htm...

http://www.apl.jhu.edu/~hall/Lisp-Notes/Macros.html (section 4, doesn't give much in the way of solving the problem though)