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