Re: scope of function definition
Ralf Juengling <[email protected]>
| Newsgroups | gmane.lisp.lush.devel |
|---|---|
| Message-ID | <[email protected]> |
On Sun, 2005-04-24 at 12:23, Raymond wrote: > Ralf, > > > I noticed that de, df, dm etc. do the binding of function > > to symbol in lexical scope. > > > > ? (let ((f ())) (de f () 1)) > > = f > > ? f > > = () > > ? > > > > Unlike defvar, the descriptions for de etc. are not explicit > > about the scope of the binding. I think they should be explicit. > > You can only do the binding globally if you do not do it within a let. When you > use let you are in effect creating a new environment for everything contained inside > it. Once you go out of scope anything defined inside is gone and you go back to > the previous environment. [...] > The way you are proposing will cause the definition > of a new f in any sub environment to redefine the global f. yes, exactly. > That is not good and > can lead to many side effects and bugs in a program. Following your reasoning, what's the purpose of defvar then? We don't need it and should get rid off it? ? (let ((f 2)) (defvar f 1) f) = 2 ? f = 1 I'm not sure what behavior of de/df/dm is better. A disadvantage of the current behavior is that it might confuse lisp programmers that come newly to lush and expect de to behave like defvar. In any case, it should be spelled out in the help texts. Ralf ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click