Re: scope of function definition
Leon Bottou <[email protected]>
| Newsgroups | gmane.lisp.lush.devel |
|---|---|
| Message-ID | <[email protected]> |
On Monday 25 April 2005 02:01 pm, Leon Bottou wrote: > On Monday 25 April 2005 12:22 pm, Ralf Juengling wrote: > > 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>. > > I could emulate the defvar/defparameter semantic. Done > > You might add a <defmacro> as a globally binding version of <dm> as well. Done. ------------------------------------------------------------------------ (defvar <name> [<val>]) [DM](sysenv.lsh) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Defines a new global variable name . Argument name must be an unquoted symbol. * If there was already an existing global variable name , function defvar does nothing. Argument val is not even evaluated. * If there was no existing global variable name , function defvar defines such a global variable, and initializes it with the result of the evaluation of argument val . Traditionally function setq was used for that purpose in SN/TLisp because there was no notion of undefined global variables. All undefined global variables were assumed to contain an empty list. This behavior was the source of many bugs. The lush kernel now prints a warning when using setq to define a new global variable. ------------------------------------------------------------------------ (defparameter <name> [<val>]) [DM](sysenv.lsh) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . * See: (defvar name [ val ]) Defines a new global variable name initialized with value val . Argument name must be an unquoted symbol. Unlike defvar , this function unconditionally evaluates val and sets the variable value. ------------------------------------------------------------------------ (defun <name> <args> ...<body>...) [DM](sysenv.lsh) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . * See: (de symb args . body ) * See: (defmacro name args ... body ...) * See: (defvar name [ val ]) Function defun defines a global DE function named name . Whereas function de defines symbol name in the current scope, function defun defines symbol name in the global scope. ------------------------------------------------------------------------ (defmacro <name> <args> ...<body>...) [DM](sysenv.lsh) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . * See: (de symb args . body ) * See: (defun name args ... body ...) * See: (defvar name [ val ]) Function defun defines a global DM function named name . Whereas function dm defines symbol name in the current scope, function defun defines symbol name in the global scope. The argument list args only matches the arguments of the macro. It should not contain a symbol for matching the function name itself. ------------------------------------------------------- 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