(Untitled)
I’m working on an expressive workflow language at work, and have hit a bit of a design standstill (in a couple of places, really). The place that I realized I hadn’t come to a conclusion was lexical vs. dynamic scoping. My language is pure (no destructive assignments are allowed, period) and I think that helps outline the problem more clearly.
In a lexically scoped language, an if block introduces a new level of scope (from which the old is also visible). For example –
if ( bampu ) { int pantsu = 1; } printf( "%d\n", pantsu );
Is a semantic error in C (because pantsu isn’t in scope outside the if block), but works fine in a dynamically scoped language (Ruby, Python, PHP…). The obvious way to “get it working” in C is to declare pantsu in a higher scope –
int pantsu; if ( bampu ) { pantsu = 1; } printf( "%d\n", pantsu );
And it works fine.
The problem here (and the reason why I’m banging my head on lexical scoping) is because this just introduced a destructive assignment (on the bolded line), something my language outlaws for performance reasons. With these constraints (both lexical scoping and no destructive assignments) the programs get a lot more functional in feel — rather than operating on stuff procedurally, you’d branch to a different function which took pantsu as an argument or something. This is a shit example for illustrating what I mean and I cbf’d to write out a better one.
Dynamic scoping isn’t the solution, either, I think. With dynamic scoping, static analysis of a program gets shot to hell.
Realistically though, I’m the only one who’s ever going to use this, so it doesn’t make much of a difference. I should just get the goddamn thing done and call it a week.
4 comments