Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbatt!cbosgd!ihnp4!vax135!ksr From: ksr@vax135.UUCP (Ken Roberts) Newsgroups: net.emacs Subject: MLisp local variables in UniPress (Gosling) Message-ID: <1514@vax135.UUCP> Date: Tue, 22-Jul-86 12:06:59 EDT Article-I.D.: vax135.1514 Posted: Tue Jul 22 12:06:59 1986 Date-Received: Wed, 23-Jul-86 07:44:46 EDT Organization: AT&T Bell Labs, Holmdel, NJ Lines: 44 There is an interesting subtlety about local variables and parameter passing in the MLisp of Unipress (Gosling) Emacs. Suppose I define the functions 'insert-times' and 'my-test': (defun (insert-times this-string n ; Inserts 'n' (argument 2) copies ; of the string given by 'this-string' (argument 1). (setq this-string (arg 1)) (setq n (arg 2)) (while (> n 0) (setq n (- n 1)) (insert-string this-string) ) ) ) (defun (my-test this-string (insert-times "Hello--" 2) (setq this-string "Hello--") (insert-times this-string 2) ) ) If I now invoke the function 'my-test', what will be inserted is not "Hello--Hello--Hello--Hello--", but rather "Hello--Hello00". This is because the expression for argument 1 is not evaluated at the time of the invocation of 'insert-times'; but rather when (arg 1) is reached. By that time, the name 'this-string' has been rebound, and initialized to 0 (by the new local declaration in the function 'insert-times'). Conclusion: Due to the way the 'arg' function is defined, local variables are not entirely insulated from other variables (local or global) that have the same name. This is a problem, since the major selling point of local variables is supposed to be that you are free to choose names for them without bothering to check if those names are already being used somewhere else. Ken Roberts