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

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

Re: replacing a function with another one


From: lee
Subject: Re: replacing a function with another one
Date: Sat, 15 Mar 2014 20:51:23 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Michael Heerdegen <michael_heerdegen@web.de> writes:

> lee <lee@yun.yagibdah.de> writes:
>
>> and it doesn´t work because end-marker is undefined despite I just
>> defined it :(  So I have
>>
>>
>>     (let ((end-marker (concat "^" comment-start 
>> lsl-hi-lock-patterns-end-marker)))
>>       (let ((marker-pos (re-search-forward end-marker (point-max) t)))
>>       (do-something)))
>>
>
> The functionality you want, and that you reached with the nested `let',
> is exactly what `let*' does.  When I was learning LISP, I was also
> confused about `let'.  Standard `let' first evaluates all
> expressions, then binds the variables, so in works "parallel" - see

Ah!  Finally I understand what the difference is!  What is the point of
having two variations of `let'?


> [...]
>>        (let ((patterns nil))
>>          (while (< (point) marker-pos)
>>            (setq patterns (append (read (current-buffer)) patterns)))
>>          (setq patterns patterns)))))))
>>
>>
>> I need this function to return `patterns'.  Without the last line, it
>> seems to return nil because the setq is enclosed in the while.
>
> `let' returns the value returned by the last body expression (in
> particular, that isn't necessarily the value of the variable `patterns'
> in your example!).  And `while' always returns nil (strictly speaking,
> the return value isn't documented, so don't rely on it at all).  So this
> is what you want:
>
>         (let ((patterns nil))
>           (while (< (point) marker-pos)
>             (setq patterns (append (read (current-buffer)) patterns)))
>           patterns)

Thank you --- I only found that out yesterday.  It makes sense when you
think that a symbol stands for itself --- which is probably not correct,
but I just think of it as that the variable stands for itself and can be
returned like that.


-- 
Knowledge is volatile and fluid.  Software is power.



reply via email to

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