From: Rock
Subject: Generators and coroutines
Date: 
Message-ID: <e6b3ad51-ce13-461f-a5d0-3dd11b1f9933@f13g2000yqj.googlegroups.com>
CL hasn't got call/cc but Graham shows in On Lisp that it is possible,
to a certain extent, to implement CPS with macros. I was wondering if
it's conceivable to go from there and implement full-blown generators
and, especially coroutines, a la Python or Ruby for instance. Not half-
baked solutions though, but real, possibly simple-to-use,
implementations, that, by the way, I think ought to work with methods
too, and not just ordinary functions.

From: Matteo Pradella
Subject: Re: Generators and coroutines
Date: 
Message-ID: <fdf2cbe6-aed0-4593-be38-6800d44f7386@w35g2000yqm.googlegroups.com>
On Dec 3, 11:53 am, Rock <···········@gmail.com> wrote:
> CL hasn't got call/cc but Graham shows in On Lisp that it is possible,
> to a certain extent, to implement CPS with macros. I was wondering if
> it's conceivable to go from there and implement full-blown generators
> and, especially coroutines, a la Python or Ruby for instance. Not half-
> baked solutions though, but real, possibly simple-to-use,
> implementations, that, by the way, I think ought to work with methods
> too, and not just ordinary functions.

you could start here:
http://common-lisp.net/project/cl-cont/
From: AngelP
Subject: Re: Generators and coroutines
Date: 
Message-ID: <2cb8bd0f-d2df-4d95-a103-430b6ec463c3@41g2000yqf.googlegroups.com>
On Dec 3, 12:53 pm, Rock <···········@gmail.com> wrote:
> CL hasn't got call/cc but Graham shows in On Lisp that it is possible,
> to a certain extent, to implement CPS with macros. I was wondering if
> it's conceivable to go from there and implement full-blown generators
> and, especially coroutines, a la Python or Ruby for instance. Not half-
> baked solutions though, but real, possibly simple-to-use,
> implementations, that, by the way, I think ought to work with methods
> too, and not just ordinary functions.

I feel there should be a solution using conditions but I have stuck.
For example:

(define-condition error-wait-for (error)
  ((text  :initarg :text :reader text)))

(defstruct task fn status result name)

(defun test()
  (format t "test~%")
  (format t "Result ~A~%"
          (restart-case ; here is a "call/cc" place
           (format t "Result ~A~%" (error 'error-wait-for :text
"wait"))
           (return1 () 1)))
  (format t "rest~%")))

(defun check-end (task)
  (format t "End of ~A?(Y/N)" (task-name task))
  (equal (read-line) "Y"))

(defun do-proc(tasks)
  (loop for x in tasks do
        (when (null (task-status x))
          (handler-bind ((error-wait-for #'(lambda (c)
                                             (setf (task-status x)
'waiting)
                                             ;does not work when there
are more than one pending tasks
                                             (loop :until (check-end
x) do
                                                   (do-proc tasks))
                                             (invoke-restart
'return1))))
                        (setf (task-result x) (funcall (task-fn x)))
                        (setf (task-status x) 'ready))))
  tasks)

(do-proc (list (make-task :fn #'test :name "t1") (make-task :fn
#'test :name "t2")))


I hope some smarter could help
Regards, Angel
From: Pascal Costanza
Subject: Re: Generators and coroutines
Date: 
Message-ID: <6pnfebF8p77aU2@mid.individual.net>
Rock wrote:
> CL hasn't got call/cc but Graham shows in On Lisp that it is possible,
> to a certain extent, to implement CPS with macros. I was wondering if
> it's conceivable to go from there and implement full-blown generators
> and, especially coroutines, a la Python or Ruby for instance. Not half-
> baked solutions though, but real, possibly simple-to-use,
> implementations, that, by the way, I think ought to work with methods
> too, and not just ordinary functions.

There are generators in http://series.sourceforge.net/


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/