archimedes-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[archimedes-discuss] emacs


From: Waldo Geraldo Faldo
Subject: [archimedes-discuss] emacs
Date: Thu, 13 Dec 2007 10:00:58 +0000

Over the past days or so, I've been giving myself a course in
Emacs Lisp  by reading the
reference manual and trying out stuff in Lisp Interaction mode. I think
I'm finally getting the basics down; the one thing I'm having trouble
with right now is this: I can't figure out how best to interpolate lists
into function calls. Let me give an example of what I mean. In Perl, my
favorite computer language, list interpolation happens automagically. So,
suppose I want the sum of 4, 3, and the elements of the lists stored in
the variables @foo and @bar. If I've defined some function "sum" that
works like Lisp's "+", I can just say

sum(4, @foo, 3, @bar)

and supposing @foo contains (1, 2) and @bar contains (0, 0), Perl will
turn that expression into

sum(4, 1, 2, 3, 0, 0)

before actually calling the sum function. So for the related situation in
Emacs Lisp, I'm inclined to try

(+ 4 foo 3 bar)

But after the arguments are evaluated, the expression becomes

(+ 4 (1 2) 3 (0 0))

which, of course, isn't what I meant at all. Now, I know that I could,
for instance, define a new function that works like + but also operates
on lists by recursively applying + to their elements. But just adding
things isn't the point here; I want a general way to splice lists
together seamlessly. I know there are various ways I can work around this
problem with eval, such as

(eval `(+ 4 ,@foo 3 ,@bar))

but that seems inelegant. I should think there'd be some way to
interpolate lists using only the implicit evaluation that each argument
of a function call gets. Isn't building up the arguments of a function
call from lists a fairly common task? Even dotted-pair notation can't
seem to overcome this difficulty, since the right-hand operand of a dot
isn't evaluated.

Is there any good way to do what I'm trying to do here? Or am I simply
trying to program in an un-Lispish style? If the latter is the case,
what's the typical way a Lisp programmer would accomplish my addition
example?

_________________________________________________________________
Don't just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]