Arc Forumnew | comments | leaders | submitlogin
1 point by parenthesis 6165 days ago | link | parent

Perhaps this is a crazy stupid idea, but what about macros that let you modify the surrounding code too:

  (def foo ()
    ...
    (make-local bar 'baz) ; macro call
    ,,,)
expands into:

  (def foo ()
    (let bar 'baz
      ...
      ,,,))


2 points by tel 6165 days ago | link

Does that always expand up to the current block? Why is it an advantage over let syntax?

-----

2 points by absz 6164 days ago | link

This would also allow things like a splice operator (mentioned here: http://arclanguage.org/item?id=540); if we had this (assuming that @x expands to (splice x)), you could write (let arglist '(4 5 6) (list 1 2 3 @arglist 7 8 9)) and get (1 2 3 4 5 6 7 8 9). This would actually be superior to apply in certain cases: (and x y @arglist) wouldn't have to evaluate y or the parts of arglist, whereas (apply and x y arglist) has the same effect in most cases, but does evaluate y, which can be problematic. I suppose one way to solve this would be to give values a "cer" (Current EnclosuRe) or some such; if lst were '(1 2 (a b) 3 4), then (cer x) = nil, (cer (car x)) = x, and (cer (car (list-ref 2))) = (list-ref 2). It's not clear what (cer (cdr x)) would be, but it would probably also be x.

-----

1 point by almkglor 6164 days ago | link

Personally I'd still implement this as a macro form, such that we would have a (spliceable ...) form which would scan its contents for splice-macros. So the syntax would look approximately like:

(spliceable (let arglist '(4 5 6) (list 1 2 3 (splice arglist) 7 8 9)))

(spliceable ...) would essentially be a generalization of the `() operator, except that ` will only scan for , while (spliceable ...) would scan for any splice-macros.

-----