10-functions.lpt 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. PSL Manual 7 February 1983 Function Definition
  2. section 10.0 page 10.1
  3. CHAPTER 10 CHAPTER 10 CHAPTER 10
  4. FUNCTION DEFINITION AND BINDING FUNCTION DEFINITION AND BINDING FUNCTION DEFINITION AND BINDING
  5. 10.1. Function Definition in PSL . . . . . . . . . . 10.1
  6. 10.1.1. Notes on Code Pointers . . . . . . . . . 10.1
  7. 10.1.2. Functions Useful in Function Definition. . . . 10.2
  8. 10.1.3. Function Definition in LISP Syntax . . . . . 10.4
  9. 10.1.4. Function Definition in RLISP Syntax . . . . . 10.6
  10. 10.1.5. Low Level Function Definition Primitives . . . 10.6
  11. 10.1.6. Function Type Predicates. . . . . . . . . 10.7
  12. 10.2. Variables and Bindings. . . . . . . . . . . . 10.8
  13. 10.2.1. Binding Type Declaration. . . . . . . . . 10.8
  14. 10.2.2. Binding Type Predicates . . . . . . . . . 10.9
  15. 10.3. User Binding Functions. . . . . . . . . . . . 10.10
  16. 10.3.1. Funargs, Closures and Environments . . . . . 10.10
  17. 10.1. Function Definition in PSL 10.1. Function Definition in PSL 10.1. Function Definition in PSL
  18. Functions in PSL are GLOBAL entities. To avoid function-variable naming
  19. clashes, the Standard LISP Report required that no variable have the same
  20. name as a function. There is no conflict in PSL, as separate function
  21. cells and value cells are used. A warning message is given for
  22. compatibility. The first major section in this chapter describes how to
  23. define new functions; the second describes the binding of variables in PSL.
  24. The final section presents binding functions useful in building new
  25. interpreter functions.
  26. 10.1.1. Notes on Code Pointers 10.1.1. Notes on Code Pointers 10.1.1. Notes on Code Pointers
  27. Print ____ _______ Print A code-pointer may be displayed by the Print functions or expanded by
  28. Explode Explode Explode. The value appears in the convention of the implementation
  29. (#<Code:a nnnn>, where a is the number of arguments of the function, and
  30. ____ _______ nnnn is the function's entry point, on the DEC-20 and VAX). A code-pointer
  31. Compress Compress may not be created by Compress. (See Chapter 12 for descriptions of
  32. Explode Compress Explode Compress ____ _______ Explode and Compress.) The code-pointer associated with a compiled
  33. GetD GetD function may be retrieved by GetD and is valid as long as PSL is in
  34. execution (on the DEC-20 and VAX, compiled code is not relocated, so
  35. PutD ____ _______ ____ _______ PutD code-pointers do not change). A code-pointer may be stored using PutD,
  36. Put SetQ Put SetQ Put, SetQ and the like or by being bound to a variable. It may be checked
  37. Eq Eq ____ _______ for equivalence by Eq. The value may be checked for being a code-pointer
  38. CodeP CodeP by the CodeP function. Function Definition 7 February 1983 PSL Manual
  39. page 10.2 section 10.1
  40. 10.1.2. Functions Useful in Function Definition 10.1.2. Functions Useful in Function Definition 10.1.2. Functions Useful in Function Definition
  41. __ In PSL, ids have a function cell that usually contains an executable
  42. instruction which either JUMPs directly to the entry point of a compiled
  43. function or executes a CALL to an auxiliary routine that handles
  44. interpreted functions, undefined functions, or other special services (such
  45. ________ as auto-loading functions, etc). The user can pass anonymous function
  46. ____ _______ objects around either as a code-pointer, which is a tagged object referring
  47. ______ to a compiled code block, or a lambda expression, representing an
  48. interpreted function.
  49. PutD PutD _____ __ ____ _____ ____ ______ ____ _______ __ ____ (PutD FNAME:id TYPE:ftype BODY:{lambda,code-pointer}): id expr
  50. _____ ____ ____ Creates a function with name FNAME and type TYPE, with BODY as
  51. PutD PutD the function definition. If successful, PutD returns the name of
  52. the defined function.
  53. ____ _______ If the body is a code-pointer or is compiled (i.e. !*COMP=T as
  54. the function was defined), a special instruction to jump to the
  55. start of the code is placed in the function cell. If it is a
  56. ______ lambda, the lambda expression is saved on the property list under
  57. the indicator !*LAMBDALINK and a call to an interpreter function
  58. LambdaLink LambdaLink (LambdaLink) is placed in the function cell.
  59. ____ ____ _____ The TYPE is recorded on the property list of FNAME if it is not
  60. ____ ____ ____ expr expr an expr.
  61. [??? We need to add code to check that the the arglist has no [??? We need to add code to check that the the arglist has no [??? We need to add code to check that the the arglist has no
  62. more than 15 arguments for exprs, 1 argument for fexprs and more than 15 arguments for exprs, 1 argument for fexprs and more than 15 arguments for exprs, 1 argument for fexprs and
  63. macros, and ??? for nexprs. Declaration mechanisms to avoid macros, and ??? for nexprs. Declaration mechanisms to avoid macros, and ??? for nexprs. Declaration mechanisms to avoid
  64. overhead also need to be available. (In fact are available overhead also need to be available. (In fact are available overhead also need to be available. (In fact are available
  65. for the compiler, although still poorly documented.) When for the compiler, although still poorly documented.) When for the compiler, although still poorly documented.) When
  66. should we expand macros? ???] should we expand macros? ???] should we expand macros? ???]
  67. PutD GetD PutD _____ GetD ____ _____ After using PutD on FNAME, GetD returns a pair of the the FNAME's
  68. ____ ____ (TYPE . BODY).
  69. GlobalP GlobalP The GlobalP predicate returns T if queried with the defined
  70. _____ function's name. If the function FNAME has already been declared
  71. as a GLOBAL or FLUID variable the warning:
  72. *** FNAME is a non-local variable
  73. _____ occurs, but the function is defined. If function FNAME is
  74. already defined, a warning message appears:
  75. *** Function FNAME has been redefined
  76. ____ Note: All function types may be compiled.
  77. The following switches are useful when defining functions. PSL Manual 7 February 1983 Function Definition
  78. section 10.1 page 10.3
  79. __________ ______ !*REDEFMSG [Initially: T] switch
  80. If !*REDEFMSG is not NIL, the message
  81. *** Function `FOO' has been redefined
  82. is printed whenever a function is redefined.
  83. __________ ______ !*USERMODE [Initially: T] switch
  84. Controls action on redefinition of a function. All functions
  85. defined if !*USERMODE is T are flagged USER. Functions which are
  86. flagged USER can be redefined freely. If an attempt is made to
  87. redefine a function which is not flagged USER, the query
  88. Do you really want to redefine the system function `FOO'?
  89. is made, requiring a Y, N, YES, NO, or B response. B starts the
  90. break loop, so that one can change the setting of !*USERMODE.
  91. After exiting the break loop, one must answer Y, Yes, N, or No.
  92. YesP YesP See YesP in Chapter 13. If !*UserMode is NIL, all functions can
  93. be redefined freely, and all functions defined have the USER flag
  94. removed. This provides some protection from redefining system
  95. functions.
  96. __________ ______ !*COMP [Initially: NIL] switch
  97. PutD PutD The value of !*COMP controls whether or not PutD compiles the
  98. function defined in its arguments before defining it. If !*COMP
  99. is NIL the function is defined as a lambda expression. If !*COMP
  100. is non-NIL, the function is first compiled. Compilation produces
  101. certain changes in the semantics of functions, particularly FLUID
  102. type access.
  103. GetD GetD _ ___ ___ ____ ____ (GetD U:any): {NIL, pair} expr
  104. _ If U is not the name of a defined function, NIL is returned. If
  105. _ ____ U is a defined function then the pair
  106. ____ _____ _____ _____ ____ _____ _____ _____ ____ _____ _____ _____ expr, fexpr, macro, nexpr expr, fexpr, macro, nexpr ____ _______ ______ ({expr, fexpr, macro, nexpr} . {code-pointer, lambda}) is
  107. returned.
  108. CopyD CopyD ___ __ ___ __ ___ __ ____ (CopyD NEW:id OLD:id): NEW:id expr
  109. ___ ___ The function body and type for NEW become the same as OLD. If no
  110. ___ definition exists for OLD an error:
  111. ***** OLD has no definition in COPYD Function Definition 7 February 1983 PSL Manual
  112. page 10.4 section 10.1
  113. ___ is given. NEW is returned.
  114. RemD RemD _ __ ___ ____ ____ (RemD U:id): {NIL, pair} expr
  115. _ Removes the function named U from the set of defined functions.
  116. GetD ____ GetD Returns the (ftype . function) pair or NIL, as does GetD. The
  117. ________ _ function type attribute of U is removed from the property list of
  118. _ U.
  119. 10.1.3. Function Definition in LISP Syntax 10.1.3. Function Definition in LISP Syntax 10.1.3. Function Definition in LISP Syntax
  120. De Df Dn Dm Ds De Df Dn Dm Ds The functions De, Df, Dn, Dm, and Ds are most commonly used in the LISP
  121. syntax form of PSL. They are difficult to use from RLISP as there is not a
  122. convenient way to represent the argument list. The functions are compiled
  123. if the compiler is loaded and the GLOBAL !*COMP is T.
  124. De De _____ __ ______ __ ____ __ ____ __ _____ (De FNAME:id PARAMS:id-list [FN:form]): id macro
  125. ____ ____ ____ expr _____ expr ____ __ Defines the function named FNAME, of type expr. The forms FN are
  126. made into a lambda expression with the formal parameter list
  127. 1
  128. ______ PARAMS, and this is used as the body of the function.
  129. Previous definitions of the function are lost. The name of the
  130. _____ defined function, FNAME, is returned.
  131. Df Df _____ __ _____ __ ____ __ ___ __ _____ (Df FNAME:id PARAM:id-list FN:any): id macro
  132. _____ _____ _____ fexpr _____ fexpr ____ __ Defines the function named FNAME, of type fexpr. The forms FN
  133. are made into a lambda expression with the formal parameter list
  134. ______ PARAMS, and this is used as the body of the function.
  135. Previous definitions of the function are lost. The name of the
  136. _____ defined function, FNAME, is returned.
  137. Dn Dn _____ __ _____ __ ____ __ ___ __ _____ (Dn FNAME:id PARAM:id-list FN:any): id macro
  138. _____ _____ _____ nexpr _____ nexpr ____ __ Defines the function named FNAME, of type nexpr. The forms FN
  139. are made into a lambda expression with the formal parameter list
  140. ______ PARAMS, and this is used as the body of the function.
  141. _______________
  142. 1
  143. Or the compiled code pointer for the lambda expression if the compiler
  144. is on. PSL Manual 7 February 1983 Function Definition
  145. section 10.1 page 10.5
  146. Previous definitions of the function are lost. The name of the
  147. _____ defined function, FNAME, is returned.
  148. Dm Dm _____ __ _____ __ ____ __ ___ __ _____ (Dm MNAME:id PARAM:id-list FN:any): id macro
  149. _____ _____ _____ macro _____ macro ____ __ Defines the function named FNAME, of type macro. The forms FN
  150. are made into a lambda expression with the formal parameter list
  151. ______ PARAMS, and this is used as the body of the function.
  152. Previous definitions of the function are lost. The name of the
  153. _____ defined function, FNAME, is returned.
  154. Ds Ds _____ __ _____ __ ____ __ ___ __ _____ (Ds SNAME:id PARAM:id-list FN:any): id macro
  155. ______ _______ ______ _______ ______ _______ smacro Smacros smacro _____ Smacros Defines the smacro SNAME. Smacros are actually a syntactic
  156. _____ _____ _____ macro macro notation for a special class of macros, those that essentially
  157. treat the macro's argument as a list of arguments to be
  158. substituted into the body of the expression and then expanded in
  159. _____ _____ _____ macro macro line, rather than using the computational power of the macro to
  160. defmacro defmacro customize code. Thus they are a special case of defmacro. See
  161. also the BackQuote facility.
  162. For example:
  163. Lisp syntax:
  164. To make a substitution macro for
  165. FIRST ->CAR we could say
  166. (DM FIRST(X)
  167. (LIST 'CAR (CADR X)))
  168. Instead the following is clearer
  169. (DS FIRST(X)
  170. (CAR X))
  171. 10.1.4. Function Definition in RLISP Syntax 10.1.4. Function Definition in RLISP Syntax 10.1.4. Function Definition in RLISP Syntax
  172. [??? THIS IS NOT SUFFICIENT DOCUMENTATION! Either move it all to [??? THIS IS NOT SUFFICIENT DOCUMENTATION! Either move it all to [??? THIS IS NOT SUFFICIENT DOCUMENTATION! Either move it all to
  173. chapter 3 or do a better job here. ???] chapter 3 or do a better job here. ???] chapter 3 or do a better job here. ???]
  174. In RLISP syntax, procedures are defined by using the Procedure construct,
  175. as discussed in Chapter 3.
  176. mode type PROCEDURE name(args);
  177. body;
  178. where mode is SYSLISP or LISP or SYMBOLIC and defaults to LISP, and type
  179. defaults to EXPR. Function Definition 7 February 1983 PSL Manual
  180. page 10.6 section 10.1
  181. 10.1.5. Low Level Function Definition Primitives 10.1.5. Low Level Function Definition Primitives 10.1.5. Low Level Function Definition Primitives
  182. PutD GetD PutD GetD The following functions are used especially by PutD and GetD, defined
  183. Eval Apply Eval Apply above in Section 10.1.2, and by Eval and Apply, defined in Chapter 11.
  184. FUnBoundP FUnBoundP _ __ _______ ____ (FUnBoundP U:id): boolean expr
  185. ________ _ Tests whether there is a definition in the function cell of U;
  186. returns NIL if so, T if not.
  187. Note: Undefined functions actually call a special function,
  188. UndefinedFunction Error FUnBoundP UndefinedFunction Error FUnBoundP UndefinedFunction, that invokes Error. FUnBoundP defines
  189. UndefinedFunction UndefinedFunction "unbound" to mean "calls UndefinedFunction".
  190. FLambdaLinkP FLambdaLinkP _ __ _______ ____ (FLambdaLinkP U:id): boolean expr
  191. _ Tests whether U is an interpreted function; return T if so, NIL
  192. if not. This is done by checking for the special code-address of
  193. lambdaLink lambdaLink the lambdaLink function, which calls the interpreter.
  194. FCodeP FCodeP _ __ _______ ____ (FCodeP U:id): boolean expr
  195. _ Tests whether U is a compiled function; returns T if so, NIL if
  196. not.
  197. MakeFUnBound MakeFUnBound _ __ ___ ____ (MakeFUnBound U:id): NIL expr
  198. _ Makes U an undefined function by planting a special call to an
  199. UndefinedFunction UndefinedFunction ________ _ error function, UndefinedFunction, in the function cell of U.
  200. MakeFLambdaLink MakeFLambdaLink _ __ ___ ____ (MakeFLambdaLink U:id): NIL expr
  201. _ Makes U an interpreted function by planting a special call to an
  202. lambdaLink lambdaLink interpreter support function (lambdaLink) function in the
  203. ________ _ function cell of U.}
  204. MakeFCode MakeFCode _ __ _ ____ _______ ___ ____ (MakeFCode U:id C:code-pointer): NIL expr
  205. _ Makes U a compiled function by planting a special JUMP to the
  206. _ code-address associated with C.
  207. GetFCodePointer GetFCodePointer _ __ ____ _______ ____ (GetFCodePointer U:id): code-pointer expr
  208. ____ _______ _ Gets the code-pointer for U. PSL Manual 7 February 1983 Function Definition
  209. section 10.1 page 10.7
  210. Code!-Number!-Of!-Arguments Code!-Number!-Of!-Arguments _ ____ _______ ___ _______ ____ (Code!-Number!-Of!-Arguments C:code-pointer): {NIL,integer} expr
  211. Some compiled functions have the argument number they expect
  212. _ stored in association with the codepointer C. This integer, or
  213. NIL is returned.
  214. _____ ____ _____ ____ _____ ____ [??? Should be extended for nexprs and declared exprs. ???] [??? Should be extended for nexprs and declared exprs. ???] [??? Should be extended for nexprs and declared exprs. ???]
  215. 10.1.6. Function Type Predicates 10.1.6. Function Type Predicates 10.1.6. Function Type Predicates
  216. See Section 2.7 for a discussion of the function types available in PSL.
  217. ExprP ExprP _ ___ _______ ____ (ExprP U:any): boolean expr
  218. ____ ____ ____ expr _ ____ _______ ______ __ expr Test if U is a code-pointer, lambda form, or an id with expr
  219. definition.
  220. FExprP FExprP _ ___ _______ ____ (FExprP U:any): boolean expr
  221. _____ _____ _____ fexpr _ __ fexpr Test if U is an id with fexpr definition.
  222. NExprP NExprP _ ___ _______ ____ (NExprP U:any): boolean expr
  223. _____ _____ _____ nexpr _ __ nexpr Test if U is an id with nexpr definition.
  224. MacroP MacroP _ ___ _______ ____ (MacroP U:any): boolean expr
  225. _____ _____ _____ macro _ __ macro Test if U is an id with macro definition.
  226. 10.2. Variables and Bindings 10.2. Variables and Bindings 10.2. Variables and Bindings
  227. __ Variables in PSL are ids, and associated values are usually stored in and
  228. __ retrieved from the value cell of this id. If variables appear as
  229. Prog Prog parameters in lambda expressions or in Prog's, the contents of the value
  230. cell are saved on a binding stack. A new value or NIL is stored in the
  231. Prog Prog value cell and the computation proceeds. On exit from the lambda or Prog
  232. the old value is restored. This is called the "shallow binding" model of
  233. LISP. It is chosen to permit compiled code to do binding efficiently. For
  234. even more efficiency, compiled code may eliminate the variable names and
  235. simply keep values in registers or a stack. The scope of a variable is the
  236. range over which the variable has a defined value. There are three
  237. different binding mechanisms in PSL.
  238. LOCAL BINDING Only compiled functions bind variables locally. Local Function Definition 7 February 1983 PSL Manual
  239. page 10.8 section 10.2
  240. variables occur as formal parameters in lambda expressions
  241. Prog Prog and as LOCAL variables in Prog's. The binding occurs as a
  242. Prog Prog lambda expression is evaluated or as a Prog form is
  243. executed. The scope of a local variable is the body of the
  244. function in which it is defined.
  245. FLUID BINDING FLUID variables are GLOBAL in scope but may occur as formal
  246. Prog Prog parameters or Prog form variables. In interpreted
  247. functions, all formal parameters and LOCAL variables are
  248. considered to have FLUID binding until changed to LOCAL
  249. binding by compilation. A variable can be treated as a
  250. FLUID only by declaration. If FLUID variables are used as
  251. parameters or LOCALs they are rebound in such a way that the
  252. previous binding may be restored. All references to FLUID
  253. variables are to the currently active binding. Access to
  254. the values is by name, going to the value cell.
  255. GLOBAL BINDING GLOBAL variables may never be rebound. Access is to the
  256. value bound to the variable. The scope of a GLOBAL variable
  257. is universal. Variables declared GLOBAL may not appear as
  258. Prog Prog parameters in lambda expressions or as Prog form variables.
  259. A variable must be declared GLOBAL prior to its use as a
  260. GLOBAL variable since the default type for undeclared
  261. variables is FLUID. Note that the interpreter does not stop
  262. one from rebinding a global variable. The compiler will
  263. issue a warning in this situation.
  264. 10.2.1. Binding Type Declaration 10.2.1. Binding Type Declaration 10.2.1. Binding Type Declaration
  265. Fluid Fluid ______ __ ____ ___ ____ (Fluid IDLIST:id-list): NIL expr
  266. __ ______ __ The ids in IDLIST are declared as FLUID type variables (ids not
  267. ______ previously declared are initialized to NIL). Variables in IDLIST
  268. already declared FLUID are ignored. Changing a variable's type
  269. from GLOBAL to FLUID is not permissible and results in the error:
  270. ***** ID cannot be changed to FLUID
  271. Global Global ______ __ ____ ___ ____ (Global IDLIST:id-list): NIL expr
  272. __ ______ __ The ids of IDLIST are declared GLOBAL type variables. If an id
  273. has not been previously declared, it is initialized to NIL.
  274. Variables already declared GLOBAL are ignored. Changing a
  275. variable's type from FLUID to GLOBAL is not permissible and
  276. results in the error:
  277. ***** ID cannot be changed to GLOBAL PSL Manual 7 February 1983 Function Definition
  278. section 10.2 page 10.9
  279. UnFluid UnFluid ______ __ ____ ___ ____ (UnFluid IDLIST:id-list): NIL expr
  280. ______ The variables in IDLIST which have been declared as FLUID
  281. variables are no longer considered as FLUID variables. Others
  282. are ignored. This affects only compiled functions, as free
  283. variables in interpreted functions are automatically considered
  284. FLUID (see [Griss 81]).
  285. 10.2.2. Binding Type Predicates 10.2.2. Binding Type Predicates 10.2.2. Binding Type Predicates
  286. FluidP FluidP _ ___ _______ ____ (FluidP U:any): boolean expr
  287. _ If U is FLUID (by declaration only), T is returned; otherwise,
  288. NIL is returned.
  289. GlobalP GlobalP _ ___ _______ ____ (GlobalP U:any): boolean expr
  290. _ If U has been declared GLOBAL or is the name of a defined
  291. function, T is returned; else NIL is returned.
  292. UnBoundP UnBoundP _ __ _______ ____ (UnBoundP U:id): boolean expr
  293. _ Tests whether U has no value.
  294. 10.3. User Binding Functions 10.3. User Binding Functions 10.3. User Binding Functions
  295. The following functions are available to build one's own interpreter
  296. functions that use the built-in FLUID binding mechanism, and interact well
  297. with the automatic unbinding that takes place during Throw and Error calls.
  298. [??? Are these correct when Environments are managed correctly ???] [??? Are these correct when Environments are managed correctly ???] [??? Are these correct when Environments are managed correctly ???]
  299. UnBindN UnBindN _ _______ _________ ____ (UnBindN N:integer): Undefined expr
  300. Prog Prog Used in user-defined interpreter functions (like Prog) to restore
  301. _ previous bindings to the last N values bound.
  302. LBind1 LBind1 ______ __ ___________ ___ _________ ____ (LBind1 IDNAME:id VALUETOBIND:any): Undefined expr
  303. ______ Support for LAMBDA-like binding. The current value of IDNAME is
  304. ___________ saved on the binding stack; the value of VALUETOBIND is then
  305. ______ bound to IDNAME. Function Definition 7 February 1983 PSL Manual
  306. page 10.10 section 10.3
  307. PBind1 PBind1 ______ __ _________ ____ (PBind1 IDNAME:id): Undefined expr
  308. Prog Prog ______ Support for Prog. Binds NIL to IDNAME after saving value on the
  309. LBind1 LBind1 ______ binding stack. Essentially LBind1(IDNAME, NIL)
  310. 10.3.1. Funargs, Closures and Environments 10.3.1. Funargs, Closures and Environments 10.3.1. Funargs, Closures and Environments
  311. [??? Not yet connected to V3 ???] [??? Not yet connected to V3 ???] [??? Not yet connected to V3 ???]
  312. We have an experimental implementation of Baker's re-rooting funarg
  313. scheme [Baker 78], in which we always re-root upon binding; this permits
  314. efficient use of a GLOBAL value cell in the compiler. We are also
  315. considering implementing a restricted FUNARG or CLOSURE mechanism. The
  316. implementation we have does not work with the current version of PSL.
  317. This currently uses a module (ALTBIND) to redefine the fluid binding
  318. _ ____ mechanism of PSL to be functionally equivalent to an a-list binding scheme.
  319. However, it retains the principal advantage of the usual shallow binding
  320. scheme: variable lookup is extremely cheap -- just look in a value cell.
  321. Typical LISP programs currently run about 8% slower if using ALTBIND than
  322. with the initial shallow binding mechanism. It is expected that this 8%
  323. difference will go away presently. This mechanism will also probably
  324. become a standard part of PSL, rather than an add on module.
  325. To use ALTBIND simply do "load altbind;" ["(load altbind)" in LISP].
  326. Existing code, both interpreted and compiled, should then commence using
  327. the new binding mechanism.
  328. The following functions are of most interest to the user:
  329. Closure Closure _ ____ ____ _____ (Closure U:form): form macro
  330. Function Function This is similar to Function, but returns a function closure
  331. Function Function including environment information, similar to Function in LISP
  332. Function* Eval Apply Function* Eval Apply 1.5 and Function* in LISP 1.6 and MACLISP. Eval and Apply are
  333. redefined to handle closures correctly. Currently only closures
  334. ____ ____ ____ expr expr of exprs are supported.
  335. EvalInEnvironment EvalInEnvironment _ ____ ___ ___ _______ ___ ____ (EvalInEnvironment F:form ENV:env-pointer): any expr
  336. ApplyInEnvironment ApplyInEnvironment __ ________ ____ ____ ____ ___ ___ _______ ___ ____ (ApplyInEnvironment FN:function ARGS:form-list ENV:env-pointer): any expr
  337. Eval Apply Eval Apply These are like Eval and Apply, but take an extra, last argument,
  338. and environment pointer. They perform their work in this
  339. environment instead of the current one.
  340. The following functions should be used with care: PSL Manual 7 February 1983 Function Definition
  341. section 10.3 page 10.11
  342. CaptureEnvironment CaptureEnvironment ___ _______ ____ (CaptureEnvironment ): env-pointer expr
  343. Save the current bindings to be restored at some later point.
  344. CaptureEnvironment CaptureEnvironment This is best used inside a closure. CaptureEnvironment returns
  345. ____ an environment pointer. This object is normally a circular list
  346. structure, and so should not be printed. The same warning
  347. applies to closures, which contain environment pointers. It is
  348. hoped that environment pointers will be made a new LISP data type
  349. soon, and will be made to print safely, relaxing this
  350. restriction.
  351. [??? add true envpointer ???] [??? add true envpointer ???] [??? add true envpointer ???]
  352. RestoreEnvironment RestoreEnvironment ___ ___ _______ _________ ____ (RestoreEnvironment PTR:env-pointer): Undefined expr
  353. Restore old bindings to what they were in the captured
  354. ___ environment, PTR.
  355. ClearBindings ClearBindings _________ ____ (ClearBindings ): Undefined expr
  356. Restore bindings to top level, i.e strip the entire stack.
  357. For a demonstration of closures, do (in RLISP)
  358. `in "PU:altbind-tests.red";'.
  359. [??? Give a practical example ???] [??? Give a practical example ???] [??? Give a practical example ???]