[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Elisp lexical-let
From: |
Marijn Schouten (hkBst) |
Subject: |
Re: Elisp lexical-let |
Date: |
Fri, 24 Jul 2009 13:09:03 +0200 |
User-agent: |
Thunderbird 2.0.0.22 (X11/20090723) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Daniel Kraft wrote:
> Hi,
>
> thanks for your comments; I'm still a bit confused, though :$
>
> Marijn Schouten (hkBst) wrote:
>>> What's about this:
>>>
>>> (defun test () a)
>>> (let ((a 1))
>>> (print a) ; 1
>>> (print (test)) ; 1
>>> (lexical-set! a 2)
>> there is only one variable `a' in my mental model,
>> so this changes the value of the only `a' and all
>> subsequent expressions accessing `a' are thus affected.
>> The same as if you had written `(set! a 2)'. Dynamic
>> and lexical only differ in how free variables in
>> procedures are bound.
>>> (print a) ; 1?
>> no, (print a) => 2
>>> (print (test)) ; 1
>> no, there is only one `a' and its value is 2 here
>>> (print (lexical a)) ; 2
>>> )
>
> Hm... my problem is trying to understand how you want this implemented;
> my main point about lexical scoping is that it enables us to use Guile's
> built-in lexical mechanisms and we don't have to save the value
> explicitly into some fluids.
>
> But if you require that the second (print (test)) above prints 1 even
> though we have done (lexical-set! a) this means that lexical-set! must
> update the place somehow where a is accessed dynamically (as is done in
> test). And that seems to imply that this lexical-set! updates the
> fluids, even though it is meant to perform on a lexically bound variable
> a; just in case that "the one" a is at some place referred to dynamically.
In my proposal it is meaningless to say "lexically bound variable", as all
variables would in principal be accessible both lexically and dynamically.
>>> I don't think it's good to have to "completely seperate" variables a and
>>> (lexical a).
>>
>> I don't understand what you mean. My proposal is to have one kind of
>> variable
>> and two kinds of access.
>
> Can you please elaborate on this? If there's only one variable and only
> the value 2 after the lexical-set! above (both for (print a) in the
> lexical scope and (print (test)) which accesses a dynamically), what
> would then be the point of writing 'a' or '(lexical a)' and what would
> be the difference between those two?
(defvar x 3)
(defun dynx () x)
(dynx) ; => 3
(defun lexx () (lexical x))
(lexx) ; => 3
(defun incdynx () (setq x (+ x 1)))
(defun inclexx () (lexical-setq x (+ (lexical x) 1)))
(let ((x 5))
(dynx) ; => 5
(lexx) ; => 3
(lexical-setq x 6)
(dynx) ; => 6
(lexx) ; => 3
(setq x 7)
(dynx) ; => 7
(lexx) ; => 3
(incdynx)
(dynx) ; => 8
(lexx) ; => 3
(inclexx)
(dynx) ; => 8
(lexx) ; => 4
)
(dynx) ; => 4
(lexx) ; => 4
(incdynx)
(dynx) ; => 5
(lexx) ; => 5
(inclexx)
(dynx) ; => 6
(lexx) ; => 6
I hope I haven't made any mistakes there and that it explains what I have in
mind.
Marijn
- --
If you cannot read my mind, then listen to what I say.
Marijn Schouten (hkBst), Gentoo Lisp project, Gentoo ML
<http://www.gentoo.org/proj/en/lisp/>, #gentoo-{lisp,ml} on FreeNode
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAkpplk8ACgkQp/VmCx0OL2wFVACfV36PIQRwjQu3gGOc8Rly6h8Z
UKQAnA5yPPMBNJsoRoc70+5znTP10r6G
=SL2/
-----END PGP SIGNATURE-----
- Elisp lexical-let, Daniel Kraft, 2009/07/21
- Re: Elisp lexical-let, Ken Raeburn, 2009/07/21
- Re: Elisp lexical-let, Daniel Kraft, 2009/07/22
- Re: Elisp lexical-let, Marijn Schouten (hkBst), 2009/07/22
- Re: Elisp lexical-let, Daniel Kraft, 2009/07/22
- Re: Elisp lexical-let, Marijn Schouten (hkBst), 2009/07/23
- Re: Elisp lexical-let, Mark H Weaver, 2009/07/23
- Re: Elisp lexical-let, Andy Wingo, 2009/07/23
- Re: Elisp lexical-let, Daniel Kraft, 2009/07/23
- Re: Elisp lexical-let,
Marijn Schouten (hkBst) <=
- Re: Elisp lexical-let, Ken Raeburn, 2009/07/22
- Re: Elisp lexical-let, Daniel Kraft, 2009/07/23
- Re: Elisp lexical-let, Andy Wingo, 2009/07/23
- Re: Elisp lexical-let, Daniel Kraft, 2009/07/24
- Re: Elisp lexical-let, Andy Wingo, 2009/07/23
Re: Elisp lexical-let, Andy Wingo, 2009/07/23