Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #37946 > unrolled thread
| Started by | humptydumpty <ouatubi@gmail.com> |
|---|---|
| First post | 2015-04-04 14:39 -0700 |
| Last post | 2015-04-05 12:50 -0700 |
| Articles | 6 — 4 participants |
Back to article view | Back to comp.lang.forth
tiny usable ycombinator humptydumpty <ouatubi@gmail.com> - 2015-04-04 14:39 -0700
Re: tiny usable ycombinator Paul Rubin <no.email@nospam.invalid> - 2015-04-05 11:15 -0700
Re: tiny usable ycombinator humptydumpty <ouatubi@gmail.com> - 2015-04-05 12:55 -0700
Re: tiny usable ycombinator franck.bensusan@gmail.com - 2015-04-06 01:35 -0700
Re: tiny usable ycombinator "WJ" <w_a_x_man@yahoo.com> - 2015-04-05 19:38 +0000
Re: tiny usable ycombinator Paul Rubin <no.email@nospam.invalid> - 2015-04-05 12:50 -0700
| From | humptydumpty <ouatubi@gmail.com> |
|---|---|
| Date | 2015-04-04 14:39 -0700 |
| Subject | tiny usable ycombinator |
| Message-ID | <e0d82db3-c7d5-44a4-b3ee-64bae33849b6@googlegroups.com> |
Hi! Fooling around I arrived at some small, usable and beauty ycombinator (gforth code): : YC >R :noname R> compile, ]] dup execute ; [[ ; Example of use, calculate 5 factorial : 1 5 :noname ( 1 n xt -- partfact m xt| ) >r dup 1 > IF tuck * swap 1- r> ELSE 2rdrop THEN ; YC dup execute drop . 120 ok Have a nice day, humptydumpty
[toc] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2015-04-05 11:15 -0700 |
| Message-ID | <87384e5tmd.fsf@jester.gateway.sonic.net> |
| In reply to | #37946 |
humptydumpty <ouatubi@gmail.com> writes: > 1 5 :noname ( 1 n xt -- partfact m xt| ) >r dup 1 > IF tuck * swap 1- > r> ELSE 2rdrop THEN ; YC dup execute drop . 120 ok OMG :-)
[toc] | [prev] | [next] | [standalone]
| From | humptydumpty <ouatubi@gmail.com> |
|---|---|
| Date | 2015-04-05 12:55 -0700 |
| Message-ID | <08cfdf74-a7d1-4836-ac7c-0649cc19038a@googlegroups.com> |
| In reply to | #37970 |
On Sunday, April 5, 2015 at 9:15:39 PM UTC+3, Paul Rubin wrote:
> humptydumpty <> writes:
> > 1 5 :noname ( 1 n xt -- partfact m xt| ) >r dup 1 > IF tuck * swap 1-
> > r> ELSE 2rdrop THEN ; YC dup execute drop . 120 ok
>
> OMG :-)
Isn't that cool? ;-)
That is just my laziness, I just posted line from terminal.
Could be something like:
: YC >R :noname R> compile, ]] dup execute ; [[ ;
:noname ( comment... )
>r dup 1 > IF tuck * swap 1- r> ELSE 2rdrop THEN
; YC CONSTANT yc.factorial ( m n -- m*n! 1 ;bla-bla )
, and when needed kick-it in action ycombinator-way:
1 5 yc.factorial dup execute
Have a nice day,
humptydumpty
[toc] | [prev] | [next] | [standalone]
| From | franck.bensusan@gmail.com |
|---|---|
| Date | 2015-04-06 01:35 -0700 |
| Message-ID | <13e93e1f-1bfc-4360-af8b-763f91675cb5@googlegroups.com> |
| In reply to | #37978 |
Le dimanche 5 avril 2015 21:55:56 UTC+2, humptydumpty a écrit :
> On Sunday, April 5, 2015 at 9:15:39 PM UTC+3, Paul Rubin wrote:
> > humptydumpty <> writes:
> > > 1 5 :noname ( 1 n xt -- partfact m xt| ) >r dup 1 > IF tuck * swap 1-
> > > r> ELSE 2rdrop THEN ; YC dup execute drop . 120 ok
> >
> > OMG :-)
>
> Isn't that cool? ;-)
>
> That is just my laziness, I just posted line from terminal.
>
> Could be something like:
>
> : YC >R :noname R> compile, ]] dup execute ; [[ ;
>
> :noname ( comment... )
> >r dup 1 > IF tuck * swap 1- r> ELSE 2rdrop THEN
> ; YC CONSTANT yc.factorial ( m n -- m*n! 1 ;bla-bla )
>
> , and when needed kick-it in action ycombinator-way:
>
> 1 5 yc.factorial dup execute
>
> Have a nice day,
> humptydumpty
Yes, very very cool !!! Great job !
btw, in Oforth, you could write something like this :
(non stateless Y, but you can also define a stateless Y).
func: Y(f) { #[ Y(f) f perform ] }
Now fact definition :
func: almost-fact(f, n) { n ifZero: [ 1 ] else: [ n n 1 - f perform * ] }
func: fact { #almost-fact Y perform }
5 fact println
120
Franck
[toc] | [prev] | [next] | [standalone]
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Date | 2015-04-05 19:38 +0000 |
| Message-ID | <mfs2vr$drb$1@dont-email.me> |
| In reply to | #37946 |
humptydumpty wrote: > Example of use, calculate 5 factorial : > > > 1 5 :noname ( 1 n xt -- partfact m xt| ) > >r dup 1 > > IF tuck * swap 1- r> ELSE 2rdrop THEN ; YC dup execute drop . 120 ok Oforth: > 1 #* 5 seq apply .s [1] (Integer) 120
[toc] | [prev] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2015-04-05 12:50 -0700 |
| Message-ID | <87pp7i4ano.fsf@jester.gateway.sonic.net> |
| In reply to | #37975 |
"WJ" <w_a_x_man@yahoo.com> writes: > Oforth: > > 1 #* 5 seq apply .s > [1] (Integer) 120 That misses the point. You are supposed to do this without using any iteration or recursion, including "seq" which works iteratively or recursively under the hood. https://en.wikipedia.org/wiki/Fixed-point_combinator
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web