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: problem with macro definitions Date: Fri, 28 Apr 2017 00:44:07 +0200 Message-ID: <20170427224407.GA5655@workstation> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1493333090 12081 195.159.176.226 (27 Apr 2017 22:44:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 27 Apr 2017 22:44:50 +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 Fri Apr 28 00:44:42 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 1d3s9S-0002xH-BP for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Apr 2017 00:44:42 +0200 Original-Received: from localhost ([::1]:34515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3s9Y-0007ek-7Q for geh-help-gnu-emacs@m.gmane.org; Thu, 27 Apr 2017 18:44:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36845) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3s94-0007ef-Ha for help-gnu-emacs@gnu.org; Thu, 27 Apr 2017 18:44:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3s91-0007w8-Ew for help-gnu-emacs@gnu.org; Thu, 27 Apr 2017 18:44:18 -0400 Original-Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]:36565) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d3s91-0007ve-74 for help-gnu-emacs@gnu.org; Thu, 27 Apr 2017 18:44:15 -0400 Original-Received: by mail-wm0-x235.google.com with SMTP id u65so28646150wmu.1 for ; Thu, 27 Apr 2017 15:44:14 -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:mime-version :content-disposition:user-agent; bh=wEHzledJ8qDCLuwEaYsRMzYTvst/nLYB379NqmNOU1Q=; b=X5Ik6upf6elfB8oqE+WIB4VbxXph9eEOKXasQL9hPAlGnAxASLrH0a7+f5WrSb4sbS EXWjO9LDTfchy8mLuKnAwZmTOqrMmVSqr3enfYrCZcqinhWXaZ42ajeSVpSdGuhhptY4 YrzZ4WRp/5cmeEFQoWPAsnMwTA7pKT3AqR60/xQou/ZWJU+dQIW7f5ROZ1skGgKI7gSs I+j+NFtDjeKomvxY3yjzmVVHNG2kkxVYOEXX0JE/ughtWdxa9DvtNOxea+LfWqrLJQ4Q aKs5JNdh2NMDqCk+0V8r/rYLxZzrkvEfI4rVTXSoryARHS6V4jnVLsMB178mhQI/qOE9 sdHw== 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 :mime-version:content-disposition:user-agent; bh=wEHzledJ8qDCLuwEaYsRMzYTvst/nLYB379NqmNOU1Q=; b=i30IkPklbmnlrbhoBdD4xeY0dnYu3uZ0RlFvOJcOz6M9BgawktRsAbXnL0muNmtH4G xhvD78Qvem/8cnufqY5AsMCIjUV728Ruu7c3XLbkuUoax/e409bmkOwcO4tYrdqVxEqQ r80oFssMhvwCUsClmN+nWX211I5qCoZeVo7UTgWkcugQxdLl6nKnG35NK8BllJx/EonS kyIZ9quFVUJo2WzDMM2X89BKVJs6scdvzyvj8N6Hbdf/cUnxHXw6bJA6T/j47fwl+g72 VtU+kyTDN7v/7evWTWXnL3qfVpe8rU4UovyeGRSqxUNqcVw4VPmOgTgvrc2Jai4+IjRy 8StA== X-Gm-Message-State: AN3rC/4N6MyKNrAbOArBA7TmY+bBnGMek/iSjrssmxF8EUwp+2dBySw5 XuVKpfrB38KuuOY7 X-Received: by 10.28.168.1 with SMTP id r1mr3992691wme.134.1493333053354; Thu, 27 Apr 2017 15:44:13 -0700 (PDT) Original-Received: from workstation ([137.101.90.238]) by smtp.gmail.com with ESMTPSA id o18sm5152539wrb.47.2017.04.27.15.44.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 27 Apr 2017 15:44:12 -0700 (PDT) X-Google-Original-From: hector Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::235 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:112894 Archived-At: Hi. I'm trying to write a macro. Honestly I find this is one of the most difficult matters about learning ELISP. 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 I thought it was a good candidate for a macro: (defmacro idx (list telt) `(let (found (idx 0)) (dolist (elt ,list found) (when (eq elt ,telt) (setq found idx)) (setq idx (1+ idx))))) Then I wrote another one: (defconst start-states '(initial red blue yellow)) (defconst shift-val 10) (defmacro state-eof (st) (let ((val (+ shift-val (idx start-states st)))) val)) Probably there is a better way to accomplish this. Anyway I'd like to know why it doesn't work. This yields 2 as expected: (idx start-states 'blue) so I expected this to return 12: (state-eof 'blue) but instead I get: wrong-type-argument number-or-marker-p nil What am I doing wrong?