6 ms·
History of T (2001)
- teejmya 8y agoPoor title.
- deleted 8y ago[deleted]
- sctb 8y agoA couple of recent related discussions: https://news.ycombinator.com/item?id=17716056 https://news.ycombinator.com/item?id=17716056 https://news.ycombinator.com/item?id=15054404 https://news.ycombinator.com/item?id=15054404
- skrebbel 8y agoBeing an extremely young programmer (I'm 35), I had never quite understood what "dynamic scoping" is - the whole idea that scoping can somehow be done differently than "like in all the languages" was foreign to me until a few minutes ago. If you're an ignorant youth like me, here's some clarification. Wikipedia's description is horrid, but C2's[0] is a gem: "In dynamic scoping, by contrast, you search in the local function first, then you search in the function that called the local function, then you search in the function that called that function, and so on, up the call stack. "Dynamic" refers to change, in that the call stack can be different every time a given function is called, and so the function might hit different variables depending on where it is called from." Sounds totally insane to me and I wonder how people made working software at all in the '80s. That said, I get happy when I remember that people often complain about how horrible it is that $OBSCURE_AWESOME_TECHNOLOGY never made it and how $TRENDY_FAD solves the same problem so much less elegantly. I mean, apparently an $AWESOME_TECHONOLOGY sometimes does win, against all odds - in this case lexical scoping. Yay Guy Steele! http://wiki.c2.com/?DynamicScoping http://wiki.c2.com/?DynamicScoping EDIT: I just realized that shells copying all environment variables into child processes is basically a present-day example of dynamic scoping (although, fortunately, without mutation - we'd have entire data centers on fire if you could mutate parent process envs). It gives me a slightly better idea how this stuff could be used to make working software.
- nickelcitymario 8y agoI'm comforted to know I'm still "extremely young" :-)
- gjulianm 8y agoI think Bash is the only common-use language that uses dynamic scoping. Whenever you get into more than two functions everything can quickly become unmanageable if you don't prefix all your declarations with 'local'. Forget one of those, and the moment you reuse a variable name you'll find yourself with some annoying weird bugs.
- slobotron 8y agoYou can get dynamic scoping in perl by prefixing things with `local`. $ENV{BLAH} = 'hi'; $Some::Package::Var = 'there'; { local $ENV{BLAH} = 'hello'; local $Some::Package::Var = 'world'; # this call will see 'hello' and 'world' some_method() } # this call will see 'hi' and 'there' some_method() All the caveats with playing with globals above notwithstanding, it's more useful in practice as a way to get a 'slightly different copy of an object': my $a = { hello => 'world', other => 'stuff'}; { delete local $a->{other}; print "$a->{hello} $a->{other}\n"; } print "$a->{hello} $a->{other}\n"; this gives world world stuff Great way for setting up log contexts etc that automatically get removed after the scope exits...
- deleted 8y ago[deleted]
- Verdex_3 8y agoWith respect to the call stack, a dynamically scoped variable is like the dual of an exception. That is to say, an exception is a way for a method to communicate with methods that are above it in the call stack. And a dynamically scoped variable is a way for a method to communicate with methods below it in the call stack. Of the two the dynamically scoped variable is more powerful than the exception because an exception can only propagate upwards. A dynamically scoped variable can propagate downward, upward, or sideways (ie sibling methods in the call graph can access the values that you placed into the dynamically scoped variable). In terms of how much trouble you can get into by misusing it, the dynamically scoped variable is more problematic than the exception (all things being equal). A dynamically scoped variable is basically just a global variable that isn't quite 100% global. So you can get into all the same problems that a global can get you into with the added benefit (or sometimes problem) that any two instances of a dynamically scoped variable might actually be different because they are coming from a different caller. Finally, there are some really good usages of a dynamically scoped variable. Consider reference counting. If you're doing reference counting every time you increase/decrease your reference count, you are going to need to modify a counter. This is fine if you only have one thread, but with multiple threads it means that every time you modifying the counter you'll need to lock. Not something you want to do if you're worried about speed. However, if you stuck your reference counting framework into dynamic variables that get populated in the thread spin up method, then you could guarantee that each reference counting instance is inside of it's own thread. Now you don't have to lock anymore when you modify the ref count (as long as you don't otherwise cross the thread barrier). All in all, I suspect that it's better that we have lexical scoping as a standard. Most of the things that I want to do with dynamic scoping, I feel like should live in a language feature or library. Additionally, dynamic scoping is more likely to break other abstractions like object oriented programming (ie we can't think of the object as an encapsulated unit if the way that it functions is determined by the methods above it in the call stack).
- lisper 8y ago> Another implementation feat of T's was that it allowed interrupts between any two instructions of user code. That was the goal, but the T3 compiler actually turned out to have a very subtle bug that manifested itself as the single hardest bug I have ever dealt with in my career. We used T to write research code for rovers and robotic arms at JPL. This code ran on two different machines: Sun3's running Solaris, and brandless embedded systems running vxWorks, but both running the same T compiler targeting the 68020 processor. On the embedded systems we would get random crashes, but the same code running on Solaris ran flawlessly. Post-mortems revealed massive and random heap corruption, so the crash was manifesting itself long after the root cause. Because the problem was random an could not be reliably reproduced, it was impossible to find the root cause. And that is how matters stood for nearly a year until someone (I don't remember who, but it wasn't me) finally figured out how to reproduce the problem reliably. Then I spent a couple of days single-stepping through machine code until I finally found the problem: the stack pointer was being decremented while a live value was still on the stack. That value was accessed by the very next instruction. Those two instructions were simply out of order. On Solaris this didn't matter because all the code ran in user space and was single-threaded. But vxWorks does not have a protected kernel address space. When an interrupt happens, that interrupt is processed on whatever process stack is currently active. So if you got an interrupt exactly between the stack pointer decrement and the subsequence load, the value was corrupted, and a few thousand instructions later everything would go kablooey.
- modells 8y agoStanford has/had a strong AI group, SAIL, that got passed around and now resides affiliated with GSB. When I was at SMI/BMIR, they had an old SAIL sign over in MSOB.
- FullyFunctional 8y agoAnyone have more detail on Douglas W. Clark's GC? Ideally the cited article or a description of the algorithm.