From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Juanma Barranquero" Newsgroups: gmane.emacs.help Subject: Re: A macro and an unwanted containing list in the resulting form Date: Wed, 23 May 2007 13:39:54 +0200 Message-ID: References: <873b1nye2g.fsf@moley.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1179920500 31032 80.91.229.12 (23 May 2007 11:41:40 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 23 May 2007 11:41:40 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: "Sebastian Tennant" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed May 23 13:41:31 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 1HqpDf-0006UH-BG for geh-help-gnu-emacs@m.gmane.org; Wed, 23 May 2007 13:41:31 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HqpDg-0001vW-Uo for geh-help-gnu-emacs@m.gmane.org; Wed, 23 May 2007 07:41:32 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HqpCA-0000ff-6G for help-gnu-emacs@gnu.org; Wed, 23 May 2007 07:39:58 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HqpC8-0000dt-16 for help-gnu-emacs@gnu.org; Wed, 23 May 2007 07:39:57 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HqpC7-0000dZ-Q2 for help-gnu-emacs@gnu.org; Wed, 23 May 2007 07:39:55 -0400 Original-Received: from wx-out-0506.google.com ([66.249.82.224]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HqpC7-0003cm-D3 for help-gnu-emacs@gnu.org; Wed, 23 May 2007 07:39:55 -0400 Original-Received: by wx-out-0506.google.com with SMTP id h26so194032wxd for ; Wed, 23 May 2007 04:39:54 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=SxgdumwtS9+NY1H9VfvlX5J8i7g3zH4knfRtdSr1+BCvzfBLpP7vJMAhZ7BC4gNwmmFeV4UB2tQRhBNDNZ7RZ6cS9u4BPVJpO4xSrq3fgBpd6fXsXd+PMMXMehL3UsonhbSH1tFexzyhqreyHjXxb3ywFpMSyrVBRaqh3cy8h8Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=dq35JYoUS2hiq/HeziRn/JcY66ZeFkbp83xR/tyLOkyOhrGpt6RAygbrEdwJ/OMjBQNoXEhbtjUXV3SHuSonDz6a3pJU7ngw31Nviiqz+HEX0x4KCmTmBIs0FeRA9IUEYfYypjdUkI4w7hisbQNphdEcL609djAgRBJFL9kQmZA= Original-Received: by 10.90.88.13 with SMTP id l13mr262381agb.1179920394627; Wed, 23 May 2007 04:39:54 -0700 (PDT) Original-Received: by 10.90.103.8 with HTTP; Wed, 23 May 2007 04:39:54 -0700 (PDT) In-Reply-To: <873b1nye2g.fsf@moley.org> Content-Disposition: inline X-detected-kernel: Linux 2.4-2.6 (Google crawlbot) 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:44323 Archived-At: On 5/23/07, Sebastian Tennant wrote: > (cond (((equal e "hello") (message "hi")) > ^((equal e "goodbye") (message "bye")))) > | ^ > | | > +--------- unwanted list -------------+ > > Clearly my approach is wrong (because this is how mapcar behaves), so > what is the best way to go about this? Try with (defmacro build-cond (alist) (append '(cond) (mapcar '(lambda (each) (cons (list 'equal 'my-var (car each)) (list (cdr each)))) alist))) Is there any reason to make the argument of build-cond an alist? You could try (defmacro build-cond (&rest conds) (append '(cond) (mapcar '(lambda (each) (cons (list 'equal 'my-var (car each)) (list (cdr each)))) conds))) and then use (build-cond ("hello" . (message "hi")) ("goodbye" . (message "bye")) Juanma