4 ms·
I want a programming language that takes dynamic scope seriously. Not because I think it would be good, but I think it would be interesting.
by __alexs 4y ago
I want a programming language that takes dynamic scope seriously. Not because I think it would be good, but I think it would be interesting.
- Jtsummers 4y agoLike Common Lisp? You get dynamic scope through what it terms "special variables". They work as expected, and can be handy.
- convolvatron 4y agoif I understand what you mean, elisp has dynamic scope. that's turned out to be useful to me a couple times...balanced against the hundreds of times that it did something I didn't want.
- yakubin 4y agoYou can opt into lexical scope for a script by starting it with: ;; -*- mode: Emacs-Lisp; lexical-binding: t; -*- You can then opt into dynamic scope for single variables, when it makes sense: (defvar variable)
- masklinn 4y agoLisps often have dynamic scoping. elisp used to only have dynamic scoping.
- sparkie 4y agoKernel is very interesting. It has fexpr-like combiners (operatives) which implicitly receive a reference to the dynamic environment of their caller. The environments are first-class and modelled as a DAG, with the local bindings in the root node with a list of other parent environments. The list of parents, and any bindings in the parent environments cannot be modified, but only the local bindings can. This puts constrains the operatives a bit - they can't just mutate anything in the dynamic environment, but only the local bindings of an environment for which they have a direct reference. Additionally, Kernel has dynamic binding built-in, and done in a nice way. You never explicitly access a dynamic variable but you only have an accessor function to it. A new scope is created when binding a dynamic variable, and the accessor will return whatever was bound anywhere in the dynamic extent of this scope. ($define! (with-str get-str) (make-keyed-dynamic-variable)) ($define! f ($lambda () (print (get-str)))) (with-str "Hello, world!" ($lambda () (f) (with-str "Goodbye, world!" f) (f))) Prints "Hello, world!" "Goodbye, world!" "Hello, world!" Perhaps the only downside to this is that a runtime error will be raised if `get-str` is called before a value is bound. I think it would be a bit nicer to include a default binding as an argument to the call of `make-keyed-dynamic-variable`. http://web.cs.wpi.edu/%7Ejshutt/kernel.html http://web.cs.wpi.edu/%7Ejshutt/kernel.html
- draegtun 4y agoPerl has dynamic scoping (along with lexical scoping).