Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #16015 > unrolled thread
| Started by | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| First post | 2012-10-07 09:19 -0700 |
| Last post | 2013-03-01 20:49 +0100 |
| Articles | 3 on this page of 43 — 14 participants |
Back to article view | Back to comp.lang.forth
Fizz Buzz Zoom Paul Rubin <no.email@nospam.invalid> - 2012-10-07 09:19 -0700
Re: Fizz Buzz Zoom mhx@iae.nl (Marcel Hendrix) - 2012-10-07 20:33 +0200
Re: Fizz Buzz Zoom Paul Rubin <no.email@nospam.invalid> - 2012-10-07 11:43 -0700
Re: Fizz Buzz Zoom mhx@iae.nl (Marcel Hendrix) - 2012-10-07 21:09 +0200
Re: Fizz Buzz Zoom Paul Rubin <no.email@nospam.invalid> - 2012-10-07 12:18 -0700
Re: Fizz Buzz Zoom ouatubi@gmail.com - 2012-10-08 01:15 -0700
Re: Fizz Buzz Zoom Paul Rubin <no.email@nospam.invalid> - 2012-10-08 09:37 -0700
Re: Fizz Buzz Zoom ouatubi@gmail.com - 2012-10-09 01:16 -0700
Re: Fizz Buzz Zoom Doug Hoffman <glidedog@gmail.com> - 2012-10-07 14:45 -0400
Re: Fizz Buzz Zoom Paul Rubin <no.email@nospam.invalid> - 2012-10-07 12:28 -0700
Re: Fizz Buzz Zoom Doug Hoffman <glidedog@gmail.com> - 2012-10-07 21:06 -0400
Re: Fizz Buzz Zoom Paul Rubin <no.email@nospam.invalid> - 2012-10-07 21:32 -0700
Re: Fizz Buzz Zoom Doug Hoffman <glidedog@gmail.com> - 2012-10-08 06:06 -0400
Re: Fizz Buzz Zoom Mark Wills <forthfreak@gmail.com> - 2012-10-08 05:24 -0700
Re: Fizz Buzz Zoom anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-10-08 14:02 +0000
Re: Fizz Buzz Zoom Paul Rubin <no.email@nospam.invalid> - 2012-10-08 08:38 -0700
Re: Fizz Buzz Zoom Paul Rubin <no.email@nospam.invalid> - 2012-10-08 08:43 -0700
Re: Fizz Buzz Zoom "A. K." <akk@nospam.org> - 2012-10-08 18:03 +0200
Re: Fizz Buzz Zoom anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-10-08 16:08 +0000
Re: Fizz Buzz Zoom Paul Rubin <no.email@nospam.invalid> - 2012-10-08 09:23 -0700
Re: Fizz Buzz Zoom anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-10-08 17:11 +0000
Re: Fizz Buzz Zoom Bernd Paysan <bernd.paysan@gmx.de> - 2012-10-08 22:12 +0200
Re: Fizz Buzz Zoom Paul Rubin <no.email@nospam.invalid> - 2012-10-08 13:16 -0700
Re: Fizz Buzz Zoom Hannu Vuolasaho <hannu.vuolasaho@nospam.tut.fi.invalid> - 2012-10-08 21:06 +0000
Re: Fizz Buzz Zoom "Elizabeth D. Rather" <erather@forth.com> - 2012-10-08 11:57 -1000
Re: Fizz Buzz Zoom Mark Wills <forthfreak@gmail.com> - 2012-10-09 01:26 -0700
Re: Fizz Buzz Zoom George Hubert <georgeahubert@yahoo.co.uk> - 2012-10-09 08:38 -0700
Re: Fizz Buzz Zoom Paul Rubin <no.email@nospam.invalid> - 2012-10-09 09:03 -0700
Re: Fizz Buzz Zoom "Elizabeth D. Rather" <erather@forth.com> - 2012-10-09 08:44 -1000
Re: Fizz Buzz Zoom anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-10-10 12:32 +0000
Re: Fizz Buzz Zoom Bernd Paysan <bernd.paysan@gmx.de> - 2012-10-10 16:59 +0200
Re: Fizz Buzz Zoom anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-10-10 16:42 +0000
Re: Fizz Buzz Zoom Paul Rubin <no.email@nospam.invalid> - 2012-10-12 21:18 -0700
Re: Fizz Buzz Zoom "Elizabeth D. Rather" <erather@forth.com> - 2012-10-12 21:06 -1000
Re: Fizz Buzz Zoom Doug Hoffman <glidedog@gmail.com> - 2012-10-10 09:02 -0400
Re: Fizz Buzz Zoom Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2012-10-08 17:50 +0100
Re: Fizz Buzz Zoom Paul Rubin <no.email@nospam.invalid> - 2012-10-08 10:15 -0700
Re: Fizz Buzz Zoom "WJ" <w_a_x_man@yahoo.com> - 2013-03-01 02:37 +0000
Re: Fizz Buzz Zoom "WJ" <w_a_x_man@yahoo.com> - 2013-03-01 04:51 +0000
Re: Fizz Buzz Zoom Doug Hoffman <glidedog@gmail.com> - 2013-03-01 05:38 -0500
Re: Fizz Buzz Zoom "WJ" <w_a_x_man@yahoo.com> - 2013-03-01 16:23 +0000
Re: Fizz Buzz Zoom "WJ" <w_a_x_man@yahoo.com> - 2013-03-01 16:36 +0000
Re: Fizz Buzz Zoom Coos Haak <chforth@hccnet.nl> - 2013-03-01 20:49 +0100
Page 3 of 3 — ← Prev page 1 2 [3]
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Date | 2013-03-01 16:23 +0000 |
| Message-ID | <kgqkmo06m4@enews4.newsguy.com> |
| In reply to | #20115 |
WJ wrote:
> Paul Rubin wrote:
>
> > This works in gforth. I'm not sure if it's valid ANS Forth, since it
> > requires multiple s" ..." string literals to be alive at the same time.
> > Coding and testing wasn't difficult in absolute terms, since the program
> > is so small, but it still took multiple tries and head-scratching, and
> > the result seems unmodular compared to a Python version. Maybe there
> > was something I could have done better.
> >
> > : fb0 ( flag sa su n d -- flag )
> > mod 0= if type -1 else 2drop 0 then or ;
> >
> > : fb ( n -- flag ) >r
> > 0 ( flag )
> > s" Fizz" r@ 3 fb0
> > s" Buzz" r@ 5 fb0
> > s" Zoom" r> 7 fb0 ;
> >
> > : f ( n -- ) dup fb ( flag ) 0= if . else drop then cr ;
> >
> > : run ( -- ) \ run to 120 so that 3*5*7=105 is included
> > 120 1 do i f loop ;
>
> Factor:
>
> USING: locals math.ranges ;
>
> :: maybe ( m n str -- )
> m n mod zero? [ str write "N" off ] when ;
>
> : fizz ( -- )
> 1 105 1 <range>
> [ dup "N" set
> [ 3 "Fizz" maybe ] [ 5 "Buzz" maybe ] [ 7 "Zoom" maybe ] tri
> "N" get [ . ] [ nl ] if*
> ] each ;
A simpler way:
:: maybe ( m n str -- m )
m n divisor? [ str write "fizzed" on ] when
m ;
: fizz ( -- )
105 [1,b]
[ "fizzed" off
3 "Fizz" maybe
5 "Buzz" maybe
7 "Zoom" maybe
"fizzed" get [ drop nl ] [ . ] if
] each ;
[toc] | [prev] | [next] | [standalone]
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Date | 2013-03-01 16:36 +0000 |
| Message-ID | <kgqlej07c1@enews4.newsguy.com> |
| In reply to | #20132 |
WJ wrote:
> WJ wrote:
>
> > Paul Rubin wrote:
> >
> > > This works in gforth. I'm not sure if it's valid ANS Forth, since it
> > > requires multiple s" ..." string literals to be alive at the same time.
> > > Coding and testing wasn't difficult in absolute terms, since the program
> > > is so small, but it still took multiple tries and head-scratching, and
> > > the result seems unmodular compared to a Python version. Maybe there
> > > was something I could have done better.
> > >
> > > : fb0 ( flag sa su n d -- flag )
> > > mod 0= if type -1 else 2drop 0 then or ;
> > >
> > > : fb ( n -- flag ) >r
> > > 0 ( flag )
> > > s" Fizz" r@ 3 fb0
> > > s" Buzz" r@ 5 fb0
> > > s" Zoom" r> 7 fb0 ;
> > >
> > > : f ( n -- ) dup fb ( flag ) 0= if . else drop then cr ;
> > >
> > > : run ( -- ) \ run to 120 so that 3*5*7=105 is included
> > > 120 1 do i f loop ;
> >
> > Factor:
> >
> > USING: locals math.ranges ;
> >
> > :: maybe ( m n str -- )
> > m n mod zero? [ str write "N" off ] when ;
> >
> > : fizz ( -- )
> > 1 105 1 <range>
> > [ dup "N" set
> > [ 3 "Fizz" maybe ] [ 5 "Buzz" maybe ] [ 7 "Zoom" maybe ] tri
> > "N" get [ . ] [ nl ] if*
> > ] each ;
>
> A simpler way:
>
> :: maybe ( m n str -- m )
> m n divisor? [ str write "fizzed" on ] when
> m ;
>
> : fizz ( -- )
> 105 [1,b]
> [ "fizzed" off
> 3 "Fizz" maybe
> 5 "Buzz" maybe
> 7 "Zoom" maybe
> "fizzed" get [ drop nl ] [ . ] if
> ] each ;
Another way.
:: maybe ( m bool n str -- m bool )
m n divisor?
[ str write m t ]
[ m bool ]
if ;
: fizz ( -- )
105 [1,b]
[ f
3 "Fizz" maybe
5 "Buzz" maybe
7 "Zoom" maybe
[ drop nl ] [ . ] if
] each ;
[toc] | [prev] | [next] | [standalone]
| From | Coos Haak <chforth@hccnet.nl> |
|---|---|
| Date | 2013-03-01 20:49 +0100 |
| Message-ID | <9f9iph7rgsvg.k1cllsxd940.dlg@40tude.net> |
| In reply to | #20115 |
> Paul Rubin wrote: > >> This works in gforth. I'm not sure if it's valid ANS Forth, since it >> requires multiple s" ..." string literals to be alive at the same time. I can't find your original posting, but why complain over multiple s" ..." string literals? In the following these are compiled and can't therefore overlap. >> >> : fb0 ( flag sa su n d -- flag ) >> mod 0= if type -1 else 2drop 0 then or ; >> >> : fb ( n -- flag ) >r >> 0 ( flag ) Here, >> s" Fizz" r@ 3 fb0 here, >> s" Buzz" r@ 5 fb0 and here >> s" Zoom" r> 7 fb0 ; There might be problems in some implementations if these strings were interpreted. But not in a colon definition. -- Coos CHForth, 16 bit DOS applications http://home.hccnet.nl/j.j.haak/forth.html
[toc] | [prev] | [standalone]
Page 3 of 3 — ← Prev page 1 2 [3]
Back to top | Article view | comp.lang.forth
csiph-web