To some extent any inversion of control style framework works like this. It can be more or less befuddling depending on the straightforwardness of the framework. Declarative style programming such as sql, xslt, or msbuild also tend to work this way, which can be maddening to debug.
What are some more obscure control flow structures? It's easy to think that eg conditionals, loops, goto, function calls are the only ones that exist. But there is also stuff like jump tables and co-routines for instance.
I don't know if it gets any more obscure than Scheme's call/cc, which is a building block for other control flow structures. You can use it for cool things like the Racket web server, where event-driven programming can be made to feel like sequential, procedural-style programming. You can also use it for sick mind twisters like ((call/cc call/cc) (call/cc call/cc))
I remember being shown call/cc briefly in CS 61A at Berkeley and then forgetting about it until recently when I saw an article on it while I was in the middle of writing an event-driven web application using Perl and Plack. I immediately saw how useful it would be and wished I had it available to use there.
I don't think I ever really understood call/cc until I read Lisp in Small Pieces. The author makes a great effort to implement call/cc in each of the interpreters and compilers he presents, and examines the hairy issues that come up when you decide to support first-class continuations.
They're what lies beyond exceptions: exceptions will unwind the stack looking for a handler (`catch` or the likes), and when found will execute that handler in its (the handler's) context (scope).
Conditions walk the stack instead of unwinding it, and execute the handler in their own context. This gives the handler the possibility of logging an error and bailing out, of course, but also of fixing the local data and resuming running the code[0], as if nothing had happened. A condition system essentially allows callees to reach into callers and ask them what to do, without having to lose any state or data.
This also gives more power to tools: without any specific instrumentation, a Smalltalk environment or a Common Lisp IDE can drop you at the error site (where the condition was signaled) without needing more than registering a condition handler when starting your code (if conditions are already handled by a condition handler in your stack, this default behavior won't happen until your handlers let the condition propagate further).
[0] Actual flexibility depends on the runtime, I'm not completely up to snuff with everything, I know in Common Lisp there's a concept of "restart": the one who signaled the condition or any of its callers can provide "restarts", which are essentially possible choices for resuming work. A log-parsing API could provide restarts to skip a corrupted or unreadable entry, to display a user prompt to ask him to "manually" parse the value or to provide the API with a value to use instead (could be a default, a placeholder, or a value obtained by calling the older log-parser you're trying to replace) (note: it's an inclusive or, the API provides all three and the developer using the API picks the one he wants depending on the situation). Or a dict's `get` method could signal on an invalid key and provide a restart making it return a default value of some sort.
COME FROM is the reason INTERCAL is among my favorite esoteric programming languages. That and the fact that its name is for "Compiler Language With No Pronounceable Acronym".
From Wikipedia: An actual example in INTERCAL would be too difficult to read
You want to make $85 hourly and $7000 per month like me just working on laptop for few hours! Would you like to be your own boss!Opportunities like this don't come by often. Don't let this one pass you by! CashHuge. com
21 comments
[ 2765 ms ] story [ 214 ms ] threadhttp://en.wikipedia.org/wiki/Aspect-oriented_programming#See...
http://search.cpan.org/dist/Acme-ComeFrom/lib/Acme/ComeFrom....
But you have to read it slowly.
Now, off to study!
Thanks, btw.
Highly recommended.
http://rubydoc.info/stdlib/core/1.9.3/Kernel:callcc
Thus you can implement pretty much anything you want in ruby, including COME FROM.
They're what lies beyond exceptions: exceptions will unwind the stack looking for a handler (`catch` or the likes), and when found will execute that handler in its (the handler's) context (scope).
Conditions walk the stack instead of unwinding it, and execute the handler in their own context. This gives the handler the possibility of logging an error and bailing out, of course, but also of fixing the local data and resuming running the code[0], as if nothing had happened. A condition system essentially allows callees to reach into callers and ask them what to do, without having to lose any state or data.
This also gives more power to tools: without any specific instrumentation, a Smalltalk environment or a Common Lisp IDE can drop you at the error site (where the condition was signaled) without needing more than registering a condition handler when starting your code (if conditions are already handled by a condition handler in your stack, this default behavior won't happen until your handlers let the condition propagate further).
[0] Actual flexibility depends on the runtime, I'm not completely up to snuff with everything, I know in Common Lisp there's a concept of "restart": the one who signaled the condition or any of its callers can provide "restarts", which are essentially possible choices for resuming work. A log-parsing API could provide restarts to skip a corrupted or unreadable entry, to display a user prompt to ask him to "manually" parse the value or to provide the API with a value to use instead (could be a default, a placeholder, or a value obtained by calling the older log-parser you're trying to replace) (note: it's an inclusive or, the API provides all three and the developer using the API picks the one he wants depending on the situation). Or a dict's `get` method could signal on an invalid key and provide a restart making it return a default value of some sort.
From Wikipedia: An actual example in INTERCAL would be too difficult to read
Gotta love it.
Some people have a wicked sense of humour
Toolkit Without An Interesting Name