Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


Sure it is. They're already using it with F#


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.


Isn't there a DLR used by the likes of F#?


IronPython and IronRuby, yes. F# is statically typed.


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


... 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 ;) ).


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...


: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.


yield could be implemented with continuations, but in C# it is implemented by turning the function into a class.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: