News for hackers. Stuff that matters.
Re:Scheme Is Love by olavk on Thursday August 20, 2009 @05:33PM (#776347)
I don't think it is possible to implement continuations on top of the CLR.
Re:Scheme Is Love by DanielBMarkham on Thursday August 20, 2009 @05:35PM (#776358)
Sure it is. They're already using it with F#
Re:Scheme Is Love by olavk on Sunday August 23, 2009 @06:28AM (#780415)
What I meant was that the CLR does not support continuations of the type that makes call/cc possible, which is required to implement scheme.

It seems that IronScheme (Scheme on CLR) haven't found a solution for this issue: http://ironscheme.codeplex.com/WorkItem/View.aspx?WorkItemId...

I may be wrong since I dont know F#, but I suspect continuations on F# is more limited than call/cc.

Re:Scheme Is Love by wglb on Thursday August 20, 2009 @06:36PM (#776517)
Isn't there a DLR used by the likes of F#?
Re:Scheme Is Love by hvs on Thursday August 20, 2009 @07:47PM (#776661)
IronPython and IronRuby, yes. F# is statically typed.
Re:Scheme Is Love by profquail on Thursday August 20, 2009 @05:56PM (#776422)
Isn't this basically what the 'yield' keyword does in C# (for enumerating values)? If not, can someone explain the difference?
Re:Scheme Is Love by mr_luc on Thursday August 20, 2009 @06:05PM (#776444)
... 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 ;) ).

Re:Scheme Is Love by bmm6o on Thursday August 20, 2009 @07:23PM (#776624)
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...
Re:Scheme Is Love by mr_luc on Friday August 21, 2009 @07:27AM (#777330)
: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.

Re:Scheme Is Love by olavk on Friday August 21, 2009 @04:40AM (#777209)
yield could be implemented with continuations, but in C# it is implemented by turning the function into a class.