From: Tomasz Wegrzanowski Date: 2006-07-27T21:36:28+09:00 Subject: Re: RLisp - Lisp naturally embedded in Ruby On 7/27/06, Christian Neukirchen wrote: > > Yeah, but setf changes variables in outside scope. > > (setf a 2) > > (defun foo () > > (setf a 3) > > a > > ) > > (foo) ; -> 3 > > a ; -> 3 > > No, that's just because a is global here. Shadow it by a local variable: > > (defun foo () > (let (a) > (setf a 3) > a)) > > a ; => 2 > (foo) ; => 3 > a ; => 2 > > > I think it would be a huge win if variables were local to > > the nearest lambda (or equivalent) by default, just like in Ruby. > > That's why one uses LET for local variables. ;-) Can we macro around it or something, so that (set-local-variable variable value) introduces a function-local variable without increasing indentation level each time it's being done? I think it's reasonable to write something like that (whatever the names of set-local-variable operator is): (defun veclen (x y) (set-local-variable x2 (* x x)) (set-local-variable y2 (* y y)) (set-local-variable z2 (+ x2 y2)) (sqrt z2) )