
Scheme Is Love - apotheon
http://msdn.microsoft.com/en-us/magazine/cc163729.aspx
======
dkarl
An utterly commonplace article in itself, but to see this written by Don Box
is surreal.

~~~
profquail
I'd never heard of him before, so I looked him up:

<http://en.wikipedia.org/wiki/Don_Box>

I did like the article though, even though there wasn't much to it. One of
these days when I have some time, I'm going to write a LISP/Scheme compiler
for .NET/CLR...my goal is to get Arc running on .NET, specifically for IIS7
since it has better support for MVC applications.

~~~
olavk
I don't think it is possible to implement continuations on top of the CLR.

~~~
profquail
Isn't this basically what the 'yield' keyword does in C# (for enumerating
values)? If not, can someone explain the difference?

~~~
mr_luc
... Heh, no, yield isn't the same as a continuation.

Yield, for iterators at least, is basically just calling a function that
you've passed in.

In Ruby (and now C#) and many other languages, there's what appears to be
syntactic sugar around this idiom, and especially in C# it's a bear to follow
what's happening because of the sea of syntax.

But all that's really happening is, you pass in an anonymous function, and
when the iterator calls yield(x), it calls that anonymous function with x.

In C#, you're saying

    
    
      okay, for this foreach doodle with a variable i, HereIsAnInterator(initialized) {
        
        but you can imagine this whole block as
        a function that gets called with i 
        every time yield() is called.
    
      }
    

Behind the scenes, the stuff between the braces gets turned into a function f,
and attached to HereIsAnIterator, accessible via (at least) yield().

Yield for iterators is just sugar around an anonymous function.

Continuations are a whole other bag o worms. (edit: originally invented as a
powerful memory-wasting device, some people now find them almost useful ;) ).

~~~
bmm6o
That may be one way to implement iterators, but it's nothing like the method
C# actually uses. See e.g. the series starting at
[http://blogs.msdn.com/ericlippert/archive/2009/07/09/iterato...](http://blogs.msdn.com/ericlippert/archive/2009/07/09/iterator-
blocks-part-one.aspx)

~~~
mr_luc
:P Look, I felt dirty enough just reading the C# code for an idiomatic usage
of an iterator ...

Obviously, in a compiled language that you control, you could take that block
and turn its contents into a method of a class for speed.

Conceptually, much easier to understand the base case: that you're passing in
an anonymous function.

In ruby, since they let you pass blocks around as objects, suddenly, poof, you
can understand _and_ implement ruby's iteration, just by learning about blocks
and seeing a snippet of code.

I like how, when they're talking about how to handle ITERATION, they say "we
thought about coroutines; we thought about continuations; we settled on what
we've got now" ... thinking about how I'd do it in CL (if I were writing a
library to make iterator-style programming more friendly, perhaps as a macro),
I have to say I wouldn't have immediately thought of using either of those. :P

Of course, I suppose for their target market, features that let you "roll your
own x", for almost any x, are far too dangerous to allow. Ugh.

C# code makes mr_luc sad.

