Christian Ohler <[EMAIL PROTECTED]> writes:

> 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?

No.  Only the value of the symbol is captured, not the symbol itself.
That is the intent of dvc-capturing-lambda.

Now if you were to do:

(funcall
 (let ((a 0))
   (dvc-capturing-lambda ()
     (incf (capture a))
     (incf (capture a)))))

You would get 2.  That was the point of my recent change to the code.
If you wanted to retain the value across calls, you would use a
buffer-local variable instead.

It kind of irritates me that a single flippant and completely
unimportant remark that I made in the "Incremental parsing of log
output" message about ways to retain state has led to a witch hunt about
dvc-capturing-lambda.  For the record, I was incorrect in suggesting
that dvc-capturing-lambda be used to track state; in retrospect, it was
obviously wrong.

> 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.

dvc-capturing-lambda is not meant to be a full-fledged replacement for
lexical-let, so it is meaningless to compare them.  It is not meant to
be used in a nested fashion; it does not weave through its body argument
in a complicated and time-consuming way, trying to not clobber function
args and the like; it just captures the value of an explicitly-denoted
symbol at call-time.

-- 
       Michael Olson -- FSF Associate Member #652     |
 http://mwolson.org/ -- Jabber: mwolson_at_hcoop.net  |  /` |\ | | |
            Sysadmin -- Hobbies: Lisp, GP2X, HCoop    | |_] | \| |_|
Projects: Emacs, Muse, ERC, EMMS, ErBot, DVC, Planner |

Attachment: pgph21SFiFpAu.pgp
Description: PGP signature

_______________________________________________
Dvc-dev mailing list
[email protected]
https://mail.gna.org/listinfo/dvc-dev

Reply via email to