cl-cont .. heh ...<div><br></div><div>This is the call/cc that will/should be included in :interface/monad :</div><div><br></div><div><div>(define-interface <monad> (<type>) ()</div><div> (:singleton)</div><div>
(:generic result (<monad> value))</div><div> (:generic bind (<monad> monadic-value monadic-function)))</div><div><br></div><div>(defmacro mlet* (monad bindings &body body)</div><div> (destructuring-bind (monad &optional (functions-spec '<monad>)) </div>
<div> (or (when (listp monad) monad) (list monad))</div><div> `(macrolet ((%mlet* (((symbol monadic-value) &rest rest) &body body)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> `(bind ,monadic-value</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> (lambda (,symbol)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> ,@(when (string-equal (symbol-name symbol) "_")</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> `((declare (ignorable ,symbol))))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> ,@(if rest </div><div><span class="Apple-tab-span" style="white-space:pre"> </span> `((%mlet* ,rest</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> ,@body))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> body)))))</div><div> (interface:with-interface (,monad ,functions-spec)</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> ,@(if bindings </div><div><span class="Apple-tab-span" style="white-space:pre"> </span> `((%mlet* ,bindings ,@body))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> body)))))</div>
<div><br></div><div><div>(interface:define-interface <continuation> (<monad>)</div><div> ()</div><div> (:singleton)</div><div> (:generic call/cc (<continuation> function)))</div><div><br></div><div>(defmethod result ((m <continuation>) value)</div>
<div> (lambda (k) (funcall k value)))</div><div><br></div><div>;m >>= f = Cont (\k -> runCont m (\a -> runCont (f a) k))</div><div><br></div><div>(defmethod bind ((m <continuation>) mv mf)</div><div> (lambda (k)</div>
<div> (funcall mv</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> (lambda (a) </div><div><span class="Apple-tab-span" style="white-space:pre"> </span> (funcall (funcall mf a) </div><div>
<span class="Apple-tab-span" style="white-space:pre"> </span>k)))))</div><div><br></div><div>; callCC f = Cont $ \k -> runCont (f (\a -> Cont $ \_ -> k a)) k</div><div><br></div><div>(defmethod call/cc ((m <continuation>) fn)</div>
<div> (lambda (k) </div><div> (funcall (funcall fn (lambda (a) </div><div><span class="Apple-tab-span" style="white-space:pre"> </span> (lambda (_) </div><div><span class="Apple-tab-span" style="white-space:pre"> </span> (declare (ignore _)) </div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> (funcall k a)))) </div><div><span class="Apple-tab-span" style="white-space:pre"> </span> k)))</div></div><div><br></div><div><br></div><div>;;; Then: </div>
<div><br></div><div><div>ORG/IPS/MONAD/CONTINUATION> (let (cc)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> (mlet* (<continuation>)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> ((a (result 1)) </div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> (a.5 (lambda (k) (setf cc k) (funcall k 5))) </div><div><span class="Apple-tab-span" style="white-space:pre"> </span> (b (result 2))</div><div>
<span class="Apple-tab-span" style="white-space:pre"> </span> (c (result (+ a a.5 b))))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>(result (list c cc))))</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> </div>
<div>=>#<CLOSURE (LAMBDA (K) :IN BIND) {CBBCE15}></div><div><br></div><div>ORG/IPS/MONAD/CONTINUATION> (funcall * #'identity)</div><div>=> (8 #<CLOSURE (LAMBDA # :IN BIND) {B88785D}>)</div><div><br>
</div><div>ORG/IPS/MONAD/CONTINUATION> (funcall (second *) 6)</div><div>=> (9 #<CLOSURE (LAMBDA # :IN BIND) {B88785D}>)</div><div><br></div><div>ORG/IPS/MONAD/CONTINUATION> (funcall (second *) 10)</div><div>
=> (13 #<CLOSURE (LAMBDA # :IN BIND) {B88785D}>)</div></div><div><br></div><div>So, that is call/cc based on the cont monad, in IPS. w00t.</div><div><br></div><div>any questions/comments/etc are most welcome.</div>
<div><br></div><div>Cheers, </div><div>drewc</div><br><div class="gmail_quote">On Mon, Oct 29, 2012 at 1:50 PM, Dan Lentz <span dir="ltr"><<a href="mailto:danlentz@gmail.com" target="_blank">danlentz@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Fare<br>
<br>
I've got ctries, redblack trees, and weight-balanced trees I've been<br>
thinking about trying to integrate with/into LIL. I would be proud if<br>
any/all of it were to be rolled into the LIL project proper.<br>
<br>
Regarding non-concurrent structures with concurrent interface -- I'm<br>
probably not the most qualified to answer but if you we're to ask me I<br>
think that new futures library by deliciousrobot looks interesting.<br>
It implements cooperative multitasking based on green threads built<br>
using cl-cont.<br>
<br>
My access to email is sporadic over the next day or so. Everyone here<br>
in South Jersey is hunkered down in anticipation of the hurricane.<br>
<br>
best regards,<br>
Dan Lentz<br>
<div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
lisp-interface-library-devel mailing list<br>
<a href="mailto:lisp-interface-library-devel@common-lisp.net">lisp-interface-library-devel@common-lisp.net</a><br>
<a href="http://lists.common-lisp.net/cgi-bin/mailman/listinfo/lisp-interface-library-devel" target="_blank">http://lists.common-lisp.net/cgi-bin/mailman/listinfo/lisp-interface-library-devel</a><br>
</div></div></blockquote></div><br></div>