call-with-current-continuation
No CommentsClosures get a lot of the press; so here’s something that many everyday programmers don’t know about.
First off, definitions:
- A Continuation is the computational state of a program (i.e. - function stack, not heap) saved into a data structure for later user.
- A higher order function is a function that takes another function as a parameter; or it is a function that returns a function as its output; or it is both.
- A non-local return is a way to immediately exit a function and transfer control to some point in function stack; similar to goto, but not quite.
call-with-current-continuation is a Scheme higher order function that saves the current computational state, and then executes an abortable procedure (a higher order function passed in as the call-with-current-continuation’s sole parameter); the called abortable procedure, which has only one parameter, is given an escape procedure; calling the escape procedure from within the abortable procedure will execute a non-local return back to its respective call-with-current-continuation; the return value of the call-with-current-continuation is either the natural return value of the abortable procedure or a single value passed to the escape procedure; and call-with-current-continuation is also known by its shorter alias: call/cc.
Example:
; Define some procedure I want to escape from.
(define my_abortable_procedure
(lambda (escape_procedure)
; Do stuff
(+ 1 1)
;nonlocal return
(escape_procedure ‘SOMEVALUE)
(display ‘NEVERREACHED_WHEN_ESCAPE_IS_CALLED)))(display (call/cc my_abortable_procedure))
; displays: SOMEVALUE
; The return value of call/cc is the value either returned by my_abortable_procedure or
; the value passed to escape_procedure
Here’s an example I found showing how one can jump back into a function call instead of escaping it.
(define return #f)
(+ 1 (call/cc
(lambda (cont)
(set! return cont)
1)))
; The above returns 2(return 22)
; The above returns 23
So what’s it all good for? Well, examples of use include Exceptions (e.g. - catch, throw, raise, and rescue), Co-routines, Backtracking, and Cooperative Multitasking.
“But I don’t use Scheme (or Lisp).”
[UPDATE:12JUNE2007] - I just watched the The 90 Minute Scheme to C compiler talk given by Marc Feeley in 2004; part one takes an incredible 10 minute tangent into talking about call/cc (while talking about continuations in general). Definitely watch it for a great explanation.
Posted in Computer Science
No Comments
Error while trying to run project: unable to start debugging on the web server
No CommentsSo im at work, you know working. I checkout a project I need to fix a bug in and make it the default web site in IIS. I set a breakpoint and try to run the debugger.
Error while trying to run project: unable to start debugging on the web server
The fix wasn’t too hard but it was kind of annoying. I have two versions of .Net installed on my work computer; 2.0 and 1.1.4blah. The default website was set as 2.0 when the project is actually 1.1.4 project.
What to do?
- Open up ISS and and right click on the website folder that host your site, in my case it was “deafult website”.
- Choose the ASP.Net tab.
- One of the options is ASP.NET version. Change it to the correct version.
- Hit OK
- It should work now.
Posted in Technology
No Comments
This not That
2 CommentsReflection is a task best practiced delicately. The bubble gum and duck tape that holds our lives together can be torn apart over a simple deliberation between dreams and reality. Thus, I took great precaution before sitting down and writing this, whatever “this” is. I didn’t want this to turn into that. Or become one of those that are usually written by them. How I hate them and their ways. I wanted this to be one of these that are written by those who don’t get along with them. How I hate them and their ways. So anyway, I enjoy reading quotes. With good timing and proper regurgitation I can appear intelligent through the expressions of those much smarter and original then I am.
“The only true wisdom is in knowing you know nothing.”
-Socrates
My life isn’t a book but I wish it were. I wish I could put it down when it got boring or took a plot twist I didn’t agree with. I want my dad to write his memoirs but he keeps shooting the idea down. He feels it is a waste of time. “I already know what happened, why waste the time I got left proving it to you.” Although I don’t agree with his logic I can’t knock his style. It would be hilarious if a fifteen year old guy wrote an autobiography. It would be a 500 page book split into 20 chapters. The first two chapters would cover toys, video games and ice cream. The next eighteen would give detailed accounts of how to masturbate. Honestly, the youth these days are spoiled with streaming video. I remember when an obvious faked picture of Kelly Kapowski, loading a little over a minute, would do the trick. Usually a guy could unload before the picture finished loading. Honestly, I can’t remember if Kelly Kapowski had knees. But I can tell you that she is not a natural…
I’m sure you would find it pleasing if I stopped discussing masturbation. So, to please you and not me I will move on to another topic. This is random just as life is. More importantly, this is not that and was certainly not written by them. Don’t waste your time thinking about what you haven’t done or telling stories of things you did a long time ago. Don’t imitate. Don’t let your life be a quote out of the social norm. Say something, break rules and piss someone off.
Or continue to play with yourself from nine to five so you can fall asleep and wake up tired.
Posted in Life Stuff
2 Comments
Burning Crusade Mocks Me
1 CommentThe box has been sitting on my desk for a few days. I want to play this game, and I want to run far far away.
Posted in Video Games
1 Comment
A Fabulous Dip
2 Comments[A filler post because I have been neglecting this blog during the holidays. More posts to come.]
Here’s a recipe I learned from a CouchSurfer while I was in Austria:
- 500 grams of Cream Cheese
- 3 Tablespoons of Sour Cream
- 200 grams of finely chopped ham. Or replace with finely chopped red or white onion.
- Salt
- 50 to 100 grams of finely chopped green onions
- A few dill pickles
Instructions:
- Finely chop the dill pickles.
- Finely chop the ham.
- Finely chop the green onions.
- Mix all the ingredients together until the dip is fine and smooth.
- While mixing, add salt as you need. Stop, taste, add, repeat until desired flavor.
It’s super easy to make, and I love how it spreads over breads. It just took me two attempts to get the taste to my liking.
Posted in Food
2 Comments