Re: scope of function definition

Ralf Juengling <[email protected]>
Newsgroups gmane.lisp.lush.devel
Message-ID <[email protected]>
On Mon, 2005-04-25 at 08:20, Leon Bottou wrote:
> [...]
>
> In common lisp, <defvar> is used to define a variable that is dynamically scoped
> instead of lexically scoped.  Such variables happen to be global by necessity.
> 
> In lush, <defvar> is used to define a global variable regardless of the current environment.
> Of course this variable will be dynamically scoped because (1) the interpreter only
> handles dynamically scoped variables, and (2) the compiler does not handle global variables at all.
>
> The addition of <defvar> is part of a nifty long term transition plan:  
> First we slowly update all lush program to define global variables with <defvar>.
> At some point, all variables involved in dynamic scoping tricks will be declared in such a way.
> Then we can effortlessly transition to a CL semantic, where all variables are lexically scoped except
> those declared with defvar.  This change would eliminate the biggest semantic difference 
> between the interpreter and the compiler, make lush a better grounded language,
> and save us a few headaches.

Thanks for the clarification.

Clearly, lush is neither CL nor scheme. However, whenever you 
adopt a construct from either CL or scheme, it would be better to
keep with the established name for it. Currently, <defvar> in lush 
and <defvar> in CL have different semantics. In fact, lush's 
<defvar> mimics Cl's <defparameter>.
This kind of thing is bound to give headaches to folks who have
been exposed to other lisps and come to lush. It also makes it
harder to port lisp code written for CL, say.


> Until now <defun> was defined as an alias to <de>
> for the sake of people familar with common lisp and similar dialects.
> As Ralf notices, this is only a gross approximation.
> 
> We can make it a little bit better (but still far from perfect).
> >From now on, writing
>  (defun f(x) (+ x x)
> is equivalent to
>  (setq :f (lambda(x) (+ x x))  
> which is the same as
>  (defvar f (lambda(x) (+ x x)) 
> 
> This might be a little less confusing...

sounds good. you might add a <defmacro> as a globally binding version
of <dm> as well...

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.