[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Returning variable "references" under lexical binding
From: |
Barry OReilly |
Subject: |
Re: Returning variable "references" under lexical binding |
Date: |
Tue, 21 May 2013 10:41:51 -0400 |
>> Why not
>>
>> (defun start-my-timer ()
>> (let ((timer (make-timer ...))
>> ...
>> timer))
>> (defun cancel-my-timer (timer)
>> (cancel-timer timer))
>
> Because start-my-timer sets up callbacks that may repeatedly change the
> value of the "timer" variable:
But you said:
> I want my routine to return an object that can be used to cancel the
> most recently set timer.
How is the above start-my-timer inadequate then?
> (defun start-my-timer ()
> (let (timer)
> ;; ... (setq timer (make-timer ...)) ...
> (lambda () timer)))
>
> (defun cancel-my-timer (timer)
> (cancel-timer (funcall timer)))
Each invocation of this start-my-timer will return a different closure.
Whether start-my-timer returns a timer or a closure, you still have to keep
track of which one to pass to cancel-my-timer. So the use of closures
doesn't facilitate anything that I can see.
- Returning variable "references" under lexical binding, Sean McAfee, 2013/05/20
- Re: Returning variable "references" under lexical binding, Barry Margolin, 2013/05/20
- Re: Returning variable "references" under lexical binding, Stefan Monnier, 2013/05/20
- Message not available
- Re: Returning variable "references" under lexical binding, Sean McAfee, 2013/05/21
- Re: Returning variable "references" under lexical binding, Stefan Monnier, 2013/05/21
- Re: Returning variable "references" under lexical binding, Barry Margolin, 2013/05/21
- Re: Returning variable "references" under lexical binding, Sean McAfee, 2013/05/21
- Re: Returning variable "references" under lexical binding, Barry Margolin, 2013/05/21
- Re: Returning variable "references" under lexical binding, Sean McAfee, 2013/05/21
- Re: Returning variable "references" under lexical binding, Stefan Monnier, 2013/05/22
- Re: Returning variable "references" under lexical binding,
Barry OReilly <=