| After reading the various discussions here (http://arclanguage.org/item?id=1227 and http://arclanguage.org/item?id=1329 come to mind), I wrote some code which alters the evaluation of brackets so that the following becomes legal: (maptable [prn _1 #\tab _2] (obj x 1 y 2 z 3))
; ==>
; x 1
; z 3
; y 2
_# parameters are 1-based, and you can also use __ for the "rest" arguments (so that the function becomes variadic). As I'm working on the already-patched version of Arc for mzscheme 370+, I have a patchfile for that version as well as instructions for the original version. (The patchfile should be largely the same for the un-pre-patched version, but I can't guarantee it.) To apply the patch, run `patch -d . < bracket.patch` in the arc0 directory. You can find the instructions at http://asz.arc.googlepages.com/add-n-ary-brackets.txt and the patch at http://asz.arc.googlepages.com/bracket.patch .The code works by macro-expanding the given expression and then finding which variables are used unbound. It then takes only the arguments of the form _# (as well as _, which is the same as _1, and __), finds the highest numbered, and constructs the argument list. Thus [... __ ...] expands to (fn __ (... __ ...)); [... _ ...] expands to (fn (_1) (let _ _1 (... _ ...))); [... _3 ... _5 ...] expands to (fn (_1 _2 _3 _4 _5) (let _ _1 (... _3 ... _5 ...))); [...] expands to (fn (_) (...)), and [... _ ... __ ...] expands to (fn (_1 . __) (let _ _1 (... _ ... __ ...))). I wouldn't be surprised if there's a much better way to write the code to make this happen, but it does seem to work. I hope people find this useful. |