Arc Forumnew | comments | leaders | submitlogin
2 points by Adlai 5620 days ago | link | parent

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/