From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kodi Arfer Newsgroups: gmane.emacs.help Subject: Combining lists in Emacs Lisp Date: Thu, 06 Dec 2007 20:39:40 +0000 Organization: UseNetServer.com Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1196985088 18556 80.91.229.12 (6 Dec 2007 23:51:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 6 Dec 2007 23:51:28 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 07 00:51:37 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1J0QVE-0002EA-JM for geh-help-gnu-emacs@m.gmane.org; Fri, 07 Dec 2007 00:51:36 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J0QUx-0000Fw-Ry for geh-help-gnu-emacs@m.gmane.org; Thu, 06 Dec 2007 18:51:19 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.kjsl.com!news-xfer.nntp.sonic.net!208.49.83.154.MISMATCH!uns-out.usenetserver.com!news.usenetserver.com!pc02.usenetserver.com!ALLTEL.NET-a2kHrUvQQWlmc!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Pan/0.129 (Benson & Hedges Moscow Gold) Original-X-Complaints-To: abuse@usenetserver.com Original-Lines: 47 Original-X-Trace: a45e947585e0c2866329830657 Original-Xref: shelby.stanford.edu gnu.emacs.help:154467 X-Mailman-Approved-At: Thu, 06 Dec 2007 18:50:18 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:49903 Archived-At: Over the past three days or so, I've been giving myself a crash course in Emacs Lisp (so I can do crazy things in my .emacs) 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?