Hello!
I'd like to ask your opinion about the use of anaphoric macros like AIF,
AWHEN, as described in Paul Graham's "On Lisp".
I think they are sometimes useful and can contribute to more compact
code, but since they rely on intentional variable capture, things can
get a little harder to read.
Do you think it is good programming style to use those constructs?
Thanks.
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
In article <············@nnrp1.deja.com>,
vincent <···········@my-dejanews.com> wrote:
>
>I'd like to ask your opinion about the use of anaphoric macros like AIF,
>AWHEN, as described in Paul Graham's "On Lisp".
>I think they are sometimes useful and can contribute to more compact
>code, but since they rely on intentional variable capture, things can
>get a little harder to read.
>Do you think it is good programming style to use those constructs?
I remember an old book (by Drew McDermott?) that
defined a SETF macro that allowed *-* in the RHS to
represent the previous value of the variable. E.g.,
(setf (artist-name artist-01)
(format nil "The artist formerly known as ~a"
*-*))
I liked it at the time, considering it to be nicely
more general than having a multiplicity of implicitly
anaphoric forms such as INCF, DECF, PUSH, POP.
--d
Dorai Sitaram wrote:
> I remember an old book (by Drew McDermott?) that
> defined a SETF macro that allowed *-* in the RHS to
> represent the previous value of the variable. E.g.,
>
> (setf (artist-name artist-01)
> (format nil "The artist formerly known as ~a"
> *-*))
>
> I liked it at the time, considering it to be nicely
> more general than having a multiplicity of implicitly
> anaphoric forms such as INCF, DECF, PUSH, POP.
I still use it. However, it's unlikely to please purists, who will want some
guarantee that the left-hand side is evaluated "as little as possible." My
macro (called !=, by the way, not setf), just substitutes the left-hand side
for *-*. It is careful about nested occurrences of !=.
-- Drew McDermott
····@bunny.gte.com (Dorai Sitaram) writes:
> In article <············@nnrp1.deja.com>,
> vincent <···········@my-dejanews.com> wrote:
> >
> >I'd like to ask your opinion about the use of anaphoric macros like AIF,
> >AWHEN, as described in Paul Graham's "On Lisp".
> >[...] things can get a little harder to read.
That's wrong: Macros should make things easier to read. However, it
might be a matter of getting used to the idiom. For better style, I
quite like WHEN-LET in LW (adopted from ZetaLisp, I seem to recall):
(when-let (position (search string1 string2))
(print position))
> I remember an old book (by Drew McDermott?) that
> defined a SETF macro that allowed *-* in the RHS to
> represent the previous value of the variable.
For that, I like the idea of defining a generic modify macro that
takes a function to do the modification:
(defmacro funf (fun place &rest args &environment env)
(multiple-value-bind (dummies vals stores setter getter)
(get-setf-method place env)
`(let* (,@(mapcar #'list dummies vals)
(,(car stores) (,fun ,getter ,@args)))
,setter)))
(defmacro incf (place &optional (inc 1))
`(funf + ,place ,inc))
--
Pekka P. Pirinen Harlequin Group plc
"The question of whether a computer can think is no more
interesting than the question of whether a submarine can swim."
E. W. Dijkstra
vincent <···········@my-dejanews.com> writes:
> I'd like to ask your opinion about the use of anaphoric macros like AIF,
> AWHEN, as described in Paul Graham's "On Lisp".
> I think they are sometimes useful and can contribute to more compact
> code, but since they rely on intentional variable capture, things can
> get a little harder to read.
> Do you think it is good programming style to use those constructs?
I'm rather fond of them and have loaded them in my default
common-lisp-user environment. You have to know what they do but the
more compact idiom makes the code more readable in my opinion.
--
Lieven Marchand <···@bewoner.dma.be>
If there are aliens, they play Go. -- Lasker