From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: hector Newsgroups: gmane.emacs.help Subject: Re: problem with macro definitions Date: Sat, 29 Apr 2017 18:06:32 +0200 Message-ID: <20170429160632.GA3291@workstation> References: <20170427224407.GA5655@workstation> <878tmjr1ry.fsf@drachen> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1493482031 14065 195.159.176.226 (29 Apr 2017 16:07:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 29 Apr 2017 16:07:11 +0000 (UTC) User-Agent: Mutt/1.5.20 (2009-06-14) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Apr 29 18:07:07 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d4Uti-0003R5-EO for geh-help-gnu-emacs@m.gmane.org; Sat, 29 Apr 2017 18:07:02 +0200 Original-Received: from localhost ([::1]:41639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4Utm-00023s-M1 for geh-help-gnu-emacs@m.gmane.org; Sat, 29 Apr 2017 12:07:06 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4UtM-00023Z-En for help-gnu-emacs@gnu.org; Sat, 29 Apr 2017 12:06:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4UtJ-0006ut-AE for help-gnu-emacs@gnu.org; Sat, 29 Apr 2017 12:06:40 -0400 Original-Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]:34970) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d4UtJ-0006u5-2C for help-gnu-emacs@gnu.org; Sat, 29 Apr 2017 12:06:37 -0400 Original-Received: by mail-wr0-x232.google.com with SMTP id z52so46848431wrc.2 for ; Sat, 29 Apr 2017 09:06:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=hYJq5+OM9zYWA7XJVuK1OuS0SU284XMXi48+2T/ISKM=; b=SvVu1Pk0BWP10Hm5gwFmBcrSY024USYxwY1Egl7k32h8B7Z4ty6mGxrk1MJuR4fMtN GWeAD01pZTRdnQpo12CNX5qO/Yl5Upi3gQVAA7C0UNooF76ntwG3Gt8gX5k7LPT3HRAf PlpzslEmj0u02c8SNRn42HiNblKYZln0KS0/lZwAMHpGHAgbSQdZ9f/7a/ffSqJVOCYz TexEG3jBEjGebM83j3+jr+39aDUrKJ04N1WeFXblGHUsAVwM9QzdfGa5lBquoi7gPxgS w15YxJ61AsDBEZtbHcdX7mRtUteSbvZAvRlCvghUIdVbJBt9q0ocdTDfA2jMkH3x4NEK a5ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=hYJq5+OM9zYWA7XJVuK1OuS0SU284XMXi48+2T/ISKM=; b=IZKA9/gaw4VqIG9NL7WTpRhGAWtbCKeTnG+v7w/9oeeXPRNRZOpPDdAUeJgQSSpJPe 4bk/7HmwGnocsmbXY4wJ+HocbErA49lDc8LoQxLhvjiN/Ndx951UuhCYOnAuvtC+l6ui PoHS1vp1kEM+7DDNyrBnXnNG9h3Pga7mYVLLQyVU7lRh6XLFStgJJVveUcHn+FN4jYV2 a+EHOg+7GiRqzDKthaWQSNoUij9PwixRthcKK1E/IZDzIMj3NqQM123qyXeg2PF0U0Cm 2ZTeYGuOq3vy5vu1GapOFQkOdQ9mX8UWV77BKHUGG8TpE+GN8hKhe5IP9302UVV7d6+6 ZKzQ== X-Gm-Message-State: AN3rC/5cRGUaA64Yer6qfYOf4/yu83kYlxNF7NEMWHAxOXfyTTnlx/ca RvxlbsGpou7EXp9n X-Received: by 10.223.136.227 with SMTP id g32mr11252101wrg.58.1493481995665; Sat, 29 Apr 2017 09:06:35 -0700 (PDT) Original-Received: from workstation ([47.62.132.10]) by smtp.gmail.com with ESMTPSA id l7sm11212563wrc.52.2017.04.29.09.06.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 29 Apr 2017 09:06:35 -0700 (PDT) X-Google-Original-From: hector Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <878tmjr1ry.fsf@drachen> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::232 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112901 Archived-At: Thank you for your reply. On Sat, Apr 29, 2017 at 11:39:13AM +0200, Michael Heerdegen wrote: > hector writes: > > > I was looking for the complementary of nth, that is, a function that > > returns the index of an element. Since it can be done at compilation > > time > > Not if you want to use it on values that are known only at run-time. I know. In this case when the list is constant it seemed to be right. > > I thought it was a good candidate for a macro: > > No, not really: > > > (defmacro idx (list telt) > > `(let (found > > (idx 0)) > > (dolist (elt ,list found) > > (when (eq elt ,telt) > > (setq found idx)) > > (setq idx (1+ idx))))) > > You loose nothing when you rewrite this as a function. In this > implementation, the index is calculated at run-time. Let me rephrase your statement: "You gain nothing when you write this as a macro. In this implementation, the index is calculated at run-time" I'm aware of that now. This is not what I meant. I'll try to rewrite it. > Note that macros don't evaluate their arguments. The argument 'blue you > pass, a read syntax for (quote blue), is a list of two elements. This > doesn't appear as an element of `start-states' which consists of four > symbols. This is the key to my confusion.