help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Evaluation of macro arguments


From: Marcin Borkowski
Subject: Re: Evaluation of macro arguments
Date: Tue, 05 Jan 2016 21:30:35 +0100
User-agent: mu4e 0.9.13; emacs 25.1.50.1


On 2016-01-05, at 20:39, Marcin Borkowski <address@hidden> wrote:

> On 2016-01-05, at 20:22, Pascal J. Bourguignon <address@hidden> wrote:
>
>> Marcin Borkowski <address@hidden> writes:
>>
>>> Hi all,
>>>
>>> continuing my quest to grok macro argument evaluation issues, I'd like
>>> (again) to make sure that I get it correctly.  So I have this simple
>>> macro generating a list of consecutive numbers (which is not without
>>> problems - I am aware of those, namely (i) it uses hard-coded symbols
>>> instead of generating them on the fly, and (ii) it has no error
>>> checking):
>>>
>>> (defmacro range (from dir to)
>>>   `(let ((delta (cond ((eq ',dir 'upto) 1)
>>>                       ((eq ',dir 'downto) -1)))
>>>          (i ,from)
>>>          (list nil))
>>>      (while (not (= i ,to))
>>>        (push i list)
>>>        (setq i (+ i delta)))
>>>      (nreverse list)))
>>
>> (let ((i 0))
>>    (list (range  i 'upto (incf i 10))  ; bam!
>>          i))
>>
>> I hope you may debug it well.
>
> That's unfair, Pascal; I wrote that I'm aware of this, I know how to
> make it work, and wasn't asking about it.

OK, technically you win, since I didn't notice that I evaluated `to'
multiple times.  Still, this was not what I was asking about - though
thank you for pointing that out to me.  It would be rather embarassing
if I missed it.

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



reply via email to

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