Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I started programming with Python. When using python, concepts like coroutine, closure made me really confusing.

Now I think I know them some superficial level, but I want to get the "enlightement" so, I choose to learn Clojure, the dialect of Lisp. I bought the book of Stuart Halloway and it's good. But when I looked the index of that book, there's no words like coroutine, continuation. I googled it, but there's anything, too.

So, my question is,

Does Clojure have continuation or coroutine (which greenlet or stackless serve) to do the jobs like the Ping-pongs without stack overflow?

Python style (though Python standard does not serve full-feature of this symmetric coroutine):

def ping():
  while 1:
   print "ping"
   function to switching to pong

def pong():
  while 1:
   function to switching to ping
   print "pong"

If not, as for learning the functional concepts, is it better to learn Scheme instead?

share|improve this question
add comment

1 Answer

Clojure doesn't have call/cc, but you don't want undelimited continuations anyway.

We argue against call/cc as a core language feature, as the distinguished control operation to implement natively relegating all others to libraries. The primitive call/cc is a bad abstraction -- in various meanings of 'bad' shown below, -- and its capture of the continuation of the whole program is not practically useful. The only reward for the hard work to capture the whole continuation efficiently is more hard work to get around the capture of the whole continuation. Both the users and the implementors are better served with a set of well-chosen control primitives of various degrees of generality with well thought-out interactions...
...Offering call/cc as a core control feature in terms of which all other control facilities should be implemented turns out a bad idea. Performance, memory and resource leaks, ease of implementation, ease of use, ease of reasoning all argue against call/cc. If there is really one distinguished control feature to implement as a primitive, with others relegated into libraries, it is not call/cc.

David Nolen wrote a delimited continuations library for Clojure. Try it out!

delimc

A delimited continuations library for Clojure 1.4.0 (and 1.3.0). Portions based on cl-cont by Slava Akhmechet (http://defmacro.org)...

share|improve this answer
    
@gnat: Nice edits; thanks! –  Frank Shearar Aug 18 '12 at 9:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.