Arc Forumnew | comments | leaders | submitlogin
User defined wrapping macros (like [ _ ])
5 points by garym 6643 days ago | 2 comments
The [ _ ] syntax for single arg functions is good. If wrapping macros where user-defined then it might be defined something like so:

(wrapmac ([ body ]) `(fn (_) ,@body))

Users could then introduce their own wrapping macros:

(wrapmac ({ file . body }) `(apply (with-open-file (f) (for-each-line f (fn (_) ,@body)))) ,file)

(wrapmac (/ pattern val /) `(match ,pattern ,val))

{"only-awesome.txt" (if /"not.awesome" _/) (prn _)) }

Or the perl like pattern matching in the example could be a "symbol-macro" for the reader:

(symac /pattern/value `(match (make-string #\" ,pattern #\") ,value))

{"only-awesome.txt" (if /not.awesome/_ (prn _)) }



2 points by treef 6641 days ago | link

pg said he would add some thing like this himself

-----

2 points by cooldude127 6642 days ago | link

I love the idea of wrapmac!

-----