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

[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: Emanuel Berg
Subject: Re: How do I pass a variable defined in a wrapping let, to a lambda?
Date: Sat, 12 Mar 2022 00:58:49 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Steinar Bang wrote:

> 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 uses variables
> defined in the wrapping (let) in the lambda...?

Dynamic/special scope?

But I see that you don't have that ... weird.

This works:

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/geh.el

(defun add-one-f (term)
  (let ((tm term))
    (lambda () (1+ tm)) ))

(funcall (add-one-f 2)) ; 3

But not this:

;; this file:
;;   https://dataswamp.org/~incal/emacs-init/geh-dynamic.el

(defun add-two-f (term)
  (let ((tm term))
    (lambda () (+ 2 tm)) ))

(funcall (add-two-f 2)) ; Symbol’s value as variable is void: tm

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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