dynamic-scope

How to create dynamical scoped variables in Python?

Hello, I am translating some code from lisp to Python. In lisp, you can have a let construct with the variables introduced declared as special and thus having dynamic scope. (See http://en.wikipedia.org/wiki/Dynamic_scope#Dynamic_scoping) How can I do likewise in Python? It seems the language does not support this directly, if true,...

Implementing dynamic scope when using CPS as intermediate language

I am currently studying the implementation of programming languages and became interested in using Continuation-Passing Style as the intermediate language of the compiler. I also want to implement limited dynamic scope (for exception-handling or Scheme parameter objects) but I cannot find the relevant literature. I think it can be done w...

Emulating lisp cons cells in Tcl

A list in lisp is a series of cons cells, but in Tcl, a list is a string with whitespace separating the elements. For translating code from lisp to tcl, one might simply take lisp lists and translate them to Tcl lists. However, this runs into trouble with side effecting cons cells not coming across to the Tcl code. For example, consid...

Closures and dynamic scope?

I think I understand why there is a danger in allowing closures in a language using dynamic scope. That is, it seems you will be able to close the variable OK, but when trying to read it you will only get the value at the top of global stack. This might be dangerous if other functions use same name in the interim. Have I missed some o...

Emulating lisp cons cells in Python

A list in lisp is a series of cons cells, but in Python, a native list is a different kind of object. For translating code from lisp to Python, one might simply take lisp lists and translate them to Python native lists. However, this runs into trouble with side effecting cons cells not coming across to the Python code. For example, co...

Adopting dynamic scoping of variables

Imagine you are designing your own programming language. Very simple language for quite specific purpose. It has functions, loops and variables. And you want to make use of dynamic scoping for variables. Consider the imaginary example: var x = "foo" var count = 0 loop (/* condition */) { var x = "bar" // A new stack frame is ...