'Use-Once' Variables and Linear Objects

John Nagle nagle at animats.com
Sat Aug 13 00:30:28 EDT 2011

On 8/2/2011 7:19 AM, Neal Becker wrote:
> I thought this was an interesting article
> http://www.pipeline.com/~hbaker1/Use1Var.html

    Single-use was something of a dead end in programming.

    Single assignment, where you can only set a variable when you create
it, is more useful.  Single assignment is comparable to functional
programming, but without the deeply nested syntax.

    Functional programs are trees, while single-assignment programs are
directed acyclic graphs.  The difference is that you can fan-out
results, while in a a functional language, you can only fan in.
This fits well with Python, where you can write things like

    def fn(x) :
         (a, b, c) = fn1()
         return(fn2(a) + fn3(b)*c)

"const" is often used in C and C++ to indicate single-assignment usage.
But C/C++ doesn't have multiple return values, so the concept isn't as
useful as it is in Python.

Optimizing compilers usually recognize variable lifetimes, and so they
create single-assignment variables internally when possible.  This
is a win for register and stack allocation, and for fine-grain
parallelism on machines which support it.

Since Python isn't very optimizable, this is mostly a curiosity.

					John Nagle

More information about the Python-list mailing list