From ... Path: supernews.google.com!sn-xit-02!supernews.com!isdnet!newsfeeds.belnet.be!news.belnet.be!news.tele.dk!129.240.148.23!uio.no!Norway.EU.net!127.0.0.1!nobody From: Erik Naggum Newsgroups: comp.lang.lisp Subject: Re: distinction? Date: 08 Dec 2000 01:45:50 +0000 Organization: Naggum Software; vox: +47 800 35477; gsm: +47 93 256 360; fax: +47 93 270 868; http://naggum.no; http://naggum.net Lines: 71 Message-ID: <3185228750011668@naggum.net> References: <3a2962c9@news.infinetgroup.com> <3184845254046912@naggum.net> <3185032506447343@naggum.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: oslo-nntp.eunet.no 976241821 2653 195.0.192.66 (8 Dec 2000 02:17:01 GMT) X-Complaints-To: newsmaster@eunet.no NNTP-Posting-Date: 8 Dec 2000 02:17:01 GMT mail-copies-to: never User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.7 Xref: supernews.google.com comp.lang.lisp:4889 * Xenophon Fenderson the Carbon(d)ated | I'm pretty clueless when it comes to dynamic scope. At least you recognize that. A lot of Scheme people think they know everything about dynamic scope when they are clueless about it. | Why is it so useful? Because it embodies intrinsic language support for the protocol that surrounds every _sane_ use of global variables (or more precisely, variables with indefinite scope -- referenceable from everywhere). Namely, if you bind a special variable, you are guaranteed that it will be restored to the value it had when you entered the dynamic extent when you exit that scope, regardless of errors, signals, non- local transfers of control, anything. Implementing this yourself is terribly hard and can get so low-level most programmers and language designers alike just give up and live with errors in restoring the old value. Typically, however, you don't even _have_ binding forms for global variables in languages that do not support special variables, so you end up _having_ to use a local copy and set and restore the global variable yourself. (let ((*print-base* 16)) ...) is in principle functionally similar to this: (let ((old-print-base *print-base*)) (unwind-protect (progn (setq *print-base* 16) ....) (setq *print-base* old-print-base))) although the differences will be very noticeable if you have parallel bindings, such as you have in a multiprocessing environment, with one binding per thread/process of this variable. Special variable binding takes care of all this. | i doubt I understand even what dynamic scope really is. Well, it's a misnomer, so that's not so strange. "Dynamic scope" is short-hand for "indefinite scope, dynamic extent". That is, you can value from anywhere (indefinite/global scope), but that particular binding extends from binding establishment through disestablishment, which looks just like a lexical binding in that it covers only so much code, but because of the indefinite scope, it actually covers all code that gets executed between binding establishment and disestablishment. | I grew up using Scheme, so I'm used to DEFINE creating a binding in | the top-most environment. Well, this is one instance of what I consider damaging in premature exposure to Scheme. It is too damn low-level and _unevolved_ as a language, yet it looks amazingly complex and rich through its simple elegance (which fools mostly any intellectual, just like simple and elegant and wrong political theories trap bright students) until you start to figure out the kind of complexity the real world needs. | I fail to see how dynamic scope is any different from top-most-level | bindings, although dynamic bindings established in one function can | affect another, right? I hope this has helped. #:Erik -- "When you are having a bad day and it seems like everybody is trying to piss you off, remember that it takes 42 muscles to produce a frown, but only 4 muscles to work the trigger of a good sniper rifle." -- Unknown