4 ms·
No. When I set the value of a symbol in a dynamically scoped by default language, it only affects the closest binding for that symbol. When I assign in bash wi
by catern 7y ago
No. When I set the value of a symbol in a dynamically scoped by default language, it only affects the closest binding for that symbol.
When I assign in bash without "local", it affects global scope. There is no way to do the corresponding behavior of "setq" in bash.
- kazinator 7y agoIt 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.