Re: [stack] define primrec in joy
stevan apter — 2005-08-20 21:33:14
i have this in my notes as:
[zero?] -rot swap [pop] swap concat swap [dup pred] swap linrec
-rot is a b c -> c a b
i don't recall whether that's rollup or rolldown in joy.
i don't remember what the joy equivalent of the zero? predicate is.
(i won't vouch for its correctness)
----- Original Message -----
From: "icpdesign" <taoufik.dachraoui@...>
To: <concatenative@yahoogroups.com>
Sent: Saturday, August 20, 2005 5:24 PM
Subject: [stack] define primrec in joy
The paper 'An Informal Tutorial on Joy', by Manfred von Thun, introduces the combinator
primrec to compute the factorial of any integer. I am wondering if it is possible to define
primrec using joy:
DEFINE
primrec == ...
Thanks
Taoufik
Yahoo! Groups Links
stevan apter — 2005-08-20 21:37:58
actually, now that i've tested it in XY, i *will* vouch for its
correctness, but only in XY. :)
here's how it looks in XY:
; primrec- [zero?] -rot swap [pop] swap , swap [dup pred] swap linrec ;
and the purely recursive version without linrec:
; primrec { [n p c] p i 1 n 1 + c primrec. } ;
; primrec. { [k n c] k n = [] [k c i k 1 + n c _z] if } ;
----- Original Message -----
From: "stevan apter" <sa@...>
To: <concatenative@yahoogroups.com>
Sent: Saturday, August 20, 2005 5:33 PM
Subject: Re: [stack] define primrec in joy
> i have this in my notes as:
>
> [zero?] -rot swap [pop] swap concat swap [dup pred] swap linrec
>
> -rot is a b c -> c a b
>
> i don't recall whether that's rollup or rolldown in joy.
>
> i don't remember what the joy equivalent of the zero? predicate is.
>
> (i won't vouch for its correctness)
>
>
> ----- Original Message -----
> From: "icpdesign" <taoufik.dachraoui@...>
> To: <concatenative@yahoogroups.com>
> Sent: Saturday, August 20, 2005 5:24 PM
> Subject: [stack] define primrec in joy
>
>
> The paper 'An Informal Tutorial on Joy', by Manfred von Thun, introduces the combinator
> primrec to compute the factorial of any integer. I am wondering if it is possible to define
> primrec using joy:
>
> DEFINE
> primrec == ...
>
> Thanks
> Taoufik
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
icpdesign — 2005-08-20 22:01:50
Your definition uses another recursive combinator (linrec). So how do we define linrec?
The tutorial gives the following sketch on how primrec executes:
"... pops the two quotations off the stack and saves them elsewhere. Then primrec tests
whether the top element on the stack (initially the 5) is equal to zero. If it is, it pops it off
and executes one of the quotations, the [1] which leaves 1 on the stack as the result.
Otherwise it pushes a decremented copy of the top element and recurses."
I am interested on how to implement "recurses" without defining a recursive function, is it
possible in joy?.
My understanding is that primrec is a primitive in joy and that it is implemented in C using
a recursive function, so i thought that we can define primrec as a recursive function as
follows:
primrec == ; q1 q2
"pops the two quotations off the stack and saves them elsewhere"
[0 =] [pop q1] ["pushes a decremented copy of the top element" primrec] ifte
Is it possible to define primrec (or linrec) without using a recursive definition
Taoufik
--- In concatenative@yahoogroups.com, "stevan apter" <sa@n...> wrote:
> i have this in my notes as:
>
> [zero?] -rot swap [pop] swap concat swap [dup pred] swap linrec
>
> -rot is a b c -> c a b
>
> i don't recall whether that's rollup or rolldown in joy.
>
> i don't remember what the joy equivalent of the zero? predicate is.
>
> (i won't vouch for its correctness)
>
>
> ----- Original Message -----
> From: "icpdesign" <taoufik.dachraoui@w...>
> To: <concatenative@yahoogroups.com>
> Sent: Saturday, August 20, 2005 5:24 PM
> Subject: [stack] define primrec in joy
>
>
> The paper 'An Informal Tutorial on Joy', by Manfred von Thun, introduces the
combinator
> primrec to compute the factorial of any integer. I am wondering if it is possible to define
> primrec using joy:
>
> DEFINE
> primrec == ...
>
> Thanks
> Taoufik
>
>
>
>
>
>
> Yahoo! Groups Links
icpdesign — 2005-08-20 22:06:24
I am glad that you read my mind. I wanted to see the following definitions:
> ; primrec { [n p c] p i 1 n 1 + c primrec. } ;
> ; primrec. { [k n c] k n = [] [k c i k 1 + n c _z] if } ;
Do you know how to write this in joy?
Thank you
Taoufik
--- In concatenative@yahoogroups.com, "stevan apter" <sa@n...> wrote:
> actually, now that i've tested it in XY, i *will* vouch for its
> correctness, but only in XY. :)
>
> here's how it looks in XY:
>
> ; primrec- [zero?] -rot swap [pop] swap , swap [dup pred] swap linrec ;
>
> and the purely recursive version without linrec:
>
> ; primrec { [n p c] p i 1 n 1 + c primrec. } ;
> ; primrec. { [k n c] k n = [] [k c i k 1 + n c _z] if } ;
>
>
>
> ----- Original Message -----
> From: "stevan apter" <sa@n...>
> To: <concatenative@yahoogroups.com>
> Sent: Saturday, August 20, 2005 5:33 PM
> Subject: Re: [stack] define primrec in joy
>
>
> > i have this in my notes as:
> >
> > [zero?] -rot swap [pop] swap concat swap [dup pred] swap linrec
> >
> > -rot is a b c -> c a b
> >
> > i don't recall whether that's rollup or rolldown in joy.
> >
> > i don't remember what the joy equivalent of the zero? predicate is.
> >
> > (i won't vouch for its correctness)
> >
> >
> > ----- Original Message -----
> > From: "icpdesign" <taoufik.dachraoui@w...>
> > To: <concatenative@yahoogroups.com>
> > Sent: Saturday, August 20, 2005 5:24 PM
> > Subject: [stack] define primrec in joy
> >
> >
> > The paper 'An Informal Tutorial on Joy', by Manfred von Thun, introduces the
combinator
> > primrec to compute the factorial of any integer. I am wondering if it is possible to
define
> > primrec using joy:
> >
> > DEFINE
> > primrec == ...
> >
> > Thanks
> > Taoufik
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >