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


Groups > comp.lang.forth > #16167

Re: Fizz Buzz Zoom

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: Fizz Buzz Zoom
Date 2012-10-10 16:42 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2012Oct10.184225@mips.complang.tuwien.ac.at> (permalink)
References (4 earlier) <7x4nm5dja8.fsf@ruckus.brouhaha.com> <2012Oct8.191146@mips.complang.tuwien.ac.at> <7x626k90t2.fsf@ruckus.brouhaha.com> <2012Oct10.143249@mips.complang.tuwien.ac.at> <2375326.3OPp2VNvLy@sunwukong.fritz.box>

Show all headers | View raw


Bernd Paysan <bernd.paysan@gmx.de> writes:
>Anton Ertl wrote:
>> Concerning the goal of future-proofing the program, I find that hard
>> for a contrived problem; you contrive one extension of the problem,
>> but someone else might contrive a completely different one, and there
>> is no way to predict which contrived extension is more probably.
>> Besides, future-proofing is not the Forth way:-).
>
>But extensibility is.  Let's say the general problem is

I actually meant Chuck Moore's way.  And I think he would not
generalize the problem and design extensibility for that on first
encounter.  Instead, he would see a more general problem and design a
more general program for it only if he encounters several similar
problems.

While I usually lean more in the direction of generalization than most
Forthers, in this case I would just follow Chuck Moore's way, because
it is a contrived problem, and any generalization would be
even more guesswork than usual.

>"print some word 
>if there is a rule to match, print a number if there isn't".

Which does not specify what happens if several rules match.  Paul
Rubin generalized the FizzBuzz problem in a way that answers that
question in a specific way, but what if the interviewer had next
asked: "Now change the program such that it prints 'boing' if the
number is divisible by three and by five".  The "ugly" program would
be easy to fix, while the generalizations along the lines that Paul
Rubin and you have in mind would require more effort.

>Defer check ( flag n -- flag' )  ' drop is check
>
>: list-items ( n1 n2 -- )
>  ?DO  false i check 0= IF  i 0 .r  THEN  cr  LOOP ;
>
>\ check DSL syntactic sugar
>
>: check[  :noname ]] dup >r [[ ['] check defer@ compile, postpone r> ;
>: ]check" ]] dup IF ." THEN or ; [[ is check ; immediate
>
>\ silly checks to test the program
>
>check[ 3 mod 0= ]check" Fizz"
>check[ 5 mod 0= ]check" Buzz"
>check[ 7 mod 0= ]check" Zoom"
>
>121 1 list-items

Cute, because it allows writing checks in different files, or
interspersed with other colon definitions; useful for allowing
extensions by several people.

>A lot of flexibility comes from having source code available, so 
>extensions or modifications are easy to do.  E.g. if I dedice that it is 
>better to append the string to a string variable instead of printing it, 
>I only have to change ]CHECK" and LIST-ITEMS.

But your approach is particularly valuable in cases where one does not
want to change the original source code.  If I can change the source
code, some of the other variants are just as easy to change and easier
to understand.

- 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 2012: http://www.euroforth.org/ef12/

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web