@madhu: "Helu
* Joe Marshall <email_address> <email_address> :
|
...<snip eminently-correct double-backquote stuff>...
|
| Avoid EVAL, though.  It simply isn't necessary and
| debugging a macro that expands to a macro isn't going
| to be any easier when you attempt to expand the middle
| level in a context where the outer level isn't visible.
I understand that EVAL is almost always the incorrect thing to
do. However consider the following hypothetical situation where I have
a class FOO with many slots:
* (defclass foo () (slot1 slot2))
* (defvar *foo* (make-instance 'foo))
Now perhaps I wish to define accessors to the effect of:
;; (define-symbol-macro FOO-SLOT1 (slot-value *foo* 'slot1))
;; (define-symbol-macro FOO-SLOT2 (slot-value *foo* 'slot2))
i.e. 
;; (setf FOO-SLOT1 10) <=> (setf (slot-value *foo* 'SLOT1) 10) etc 
The most natural way I can think of doing this is:
* (loop for slot in '(slot1 slot2)
  for accessor = (intern (concatenate 'string "FOO-" (symbol-name slot)))
  do (eval `(define-symbol-macro ,accessor (slot-value *foo* ',slot))))
I cant think of any good reason to avoid EVAL in this case, in favour
of macrology.  Maybe I am missing something? (like an easy defmacro
solution, or is the motivating example somehow invalid?)
Regards
Madhu"
    @mdanish: "<quote>
(macrolet ((frob (&rest slots)
             `(progn
               ,@(loop for slot in slots
                       for accessor = (intern (format nil "~A-~A" 'foo slot))
                       collect `(define-symbol-macro ,accessor
                                 (slot-value *foo* ',slot))))))
  (frob slot1 slot2))
; Matthew Danish <email_address>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark.""
    @madhu: "Helu
* Joe Marshall <email_address> <email_address> :
|>> 
|>> * (loop for slot in '(slot1 slot2)
|>>   for accessor = (intern (concatenate 'string "FOO-" (symbol-name slot)))
|>>   do (eval `(define-symbol-macro ,accessor (slot-value *foo* ',slot))))
|
| Matthew Danish <email_address> writes:
|> (macrolet ((frob (&rest slots)
|>              `(progn
|>                ,@(loop for slot in slots
|>                        for accessor = (intern (format nil "~A-~A" 'foo slot))
|>                        collect `(define-symbol-macro ,accessor
|>                                  (slot-value *foo* ',slot))))))
|>   (frob slot1 slot2))
|
|
| To point out something that wasn't mentioned (perhaps it is too obvious, but 
| I'm good at seeing the obvious...),
|
| Madhu must arrange (by some mechanism) for his code to be evaluated at
| compile time, but that is already built in to Matthew Danish's code.
Indeed!
This was what I was missing. And counts as a reason to avoid EVAL in
this case. (and family of cases where the macro expands to a macro
only used at toplevel)
Thanks for bearing with me!
Regards
Madhu :>"
{'source': 'USENET', 'other_information': '{"reply_count": 2, "forum_name": "comp.lang.lisp.20141008.mbox"}', 'file': 'data/output/usenet-comp.lang.parquet'}