3 ms·
It so happens that I actually know what I'm talking about in this area, with regard to both languages/families: #!/bin/bash v=xyz f1() { printf
by kazinator 7y ago
It so happens that I actually know what I'm talking about in this area, with regard to both languages/families:
#!/bin/bash
v=xyz
f1()
{
printf "v = %s\n" $v
v=clobber
}
f2()
{
local v="abc"
f1
f1
}
f2
f1
f1
Output:
v = abc
v = clobber
v = xyz
v = clobber
Almost line-for-line analogous Common Lisp program. Defining the variable is mapped to defparameter, local mapped to let and setq to assignment:
(defparameter v 'xyz)
(defun f1 ()
(format t "v = ~a~%" v)
(setq v 'clobber))
(defun f2 ()
(let ((v 'abc))
(f1)
(f1)))
(f2)
(f1)
(f1)
Output (from clisp):
v = ABC
v = CLOBBER
v = XYZ
v = CLOBBER
- catern 7y agoThat seems to be the case. My original statement was wrong then. My mistake - for some reason I thought the bash behavior was different.