Michael Livshin <email@example.com> wrote:
| Erik Naggum <firstname.lastname@example.org> writes:
| > well, Emacs Lisp calls them "hooks" -- lists of functions to call to
| > allow users to customize the behavior of internal functions.
| hmmm. what you are talking about is mapc'ing funcall over a list
| of symbols, right?
| the Scheme "moral equivalent" (if we assume that a hook is a list
| of symbols, not closures) would be:
| (map (lambda (sym . args) (apply (eval sym) args))
| <list-of-names> ...)
| that's too easy, so I probably don't get something here ;(.
What you didn't get [and thereby triggered an otherwise needless flamefest
from Erik! ;-} ;-} ] is that the "Scheme moral equivalent" is *NOT* a
"list of symbols", but (as you *almost* said) "a list of closures" themselves.
So no "eval" is needed at all:
(for-each (lambda (x) (x)) *foo-hook*)
or if there are per-function-dependent args to be passed:
> (map (lambda (f a1 a2) (f a1 a2))
(list + - * /) ; "list", not "quote": get the the *values*!
'(1 2 3 4)
'(5 6 7 8))
(6 -4 21 1/2)
Or more generally, using the more general definition of Scheme "funcall"
I gave in another reply in this thread:
> (define (funcall f . rest) (apply f rest))
> (map funcall (list + - * /)
'(1 2 3 4)
'(5 6 7 8)
'(0.1 0.1 0.1 0.1))
(6.1 -4.1 2.1 5.0)
Scheme and Common Lisp have *very* different "natural" styles in some areas,
and the "Lisp1" nature of Scheme and the fact that the function position
of a call is evaluated *exactly* the same way as the argument positions
means that in most situations where a Common Lisp programmer might pass
around the *name* of a function -- knowing that "symbol-function" is cheap
and does not require "eval" -- the Scheme programmer will simply pass around
the function itself.
Unlike Erik [whose opinion I respect], I do like Scheme... for some things.
But I definitely have learned that Scheme is *not* a "subset" or even
"dialect" of Common Lisp (though my opinion, which various others agree
*and* disagree with, is that Scheme is certainly a member of the generic
"Lisp family"), and that it is best not to try to argue detailed comparisons
between them (other than maybe presenting rough crib sheets for use by
people trying to move from one to the other, for whatever reason).
Rob Warnock, 8L-846 email@example.com
Applied Networking http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
1600 Amphitheatre Pkwy. FAX: 650-933-0511
Mountain View, CA 94043 PP-ASEL-IA