Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!think!caip!unirot!mg From: mg@unirot.UUCP (Mike Gallaher) Newsgroups: net.emacs Subject: Re: MLisp local variables in UniPress (Gosling) Message-ID: <916@unirot.UUCP> Date: Tue, 29-Jul-86 06:58:53 EDT Article-I.D.: unirot.916 Posted: Tue Jul 29 06:58:53 1986 Date-Received: Tue, 29-Jul-86 21:36:13 EDT References: <1514@vax135.UUCP> Organization: The Soup Kitchen Lines: 46 Summary: avoiding name conflicts > 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. This is indeed one of the most confusing subtleties of MLisp. (It wasn't even documented anywhere before V2.10!) Once you understand what is going on, it is not hard to avoid problems. The MLisp coding guidelines (doc/mlisp-std) recommend that local variable names be prefixed by some string unique to the function it is defined in. For instance, a function called describe-moused-word might have a variable $dmw-count. (The '$' is a naming convention indicating that it is a local variable.) Also, be careful about evaluating args that may depend on which buffer is current, or where the region is, etc. For instance, suppose you have (defun (foo (temp-use-buffer "*scratch*" (setq @foo (arg 1)) ) )) (mark-whole-buffer) (foo (region-to-string)) foo will evaluate the argument, (region-to-string), within the buffer *scratch*, not in the buffer from which foo was called. Though you can usually write the code so as not to depend on such things, the most general way around this problem is to have functions evaluate their arguments and store the results in local variables before doing anything else: (defun (foo $s (setq $s (arg 1)) (temp-use-buffer "*scratch*" (setq @foo $s) ) )) Once you come to properly love MLisp, you will realize that you wouldn't want it to be any other way. :-) Mike Gallaher Unipress Software