Michael Olson, 2007-08-28:
> Christian Ohler <[EMAIL PROTECTED]> writes:
>
>> Also, its semantics are difficult to predict and/or under-documented,
>> otherwise Michael wouldn't have suggested using it for state variables
>> even though that won't work.
>
> This is not true anymore, AFAICT, now that I have implemented re-use of
> symbols that are captured more than once.
Hmm, I haven't looked very closely at your recent changes, but if this
were so, shouldn't
(defun make-counter ()
(let ((a 0))
(dvc-capturing-lambda ()
(incf (capture a)))))
=> make-counter
(setq a (make-counter))
=> (lambda ...)
(funcall a)
=> 1
(funcall a)
=> 1
return 2 on the second call? Or how do you intend to implement state
variables?
(I am using your most recent code, but this example has only one
occurrence of `capture', so it's not really related to the problem you
fixed.)
`lexical-let' works:
(defun make-counter ()
(lexical-let ((a 0))
(lambda ()
(incf a))))
=> make-counter
(setq a (make-counter))
=> (lambda ...)
(funcall a)
=> 1
(funcall a)
=> 2
Either way, I think this discussion supports my point that the semantics
of `dvc-capturing-lambda' are hard to predict and not what developers
naturally expect. Also, we wouldn't even be spending time discussing
this if we simply relied on the built-ins that others have already
debugged for us.
Christian.
_______________________________________________
Dvc-dev mailing list
[email protected]
https://mail.gna.org/listinfo/dvc-dev