Arc Forumnew | comments | leaders | submitlogin
1 point by CatDancer 5643 days ago | link | parent

rntz notes that this isn't as powerful as symbol macros, and that's true: this lets you specify the behavior of a global variable at run time, while symbol macros would let you manipulate the effect of a symbol during macro expansion (compile time).


1 point by conanite 5643 days ago | link

I don't get symbol macros. Is there an example of a symbol macro in use? On another thread someone mentioned that a symbol macro can expand into arbitrary code. Is this the same as an ordinary macro with no arguments (except for a pair of parens) ?

On a possibly related note, when compiling (assign ...) forms, ac.scm calls macex on the 1st arg:

  (assign (foo bar) 12)
'(foo bar) gets macexed. Later, ac-set requires that its first argument be a symbol. So '(foo bar) must expand into a symbol. I didn't see this obviously being used anywhere in arc ... do I need to look harder? Is its usage buried under layers of macros (deep inside '= for example), or what's the story? Is this somehow related to the concept of symbol macros?

yours truly, Confused.

-----

2 points by Adlai 5643 days ago | link

I'm not sure about your related note, but for an example of symbol macros in use:

This example is from Common Lisp's object system, called CLOS. When you want to do some code while accessing specific slots of an object, you can use a 'with-slots form, which lets you name symbols that you'll use to reference specific slots of the object. The 'with-slots form then generates local symbol-macros for each symbol you mentioned, which expand into code to access those slots. An example, taken from PCL [1]:

  (with-slots ((bal balance)) account  ; Here 'balance is the name of the slot, and 'account is the specific object
    (when (< bal *minimum-balance*)    ; *symbol* is a CL convention for global variables
      (decf bal (* bal .01)))))        ; decf is like --
[1] Practical Common Lisp, by Peter Seibel, available online at www.gigamonkeys.com/book/

-----

2 points by eds 5642 days ago | link

Another use for symbol macros is in writing package/module systems, where you want to determine which package a symbol goes into based on the compilation context.

You can do this to a certain extent already, using package!symbol notation, but this still doesn't allow using symbols without prefixes.

EDIT: See http://arclanguage.org/item?id=3572

-----