Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #26102 > unrolled thread

Y combinator

Started byLars Brinkhoff <lars.spam@nocrew.org>
First post2013-10-03 09:57 +0200
Last post2013-10-07 15:06 +0200
Articles 3 — 2 participants

Back to article view | Back to comp.lang.forth

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Y combinator Lars Brinkhoff <lars.spam@nocrew.org> - 2013-10-03 09:57 +0200
    Re: Y combinator anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-10-03 13:09 +0000
      Re: Y combinator Lars Brinkhoff <lars.spam@nocrew.org> - 2013-10-07 15:06 +0200

#26102 — Y combinator

FromLars Brinkhoff <lars.spam@nocrew.org>
Date2013-10-03 09:57 +0200
SubjectY combinator
Message-ID<85eh82hjlr.fsf@junk.nocrew.org>
> Defining Y in ANS Forth (no RECURSIVE) is left as an exercise to the
> reader:-)

I read, I exercised, I posted.

: y ( xt1 -- xt2 )   here tuck 2>r  1 cells allot
   :noname r> postpone literal postpone @ r> compile, postpone ;
   dup rot ! ;

\ Sample usage, factorial function:
:noname ( u1 xt -- u2 )   over ?dup if 1- swap execute * else 2drop 1 then ;
y 6 swap execute .

[toc] | [next] | [standalone]


#26105

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2013-10-03 13:09 +0000
Message-ID<2013Oct3.150934@mips.complang.tuwien.ac.at>
In reply to#26102
Lars Brinkhoff <lars.spam@nocrew.org> writes:
[Anton Ertl in 2002:-)]
>> Defining Y in ANS Forth (no RECURSIVE) is left as an exercise to the
>> reader:-)
>
>I read, I exercised, I posted.
>
>: y ( xt1 -- xt2 )   here tuck 2>r  1 cells allot
>   :noname r> postpone literal postpone @ r> compile, postpone ;
>   dup rot ! ;

Nice.

Now Curry's definition of Y is

Y = lambda f.(lambda x.f (x x))(lambda x.f (x x))

I am wondering what capabilities of Forth we have to remove until we
have to go to these lengths.

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2013: http://www.euroforth.org/ef13/

[toc] | [prev] | [next] | [standalone]


#26344

FromLars Brinkhoff <lars.spam@nocrew.org>
Date2013-10-07 15:06 +0200
Message-ID<85vc19dydi.fsf@junk.nocrew.org>
In reply to#26105
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
> Lars Brinkhoff <lars.spam@nocrew.org> writes:
>>: y ( xt1 -- xt2 )   here tuck 2>r  1 cells allot
>>   :noname r> postpone literal postpone @ r> compile, postpone ;
>>   dup rot ! ;
>
> Nice.
>
> Now Curry's definition of Y is
>
> Y = lambda f.(lambda x.f (x x))(lambda x.f (x x))
>
> I am wondering what capabilities of Forth we have to remove until we
> have to go to these lengths.

"Why" indeed.

I was tempted to submit this smaller version, but felt that the named
definition was not quite in the spirit of the original Y.

: y ( xt "name" -- )   >in @ create >in ! , ' ,  does> 2@ execute ;

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web