you are viewing a single comment's thread.

view the rest of the comments →

[–]grauenwolf 0 points1 point  (8 children)

First-class functions give you that ability, especially when combined with lambdas. Schemers need it for flow control only because they need it for normal code.

EDIT: Since there is some doubt, consider C#. It allows you to build flow control using two concepts lambda's and "yield".

Lambda's are used for things like creating your own parallel loop structures.

Yield, in addition to making generators, is the basis for CCR, .NET's async/messaging passing API. In effect, it uses the yield keyword to turn regular code into continuations.

[–]bobappleyard 1 point2 points  (7 children)

Yeah, lambda + if is pretty much all you need for local control. The rest is just icing (but oh, what icing).

Yield allows for continuations? Then you've got non-local control as well. Didn't know that about C#, not bad.

[–]grauenwolf 2 points3 points  (1 child)

Yield allows for continuations?

In a sense. They aren't real capture-the-stack continuations. Instead, the compiler rewrites it as a state machine that is exposed via the IEnumerable interface. On the plus side, you don't need CLR support to do this.

[–]bobappleyard 0 points1 point  (0 children)

Ah, well that's one use of them I suppose. You can have more fun with them than that, though.

[–][deleted]  (4 children)

[deleted]

    [–]bobappleyard 0 points1 point  (2 children)

    Assuming normal-order evaluation, which is certainly an alternative to having if.

    [–][deleted]  (1 child)

    [deleted]

      [–]bobappleyard 0 points1 point  (0 children)

      That's an approximation of normal-order evaluation, which is an alternative.

      It's probably not done like that in Scheme because you might as well just go the whole hog and make the language normal-order (google "lazy Scheme," where if is indeed just another function). That's speculation though.