[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do I pass a variable defined in a wrapping let, to a lambda?
From: |
Eric Abrahamsen |
Subject: |
Re: How do I pass a variable defined in a wrapping let, to a lambda? |
Date: |
Fri, 11 Mar 2022 15:48:23 -0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
Steinar Bang <sb@dod.no> writes:
>> I have been trying to write a restclient.el[1] result function that can be
>> used to save the body of a GET result to a file[2].
>>
>> My first attempt didn't work[3].
>>
>> I tried to look at an existing result function that actually worked[4],
>> and I finally figured it out: the final form of that function is a
>> lambda!
>>
>> So it was probably that lambda that was run to create the result?
>>
>> I rewrote my example code to this[5].
>>
>> But it still didn't work. And the reason it didn't work is that
>> filename didn't have a value set.
>>
>> If I replace the filename variable with a text constant[6], then the
>> function works.
>>
>> But as far as I can tell, the function in[4] uses variables defined in
>> the wrapping (let) in the lambda...?
>>
>> So why is that working but my filename failing?
> They've got a lexical-binding cookie at the top of the file, but you
> don't! :)
Oh, maybe I'm wrong. I just tested some code in two different elisp
buffers, one with lexical-binding -> t and one with it nil, and it
worked in both cases. Darn -- I thought I understood lexical-binding.
(defun steinars-test (file)
(let ((fname (expand-file-name file)))
(lambda () (message "file is %s" fname))))
(setq payload (steinars-test "~/.emacs.d/init.el"))
(funcall payload)
Re: How do I pass a variable defined in a wrapping let, to a lambda?, Steinar Bang, 2022/03/12
Re: How do I pass a variable defined in a wrapping let, to a lambda?, Emanuel Berg, 2022/03/12
Re: How do I pass a variable defined in a wrapping let, to a lambda?, Eric Abrahamsen, 2022/03/13
Re: How do I pass a variable defined in a wrapping let, to a lambda?, Steinar Bang, 2022/03/13
Re: How do I pass a variable defined in a wrapping let, to a lambda?,
Eric Abrahamsen <=
Re: How do I pass a variable defined in a wrapping let, to a lambda?, Michael Heerdegen, 2022/03/11
- Re: How do I pass a variable defined in a wrapping let, to a lambda?, Eric Abrahamsen, 2022/03/11
- Re: How do I pass a variable defined in a wrapping let, to a lambda?, Emanuel Berg, 2022/03/11
- Re: How do I pass a variable defined in a wrapping let, to a lambda?, Jean Louis, 2022/03/12
- `let' vs `let*' (was: Re: How do I pass a variable defined in a wrapping let, to a lambda?), Emanuel Berg, 2022/03/14
- Re: `let' vs `let*' (was: Re: How do I pass a variable defined in a wrapping let, to a lambda?), Jean Louis, 2022/03/15