Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Dynamic binding
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
His Holiness the Reverend Doktor Xenophon Fenderson, the Carbon(d)ated  
View profile  
 More options Mar 21 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: "His Holiness the Reverend Doktor Xenophon Fenderson, the Carbon(d)ated" <xenop...@irtnog.org>
Date: 1999/03/21
Subject: Dynamic binding
I'm not certain I understand dynamic binding correctly.  Here's the
example code I cooked up (being run under ACL5 on Linux):

(DEFVAR B 1)
=> B
(DEFUN FOO (A) (CONS A B))
=> FOO
(DEFUN BAR (B) (FOO 'A))
=> BAR
(DEFUN BAZ (B) (DECLAIM (SPECIAL B)) (FOO 'A))
=> BAZ
(BAR 'B)
=> (A . B) ; shouldn't that be "(A . 1)"?
(BAZ 'B)
=> (A . B) ; as expected (?)

I thought that (DECLAIM (SPECIAL B)) extends the dynamic environment
with the value of B from the lexical environment, and that the free
variable B in FOO would have dynamic binding.  I'm trying to follow
Queinnec's descriptions of dynamic vs. lexical bindings in chapter 1
of _Lisp in Small Pieces_ (page 19 in my copy), along with the
HyperSpec's description of Lisp's evaluator in section 3.  Er, help?

--
Rev. Dr. Xenophon Fenderson, the Carbon(d)ated, KSC, DEATH, SubGenius, mhm21x16
Pope, Patron Saint of All Things Plastic fnord, and Salted Litter of r.g.s.b
In a lecture, Werner von Braun once said "Ve haf alvays been aiming for zer
stars" and a little voice at the back replied "But ve keep hittink London".


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Innes  
View profile  
 More options Mar 21 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Andrew Innes <andr...@harlequin.co.uk>
Date: 1999/03/21
Subject: Re: Dynamic binding
On 21 Mar 1999 15:18:44 -0500, "His Holiness the Reverend Doktor Xenophon Fenderson, the Carbon(d)ated" <xenop...@irtnog.org> said:

No, it declares that the enclosing binding is dynamic, not lexical.  Any
lexically apparent binding is hidden.

>and that the free
>variable B in FOO would have dynamic binding.

It does, and so does the argument binding of BAR because DEFVAR
proclaims B to be special everywhere.

AndrewI

--
Andrew Innes                  Software Developer, Intelligence Products
Harlequin Limited, Barrington Hall, Barrington, Cambridge CB2 5RG, U.K.
Tel: +44 1223 873868  Fax: +44 1223 873873     http://www.harlequin.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kent M Pitman  
View profile  
 More options Mar 21 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Kent M Pitman <pit...@world.std.com>
Date: 1999/03/21
Subject: Re: Dynamic binding
"His Holiness the Reverend Doktor Xenophon Fenderson, the Carbon(d)ated" <xenop...@irtnog.org> writes:

> I'm not certain I understand dynamic binding correctly.  Here's the
> example code I cooked up (being run under ACL5 on Linux):

> (DEFVAR B 1)
> => B

This declares B special in all subsequent uses, whether or not there
is an accompanying declare.  It can't be retracted nor lexically shadowed.
(It can be shadowed by making a new package, of course.)

> (DEFUN BAZ (B) (DECLAIM (SPECIAL B)) (FOO 'A))
> => BAZ

Use DECLAIM only at top-level.  Doing it in a program won't do what
you expect.  Use only DECLARE in programs.  Use either DECLAIM or
PROCLAIM at top-level.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
His Holiness the Reverend Doktor Xenophon Fenderson, the Carbon(d)ated  
View profile  
 More options Mar 21 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: "His Holiness the Reverend Doktor Xenophon Fenderson, the Carbon(d)ated" <xenop...@irtnog.org>
Date: 1999/03/21
Subject: Re: Dynamic binding

>>>>> "KMP" == Kent M Pitman <pit...@world.std.com> writes:
>>>>> "me" == "Xenophon Fenderson, the Carbon(d)ated" <xenop...@irtnog.org> writes:

    me> I'm not certain I understand dynamic binding correctly.  Here's
    me> the example code I cooked up (being run under ACL5 on Linux):
    me>
    me> (DEFVAR B 1) => B

    KMP> This declares B special in all subsequent uses, whether or
    KMP> not there is an accompanying declare.  It can't be retracted
    KMP> nor lexically shadowed. (It can be shadowed by making a new
    KMP> package, of course.)

Ah, I understand.  If I replace "(DEFVAR B 1)" with "(SETQ B 1)",
"(SPECIAL B)" works as expected.

    me> (DEFUN BAZ (B) (DECLAIM (SPECIAL B)) (FOO 'A)) => BAZ

    KMP> Use DECLAIM only at top-level.  Doing it in a program won't
    KMP> do what you expect.  Use only DECLARE in programs.  Use
    KMP> either DECLAIM or PROCLAIM at top-level.

Yeah, once I read a little further down in the definition of SPECIAL I
realized I'd made an error.

--
Rev. Dr. Xenophon Fenderson, the Carbon(d)ated, KSC, DEATH, SubGenius, mhm21x16
Pope, Patron Saint of All Things Plastic fnord, and Salted Litter of r.g.s.b
In a lecture, Werner von Braun once said "Ve haf alvays been aiming for zer
stars" and a little voice at the back replied "But ve keep hittink London".


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vassil Nikolov  
View profile  
 More options Mar 22 1999, 3:00 am
Newsgroups: comp.lang.lisp
From: Vassil Nikolov <vniko...@poboxes.com>
Date: 1999/03/22
Subject: Re: Dynamic binding
In addition to the explanations in the other posting, consider this
variation of your example:

;; no DEFVAR of B

> (setf b 'g)  ;give it a global value but don't make it dynamic everywhere
G
> (defun foo (a) (cons a b))

;; maybe a warning about assuming B special
FOO
> (defun lex-bar (b) (foo 'lex))
LEX-BAR
> (defun dyn-bar (b)

    (declare (special b))  ;DECLAIM is usually top level only
    (foo 'dyn))
DYN-BAR
> (lex-bar 'val)

(LEX . G) ;LEX-BAR binds its parameter lexically so FOO doesn't see that
> (dyn-bar 'val)

(DYN . VAL) ;FOO sees the binding of B made by DYN-BAR

In the above example, B is not globally declared (proclaimed) special
(which it would have been with DEFVAR), but just in specific places.

Disclaimer: I have not actually run this example (sorry, too lazy),
please run it!

> I thought that (DECLAIM (SPECIAL B)) extends the dynamic environment
> with the value of B from the lexical environment.

(...)

DECLAIM does something else, but I won't go into it as I think you
were thinking about DECLARE here.  (After you have things about
declarations clear, read the description of DECLAIM.)

Now (DECLARE (SPECIAL B)) means: within the scope of this declaration
treat all references to B as references to a dynamic variable, ignoring
any lexical bindings that might otherwise be in force.  `The scope of
this declaration' is the form in which this declaration appears including
any nested forms *but* excluding nested forms like LET and DO that bind
B.  (Well, this is just a rough description; consult the literature for
the Real Thing.)

If you want (I can't think of a reason) to `extend the dynamic
environment with the value of B from the lexical environment' you
can do e.g.

  (let ((x b))
    (declare (special x))
    ...)

or

  (defvar x 'init "my starless and bible black global variable")
  ...
  (let ((x b)) ...)

---assuming that B is a lexical variable in the scope that surrounds
this LET---and for the duration of the execution of the LET, anywhere
in the program text (i.e. not just in the textual body of the LET),
the binding for X in the dynamic environment (until changed) would
have B's value.  Now if you rename X as B in the above example, you
get a lexical B and a dynamic B.  I hope you are not too confused.

Good luck, and keep asking questions until you are sure you get it,
Vassil.

P.S.  Beware of analogies with other programming languages like C:
some things about variables are similar and some are very different.

Vassil Nikolov <vniko...@poboxes.com> www.poboxes.com/vnikolov
(You may want to cc your posting to me if I _have_ to see it.)
   LEGEMANVALEMFVTVTVM  (Ancient Roman programmers' adage.)

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »