Arc Forumnew | comments | leaders | submitlogin
,@body
3 points by skenney26 5828 days ago | 2 comments
The following is an attempt to compress the ,@body pattern:

  (mac bod (name parms . body)
    `(mac ,name ,(rreduce cons (join parms (list 'body))) &))
& is a readmacro that translates to ,@body.

With the bod macro when...

  (mac when (test . body)
    `(if ,test (do ,@body)))
...becomes:

  (bod when (test)
    `(if ,test (do &)))
rfn...

  (mac rfn (name parms . body)
    `(let ,name nil
       (set ,name (fn ,parms ,@body))))
...becomes:

  (bod rfn (name parms)
    `(let ,name nil
       (set ,name (fn ,parms &))))
There's a version of arc.arc at http://github.com/skenney26/sarc/tree/master that has the bod macro and a few other macros translated to this syntax. (A few definitions had to be juggled around too.) An updated version of as.scm can also be found at the same url along with amp.scm which modifies the readtable for &. (brackets.scm was used as a template for amp.scm)

Perhaps this can be generalized to handle macros such as atomic that only have a rest parameter.

Feedback/improvements/criticisms appreciated.



1 point by drcode 5828 days ago | link

It's an interesting idea, but unfortunately I can't really say that I'm feeling it (now mind you, I've made plenty of suggestions on this forum for ideas that were far worse than this one :-)

Here's the main issues I have with it:

1. Breaks the symmetry of declaration vs. use of parameters- If you're using a variable you should see it declared somewhere. It is true that anaphoric macros like 'aif break this rule, but the payoff with these macros is really high because they allow you avoid an entire 'let form. This makes them worth having, anyway.

2. The token count in the body of the macro doesn't change appreciably- Yes, you do have one less 'unquote-splice reference, but that is a pretty small gain.

3. The rule for macros used to be "if you see a comma, data is being spliced in". The comma used to divide the syntactic from the metasyntactic content- This now breaks that rule.

4. The Ampersand is a potentially extremely valuable symbol character that could now no longer be used for other purposes as the language evolves.

5. In a way, the body parameter is still there, it is just hidden inside of the word 'bod. If the 'bod macro offered some deeper insight into macro creation this wouldn't be the case- However, since there's a one-to-one correspondence between the 'bod macro and the 'body parameter, this macro is really just a way to move the 'body parameter definition to a different place in the function syntax. (That's why, for instance, I like the fact that arc doens't bother with a '1+ function)

-----

1 point by almkglor 5828 days ago | link

Dunno, would ... be a better choice?

  (bod when (test)
    `(if ,test (do ...)))

  (bod rfn (name parms)
    `(let ,name nil
       (set ,name (fn ,parms ...))))

Of course this horribly complicates the readtable though.

-----