On Thu, 23 Mar 2006 23:47:46 +0100, Matthew D Swank
<·······································@c.net> wrote:
Interesting
You might want to look into Curry
I think it would simplify the implementation
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
On Fri, 24 Mar 2006 09:34:53 +0100, John Thingstad wrote:
> On Thu, 23 Mar 2006 23:47:46 +0100, Matthew D Swank
> <·······································@c.net> wrote:
> Interesting
> You might want to look into Curry
> I think it would simplify the implementation
Do you mean http://www.informatik.uni-kiel.de/~curry/ ?
I'm not sure how that relates to Common Lisp.
Matt
--
"You do not really understand something unless you can
explain it to your grandmother." — Albert Einstein.
On Fri, 24 Mar 2006 13:43:34 +0100, Matthew D Swank
<·······································@c.net> wrote:
> On Fri, 24 Mar 2006 09:34:53 +0100, John Thingstad wrote:
>
>> On Thu, 23 Mar 2006 23:47:46 +0100, Matthew D Swank
>> <·······································@c.net> wrote:
>> Interesting
>> You might want to look into Curry
>> I think it would simplify the implementation
>
> Do you mean http://www.informatik.uni-kiel.de/~curry/ ?
> I'm not sure how that relates to Common Lisp.
>
> Matt
Not exaclty. Haskell Brooks Curry is a mathematician from which
both languages Haskel and Curry are named after.
What I was refering to is a programming tequnique called currying.
http://en.wikipedia.org/wiki/Currying
It is the lightweight cusin of monads.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
On Mon, 27 Mar 2006 00:25:42 +0200, John Thingstad wrote:
> Haskell Brooks Curry is a mathematician from which
> both languages Haskel and Curry are named after.
> What I was refering to is a programming tequnique called currying.
> http://en.wikipedia.org/wiki/Currying
> It is the lightweight cusin of monads.
I am familiar with the technique. In fact, the first cps transformer I
ever wrote was curried. Your use of curry as a proper noun confused me a
little.
The example I posted was an attempt to post a usable, if
primitive generator facility in Common Lisp with as little auxiliary code
as I could manage. Of course I saw ways to simplify it almost immediately
after I posted it, but, as the say in the Perl community, "Warnock
applies". The relatively sparse response to the post didn't encourage me
to modify the code any further.
Sorry I misunderstood you.
Matt
--
"You do not really understand something unless you can
explain it to your grandmother." — Albert Einstein.
Matthew D Swank <·······································@c.net> wrote:
+---------------
| Of course I saw ways to simplify it almost immediately
| after I posted it, but, as the say in the Perl community,
| "Warnock applies".
+---------------
Interesting. I'd never heard of this one before. (Of course,
it's named for *Bryan*, not John [no relation either] or me...) ;-}
-Rob
-----
Rob Warnock <····@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607
Rob Warnock wrote:
> Matthew D Swank <·······································@c.net> wrote:
> +---------------
> | Of course I saw ways to simplify it almost immediately
> | after I posted it, but, as the say in the Perl community,
> | "Warnock applies".
> +---------------
>
> Interesting. I'd never heard of this one before. (Of course,
> it's named for *Bryan*, not John [no relation either] or me...) ;-}
In this group `Warnock evals.'
Joe Marshall <··········@gmail.com> wrote:
+---------------
| Rob Warnock wrote:
| > Matthew D Swank <·······································@c.net> wrote:
| > +---------------
| > | "Warnock applies".
| > +---------------
| >
| > Interesting. I'd never heard of this one before.
|
| In this group `Warnock evals.'
+---------------
ROTFL! Got me... ;-} ;-}
[Though eval'ing also requires apply'ing, in general, and v-v...]
-Rob
-----
Rob Warnock <····@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607
On Mon, 27 Mar 2006 01:39:40 +0200, Matthew D Swank
<·······································@c.net> wrote:
> On Mon, 27 Mar 2006 00:25:42 +0200, John Thingstad wrote:
>
>> Haskell Brooks Curry is a mathematician from which
>> both languages Haskel and Curry are named after.
>> What I was refering to is a programming tequnique called currying.
>> http://en.wikipedia.org/wiki/Currying
>> It is the lightweight cusin of monads.
>
> I am familiar with the technique. In fact, the first cps transformer I
> ever wrote was curried. Your use of curry as a proper noun confused me a
> little.
> The example I posted was an attempt to post a usable, if
> primitive generator facility in Common Lisp with as little auxiliary code
> as I could manage. Of course I saw ways to simplify it almost
> immediately
> after I posted it, but, as the say in the Perl community, "Warnock
> applies". The relatively sparse response to the post didn't encourage me
> to modify the code any further.
>
> Sorry I misunderstood you.
>
> Matt
>
I encourage you to try some more.
I thought your code looked great.
Thought it could use some improvements
don't let the slow response here slow
you down.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
On Tue, 28 Mar 2006 03:29:58 -0600, Matthew D Swank wrote:
Next is a little too eager.
Delete:
> ;;add a run method for cons (prolly means yields should be their own class)
>
> (defmethod run ((monad-val cons))
> monad-val)
>
and redefine next:
(defun next (generator &optional return-value)
(let ((gen-pair (run generator)))
(if (null gen-pair)
(values nil nil)
(destructuring-bind (gen . val) gen-pair
(values (continuation #'(lambda (current)
(declare (ignore current))
(funcall gen return-value)))
val)))))
Matt
--
"You do not really understand something unless you can
explain it to your grandmother." — Albert Einstein.
Matthew D Swank wrote:
> I suppose this is a little long but coroutines have come up a bit lately,
<snip>
Thank you for this code. I am trying to use it, but I cannot say I
understand it fully. I probably need to spend more time with
continuations and monads. Even the most basic thing is baffling me: I'm
trying to write the equivalent of the following Scheme code:
(call/cc (lambda (k) (k 42)))
My guess is it should look like this:
(call/cc (lambda (k) (funcall (func-object k) 42)))
...but this returns a continuation. What am I doing wrong?
On Tue, 28 Mar 2006 11:24:57 +0200, Philippe Lorin wrote:
> Matthew D Swank wrote:
>> I suppose this is a little long but coroutines have come up a bit lately,
> <snip>
>
> Thank you for this code. I am trying to use it, but I cannot say I
> understand it fully. I probably need to spend more time with
> continuations and monads. Even the most basic thing is baffling me: I'm
> trying to write the equivalent of the following Scheme code:
> (call/cc (lambda (k) (k 42)))
>
> My guess is it should look like this:
> (call/cc (lambda (k) (funcall (func-object k) 42)))
>
> ...but this returns a continuation. What am I doing wrong?
Well, k is just a normal function so you don't have to use func-object.
Also, once you have a continuation object you can see what it evaluates
too by running it. So:
(run (call/cc (lambda (k) (funcall k 42))))
=> 42
If using the datatype is confusing you can also use this simpler
formulation:
;;continuation == (A -> Answer) -> Answer
(defun unit (val)
#'(lambda (current) (funcall current val)))
(defun bind (continuation next)
#'(lambda (current)
(funcall continuation
#'(lambda (val)
(funcall (funcall next val)
current)))))
(defun run (continuation)
(funcall continuation #'identity))
;;;((A -> continuation) -> continuation) -> continuation
(defun call/cc (entry-point)
#'(lambda (current)
(flet ((escape (val)
;;compare with unit
#'(lambda (final)
(declare (ignore final))
(funcall current val))))
;;compare with bind
(funcall (funcall entry-point #'escape)
current))))
Also CPS (Continuation Passing Style) is a little more traditional in
lisp, but I like the monadic form since it seems a little less clunky to
me in code I actually have to read (as opposed to using CPS as a
technique to transform code automatically). However, I am prepared to
believe that mine is a minority opinion among Common Lisp users.
Matt
--
"You do not really understand something unless you can
explain it to your grandmother." — Albert Einstein.
On Fri, 07 Apr 2006 11:26:26 +0200, Philippe Lorin wrote:
> Matthew D Swank wrote:
>> (defun unit (val)
>> #'(lambda (current) (funcall current val)))
>
> Could you explain what UNIT is used for?
It's used to "inject" a value into the continuation monad. Monadic
continuations are just functions, functions that take a particular type of
a function as an argument. Confusingly this argument is also called a
(primitive) continuation.
Maybe a example is in order:
In regular CPS the primitive continuation is passed as an argument:
(defun add (a b k)
(funcall k (+ a b)))
So k takes (+ a b) and spits out an answer.
(add 2 3 #'identity)
=> 5
In monadic continuations instead of passing k to each function, each
function returns a higher order function that will take a primitive
continuation as an argument.
In our example:
(defun add (a b)
#'(lambda (k) (funcall k (+ a b))))
So UNIT encapsulates the operation of passing a value to the current
continuation:
(defun add (a b)
(unit (+ a b)))
(funcall (add 2 3) #'identity)
=> 5
Matt
--
"You do not really understand something unless you can
explain it to your grandmother." — Albert Einstein.