From ... From: Erik Naggum Subject: Re: beginner question Date: 1998/04/28 Message-ID: <3102745327716241@naggum.no>#1/1 X-Deja-AN: 348365493 References: <353F12C5.4FFC20F2@csst.cs.technion.ac.il> <6hp3jt$4t984@fido.asd.sgi.com> <3102397945639898@naggum.no> <6i3u09$6clm@fido.asd.sgi.com> mail-copies-to: never Organization: Naggum Software; +47 8800 8879; http://www.naggum.no Newsgroups: comp.lang.lisp * Rob Warnock | But that really wasn't the quesion I was asking! To rephrase it in the | context of your example, suppose when you write the code you give, there's | *already* a top-level variable named "line-counter" -- which, as several | people have answered me, is necessarily "special" (dynamic). So now instead | of getting a new lexical variable "line-counter" for your functions "foo" & | "bar" to share privately, you have perturbed the value of the global dynamic | variable "line-counter", and if either "foo" or "bar" calls a function that | uses "line-counter", unexpectedness will happen... (Won't it?) if you don't stick to the very good convention to use asterisks around special variables, the expected unexpectedness will happen. that's why you _always_ want to use asterisks around special variables. there is no (declare (nospecial ...)), unfortunately. (I think there should be.) | As someone else pointed out, the way you do what you want in Scheme is: | | (define foo #f) | (define bar #f) | (let ((line-counter 0)) | (set! foo (lambda (...) ...)) | (set! bar (lambda (...) ...))) | | (which is basically identical to the usual expansion of "letrec"...) let's see some elegant syntax for it, now that you have DEFINE-SYNTAX to play with, and I'll perhaps modify my statement. the above (the use of internal vs top-level DEFINE in general, actually) is such a horribly klutzy way of doing things that my knee-jerk reaction is "inelegant by design". Schemers don't think so -- they have already decided that Scheme is elegant, and that this is "necessary", although they keep arguing that "necessary" translates to "inelegant" in Common Lisp. I find it moderately amusing to tease Schemers with instances like this. #:Erik -- Abort, Retry, or Upgrade?