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


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

Valentine Bingo - Comments?

Started bySteve Graham <jsgrahamus@yahoo.com>
First post2012-01-26 14:24 -0700
Last post2012-03-07 22:10 -0800
Articles 20 on this page of 32 — 15 participants

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


Contents

  Valentine Bingo - Comments? Steve Graham <jsgrahamus@yahoo.com> - 2012-01-26 14:24 -0700
    Re: Valentine Bingo - Comments? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-02-01 23:12 -0800
    Re: Valentine Bingo - Comments? Paul Rubin <no.email@nospam.invalid> - 2012-02-04 21:15 -0800
      Re: Valentine Bingo - Comments? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-02-07 17:59 -0800
      Re: Valentine Bingo - Comments? Steve Graham <jsgrahamus@yahoo.com> - 2012-02-08 07:53 -0700
        Re: Valentine Bingo - Comments? Paul Rubin <no.email@nospam.invalid> - 2012-02-08 10:59 -0800
    Re: Valentine Bingo - Comments? crc <charles.childers@gmail.com> - 2012-02-03 11:35 -0800
    Re: Valentine Bingo - Comments? Steve Graham <jsgrahamus@yahoo.com> - 2012-02-07 07:39 -0700
    Re: Valentine Bingo - Comments? "WJ" <w_a_x_man@yahoo.com> - 2012-03-03 05:32 +0000
      Re: Valentine Bingo - Comments? "Elizabeth D. Rather" <erather@forth.com> - 2012-03-02 21:00 -1000
      Re: Valentine Bingo - Comments? "WJ" <w_a_x_man@yahoo.com> - 2012-03-03 09:21 +0000
        Re: Valentine Bingo - Comments? Paul Rubin <no.email@nospam.invalid> - 2012-03-03 01:26 -0800
          Re: Valentine Bingo - Comments? Josh Grams <josh@qualdan.com> - 2012-03-03 12:52 +0000
            Re: Valentine Bingo - Comments? John Passaniti <john.passaniti@gmail.com> - 2012-03-03 14:08 -0800
              Re: Valentine Bingo - Comments? Paul Rubin <no.email@nospam.invalid> - 2012-03-03 14:41 -0800
                Re: Valentine Bingo - Comments? John Passaniti <john.passaniti@gmail.com> - 2012-03-03 17:39 -0800
                  Re: Valentine Bingo - Comments? Paul Rubin <no.email@nospam.invalid> - 2012-03-03 19:18 -0800
                    Re: Valentine Bingo - Comments? vandys@vsta.org - 2012-03-05 17:27 +0000
              Re: Valentine Bingo - Comments? "Elizabeth D. Rather" <erather@forth.com> - 2012-03-03 17:51 -1000
              Re: Valentine Bingo - Comments? Josh Grams <josh@qualdan.com> - 2012-03-04 12:29 +0000
                Re: Valentine Bingo - Comments? Rugxulo <rugxulo@gmail.com> - 2012-03-04 07:53 -0800
                  Re: Valentine Bingo - Comments? Josh Grams <josh@qualdan.com> - 2012-03-04 17:24 +0000
                    Re: Valentine Bingo - Comments? Rugxulo <rugxulo@gmail.com> - 2012-03-04 11:41 -0800
              Re: Valentine Bingo - Comments? Rugxulo <rugxulo@gmail.com> - 2012-03-04 08:16 -0800
                Re: Valentine Bingo - Comments? Bernd Paysan <bernd.paysan@gmx.de> - 2012-03-04 17:39 +0100
                  Re: Valentine Bingo - Comments? Bernd Paysan <bernd.paysan@gmx.de> - 2012-03-04 17:42 +0100
                Re: Valentine Bingo - Comments? kenney@cix.compulink.co.uk - 2012-03-05 04:09 -0600
      Re: Valentine Bingo - Comments? Rugxulo <rugxulo@gmail.com> - 2012-03-03 11:35 -0800
      Re: Valentine Bingo - Comments? Doug Hoffman <glidedog@gmail.com> - 2012-03-04 10:07 -0500
        Re: Valentine Bingo - Comments? mhx@iae.nl (Marcel Hendrix) - 2012-03-04 17:42 +0200
          Re: Valentine Bingo - Comments? hwfwguy@gmail.com - 2012-03-06 20:38 -0800
        Re: Valentine Bingo - Comments? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-03-07 22:10 -0800

Page 1 of 2  [1] 2  Next page →


#9243 — Valentine Bingo - Comments?

FromSteve Graham <jsgrahamus@yahoo.com>
Date2012-01-26 14:24 -0700
SubjectValentine Bingo - Comments?
Message-ID<jfsgbb$lu6$1@speranza.aioe.org>
Thanks to all who posted comments to the earlier Word Array posting.

Here is the finished (for now) program which prints out 1 or more 
Valentine Bingo Cards.  I'd be interested in any comments on style, etc.

Thanks, Steve

---

\
\ Valentine Bingo
\

create wordarr
     ," Be Mine"
     ," Love"
     ," It's Love"
     ," All Mine"
     ," Kiss Me"
     ," You & Me"
     ," Awesome"
     ," My Baby"
     ," Love Me"
     ," All Star"
     ," My Way"
     ," Love You"
     ," For You"
     ," Cool"
     ," I Hope"
     ," Love Life"
     ," Angel"
     ," Sweet Talk"
     ," True Love"
     ," Be Good"
     ," How Nice"
     ," Let's Kiss"
     ," #1 Fan"
     ," Be True"
     ," Love Her"
     0 ,

\ number of phrases
25 constant #wordarr

\ which numbers chosen
create chosen-bingo-numbers #wordarr allot

\ chosen numbers in order
create ordered-bingo-numbers #wordarr allot

\ jump from one phrase to the next
: jumper	        \ addr -- addr'
   count + aligned
;

\ get nth phrase
: nth$		\ n base -- addr
   swap 0 ?do  jumper  loop
;

\ print phrases
: .tab		\ base --
   begin
     dup @
    while
     dup count cr type  jumper
   repeat
   drop
;

\ print first part of webpage
: .html-1          \ --
     cr
     ." <HTML>" cr
     ."   <BODY>" cr
     ."     <TABLE border=1 height=500 width=500>" cr
     ."       <TR style='color:red;'>" cr
     ."         <TH width='20%'>B</TH>" cr
     ."         <TH width='20%'>I</TH>" cr
     ."         <TH width='20%'>N</TH>" cr
     ."         <TH width='20%'>G</TH>" cr
     ."         <TH width='20%'>O</TH></TR>" cr
;

\ print last part of webpage
: .html-2          \ --
     cr ."     </TABLE>"
     cr ."   </BODY>"
     cr ."  </HTML>"
     cr
  ;

\ get 24 random non-repeating numbers in order
: get-bingo-numbers  \ --
     #wordarr chosen-bingo-numbers over erase
     ordered-bingo-numbers over erase
     24 0 do
        dup choose
        begin
          dup chosen-bingo-numbers + c@ 0 >
          while
            drop dup choose
        repeat
        chosen-bingo-numbers over + 1 swap c!
        ordered-bingo-numbers i + c!
     loop
     drop
;

\ print nth square's phrase given proper number
: (.square)         \ n --
     ordered-bingo-numbers + c@
     wordarr nth$ count type
;

\ print nth square's phrase given any number
: .square           \ n --
     dup 12 <
     if   (.square)
     else dup 12 =
          if   drop ." Free Square"
          else 1- (.square)
          then
      then
;

\ print rows of bingo card
: .rows              \ --
   5 0 do
     cr ."       <TR align='center' >"
     5 0 do
       cr ."         <TD>"
       j 5 * i +
       .square
       cr ."         </TD>"
     loop
     cr ."       </TR>"
   loop
;

\ print n bingo cards
: .cards             \ n --
     0 do
       get-bingo-numbers
       .html-1
       .rows
       .html-2
     loop
;

---

1 .cards
<HTML>
   <BODY>
     <TABLE border=1 height=500 width=500>
       <TR style='color:red;'>
         <TH width='20%'>B</TH>
         <TH width='20%'>I</TH>
         <TH width='20%'>N</TH>
         <TH width='20%'>G</TH>
         <TH width='20%'>O</TH></TR>

       <TR align='center' >
         <TD>True Love
         </TD>
         <TD>I Hope
         </TD>
         <TD>You & Me
         </TD>
         <TD>Be Good
         </TD>
         <TD>For You
         </TD>
       </TR>
       <TR align='center' >
         <TD>Love
         </TD>
         <TD>Sweet Talk
         </TD>
         <TD>All Mine
         </TD>
         <TD>How Nice
         </TD>
         <TD>Angel
         </TD>
       </TR>
       <TR align='center' >
         <TD>Cool
         </TD>
         <TD>Be Mine
         </TD>
         <TD>Free Square
         </TD>
         <TD>All Star
         </TD>
         <TD>Let's Kiss
         </TD>
       </TR>
       <TR align='center' >
         <TD>Love Me
         </TD>
         <TD>Kiss Me
         </TD>
         <TD>#1 Fan
         </TD>
         <TD>My Way
         </TD>
         <TD>Love Her
         </TD>
       </TR>
       <TR align='center' >
         <TD>My Baby
         </TD>
         <TD>It's Love
         </TD>
         <TD>Love You
         </TD>
         <TD>Love Life
         </TD>
         <TD>Awesome
         </TD>
       </TR>
     </TABLE>
   </BODY>
  </HTML>
  ok

[toc] | [next] | [standalone]


#9357

FromHugh Aguilar <hughaguilar96@yahoo.com>
Date2012-02-01 23:12 -0800
Message-ID<ea3e5d2d-8108-4bd5-8623-5635540e96c5@o12g2000vbd.googlegroups.com>
In reply to#9243
On Jan 26, 2:24 pm, Steve Graham <jsgraha...@yahoo.com> wrote:
> Thanks to all who posted comments to the earlier Word Array posting.
>
> Here is the finished (for now) program which prints out 1 or more
> Valentine Bingo Cards.  I'd be interested in any comments on style, etc.
>
> Thanks, Steve

Good job on writing a program, Steve! I have a great deal of respect
for anybody who writes a Forth program (as compared to just claiming
to be the world's expert on Forth without every writing any Forth code
at all).

I rewrote the program to use my novice package (http://www.forth.org/
novice.html). In regard to style, I don't like all of those nested
control-structures and stair-step indentation. I largely avoided that
in my version.

My program is totally ANS-Forth compatible. I would be interested in
seeing any of the comp.lang.forth crowd write a version of their own.
Maybe you could all work together on it!

I removed all of the comments from my program so that they wouldn't
get word-wrapped in this post. The fully commented program is
available by email if anybody wants to see it. Here is the version
without comments:


\ We need NOVICE.4TH    already loaded.
\ We need LIST.4TH      already loaded.

marker bingo.4th

5 constant squares

squares 2/ constant middle

squares dup * 1- constant min-phrases

variable phrases
variable #phrases

squares squares w  2array card

variable html


: append-html ( head -- )
    html @  swap link
    html ! ;

: fill-phrases ( -- )
    c" phrases.txt" read-seq    dup phrases !
    length                      #phrases !
    #phrases @  min-phrases  < abort" *** PHRASES.TXT file needs at
least enough phrases to fill bingo card ***"
    squares 1 and           0= abort" *** SQUARES needs to be an odd
number so there is a middle square ***" ;

: <fill-card> ( element -- )
    phrases @  #phrases @ rnd  nth
    phrases @  swap  remove
    rot !
    phrases !  -1 #phrases +! ;

: fill-card ( -- )
    card-zero
    c" FREE " new-seq  middle middle card !
    lim-card ^card do
        I @ 0= if  I <fill-card>  then
        w +loop ;

: <fill-html> { element -- }
    <cstr
        c"         <TD> "   +cstr
        element @  .line @  +cstr
        c"  </TD>"          +cstr
    cstr> new-seq  append-html ;

: fill-html ( -- )
    c" prologue.html"                   read-seq  html !
    squares 0 do
        c"       <TR align='center' >"  new-seq   append-html
        squares 0 do  I J card  <fill-html>  loop
        c"       </TR>"                 new-seq   append-html
        loop
    c" epilogue.html"                   read-seq  append-html ;

: generate-html { filename -- }
    init-seed
    fill-phrases
    fill-card
    fill-html
    html @  filename  write-seq
    lim-card ^card do  I @ <kill-seq>  w +loop
    html @ kill-seq
    phrases @ kill-seq ;


You also need the PROLOGUE.HTML file:

<HTML>
  <BODY>
    <TABLE border=1 height=500 width=500>
      <TR style='color:red;'>
        <TH width='20%'>B</TH>
        <TH width='20%'>I</TH>
        <TH width='20%'>N</TH>
        <TH width='20%'>G</TH>
        <TH width='20%'>O</TH></TR>


You also need the EPILOGUE.HTML file:

    </TABLE>
  </BODY>
</HTML>


And finally, you need a PHRASES.TXT file (this can contain as many
phrases as you want):

Be Mine
Love
It's Love
All Mine
Kiss Me
You & Me
Awesome
My Baby
Love Me
All Star
My Way
Love You
For You
Cool
I Hope
Love Life
Angel
Sweet Talk
True Love
Be Good
How Nice
Let's Kiss
#1 Fan
Be True
Love Her


This is an example result:

<HTML>
  <BODY>
    <TABLE border=1 height=500 width=500>
      <TR style='color:red;'>
        <TH width='20%'>B</TH>
        <TH width='20%'>I</TH>
        <TH width='20%'>N</TH>
        <TH width='20%'>G</TH>
        <TH width='20%'>O</TH></TR>
      <TR align='center' >
        <TD> Love You  </TD>
        <TD> How Nice  </TD>
        <TD> Be Good  </TD>
        <TD> #1 Fan  </TD>
        <TD> You & Me  </TD>
      </TR>
      <TR align='center' >
        <TD> For You  </TD>
        <TD> Angel  </TD>
        <TD> Awesome  </TD>
        <TD> Cool  </TD>
        <TD> My Way  </TD>
      </TR>
      <TR align='center' >
        <TD> It's Love  </TD>
        <TD> All Mine  </TD>
        <TD> FREE  </TD>
        <TD> Be Mine  </TD>
        <TD> Love  </TD>
      </TR>
      <TR align='center' >
        <TD> Kiss Me  </TD>
        <TD> Let's Kiss  </TD>
        <TD> Love Me  </TD>
        <TD> I Hope  </TD>
        <TD> True Love  </TD>
      </TR>
      <TR align='center' >
        <TD> All Star  </TD>
        <TD> My Baby  </TD>
        <TD> Sweet Talk  </TD>
        <TD> Love Life  </TD>
        <TD> Love Her  </TD>
      </TR>
    </TABLE>
  </BODY>
</HTML>

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


#9371

FromPaul Rubin <no.email@nospam.invalid>
Date2012-02-04 21:15 -0800
Message-ID<7xehu9rhcp.fsf@ruckus.brouhaha.com>
In reply to#9243
Steve Graham <jsgrahamus@yahoo.com> writes:
> Here is the finished (for now) program which prints out 1 or more
> Valentine Bingo Cards.  I'd be interested in any comments on style,
> etc.

I'm no Forth wizard either, but generally code in any language should
follow the DRY (Don't Repeat Yourself) principle.  Seeing the same set
of strings in two places in the program is a "code smell".  I also
felt that the weird packed c-addr format and the linear jumping
through it on each output square was a bit clumsy, though it's an
artifact of how ," works.  ," is present in gforth by the way, but
undocumented, so I had to spend a while figuring out what it did.

As an exercise for myself I wrote my own version, partly adapted
from yours.  This works in gforth 0.7.  Gforth doesn't have
the "choose" function or any other built-in random number generator
as far as I can tell, so I had to write a simple one.  I used
gforth's "utime" function (current time in microseconds) to
seed it -- I don't know if VFX has that, but there is probably
something similar.

================================================================

create packed-messages
     ," Be Mine"
     ," Love"
     ," It's Love"
     ," All Mine"
     ," Kiss Me"
     ," You & Me"
     ," Awesome"
     ," My Baby"
     ," Love Me"
     ," All Star"
     ," My Way"
     ," Love You"
     ," For You"
     ," Cool"
     ," I Hope"
     ," Love Life"
     ," Angel"
     ," Sweet Talk"
     ," True Love"
     ," Be Good"
     ," How Nice"
     ," Let's Kiss"
     ," #1 Fan"
     ," Be True"
     ," Love Her"
     0 ,

create pvec 24 cells allot \ array of c-addrs that point to messages
variable pnext             \ pointer to next slot in pvec

\ simple random number generator.  utime is a gforth word that
\ gets the number of microseconds since some epoch, as 2 words
\ on the stack, used to initialize the RNG seed.
variable rand-seed   utime drop rand-seed !
: get-rand ( -- n )
    rand-seed @ 1103515245 * 12345 + dup rand-seed ! ;


: n-get ( n -- n ) \ get word at location n from array
    cells pvec + @ ;
: n-set ( n v -- ) \ set word at location n in array to v
    swap cells pvec + ! ;

\ create a randomly addressible array of the c-addrs by
\ jumping through the packed vector
: init-pvec ( -- )
    packed-messages
    24 0 do i over n-set dup c@ + 1+ aligned loop
    pvec pnext !
    drop ; 

: dump-pvec \ for debugging
    cr 24 0 do i . i n-get count type cr loop ;

\ these 2 words are for randomly shuffling the array
: exch ( n1 n2 -- ) \ swap locations n1 and n2 in array
    2dup n-get >r n-get n-set r> n-set ;
: shuffle ( -- )
    24 0 do   get-rand 24 mod   i exch loop
    pvec pnext ! ;
    
: next-msg ( -- addr u ) \ get next message from the array
    pnext @ dup 1 cells + pnext ! @ count ;

: tr ( -- ) \ start a row
    ."       <tr>" cr ;
: /tr ( -- ) \ end a row
    ."       </tr>" cr ;
: td/ ( addr u -- )
    ."         <td>" type ." </td>" cr ;    

\ print first part of webpage
: p-header  ( -- )
     cr
     ." <HTML>" cr
     ."   <BODY>" cr
     ."     <TABLE border=1 height=500 width=500>" cr
     ."       <TR style='color:red;'>" cr
     ."         <TH width='20%'>B</TH>" cr
     ."         <TH width='20%'>I</TH>" cr
     ."         <TH width='20%'>N</TH>" cr
     ."         <TH width='20%'>G</TH>" cr
     ."         <TH width='20%'>O</TH></TR>" cr ;

\ print last part of webpage
: p-footer  ( -- )
     cr ."     </TABLE>"
     cr ."   </BODY>"
     cr ."  </HTML>"
     cr ;

: dprint ( -- ) \ get next message and print it
    next-msg td/ ;

: x-row ( -- ) \ print regular row
    tr dprint dprint dprint dprint dprint  /tr ;

: centerprint s" Free Square" td/ ;
: center-row ( -- ) \ print center row
    tr dprint dprint centerprint dprint dprint /tr ;

: make-card ( -- )
    shuffle 
    p-header
    x-row x-row center-row x-row x-row
    p-footer ;

: .cards ( n -- ) \ print n cards
    init-pvec  
    0 do make-card loop ;

1 .cards
bye

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


#9452

FromHugh Aguilar <hughaguilar96@yahoo.com>
Date2012-02-07 17:59 -0800
Message-ID<c66aca6d-2af5-4de4-8937-9c70467407c7@i18g2000yqf.googlegroups.com>
In reply to#9371
On Feb 4, 10:15 pm, Paul Rubin <no.em...@nospam.invalid> wrote:
> Steve Graham <jsgraha...@yahoo.com> writes:
> > Here is the finished (for now) program which prints out 1 or more
> > Valentine Bingo Cards.  I'd be interested in any comments on style,
> > etc.
>
> I'm no Forth wizard either, but generally code in any language should
> follow the DRY (Don't Repeat Yourself) principle.  Seeing the same set
> of strings in two places in the program is a "code smell".  I also
> felt that the weird packed c-addr format and the linear jumping
> through it on each output square was a bit clumsy, though it's an
> artifact of how ," works.  ," is present in gforth by the way, but
> undocumented, so I had to spend a while figuring out what it did.
>
> As an exercise for myself I wrote my own version, partly adapted
> from yours.  This works in gforth 0.7.  Gforth doesn't have
> the "choose" function or any other built-in random number generator
> as far as I can tell, so I had to write a simple one.  I used
> gforth's "utime" function (current time in microseconds) to
> seed it -- I don't know if VFX has that, but there is probably
> something similar.
>
> ================================================================
>
> create packed-messages
>      ," Be Mine"
>      ," Love"
>      ," It's Love"
>      ," All Mine"
>      ," Kiss Me"
>      ," You & Me"
>      ," Awesome"
>      ," My Baby"
>      ," Love Me"
>      ," All Star"
>      ," My Way"
>      ," Love You"
>      ," For You"
>      ," Cool"
>      ," I Hope"
>      ," Love Life"
>      ," Angel"
>      ," Sweet Talk"
>      ," True Love"
>      ," Be Good"
>      ," How Nice"
>      ," Let's Kiss"
>      ," #1 Fan"
>      ," Be True"
>      ," Love Her"
>      0 ,
>
> create pvec 24 cells allot \ array of c-addrs that point to messages
> variable pnext             \ pointer to next slot in pvec
>
> \ simple random number generator.  utime is a gforth word that
> \ gets the number of microseconds since some epoch, as 2 words
> \ on the stack, used to initialize the RNG seed.
> variable rand-seed   utime drop rand-seed !
> : get-rand ( -- n )
>     rand-seed @ 1103515245 * 12345 + dup rand-seed ! ;
>
> : n-get ( n -- n ) \ get word at location n from array
>     cells pvec + @ ;
> : n-set ( n v -- ) \ set word at location n in array to v
>     swap cells pvec + ! ;
>
> \ create a randomly addressible array of the c-addrs by
> \ jumping through the packed vector
> : init-pvec ( -- )
>     packed-messages
>     24 0 do i over n-set dup c@ + 1+ aligned loop
>     pvec pnext !
>     drop ;
>
> : dump-pvec \ for debugging
>     cr 24 0 do i . i n-get count type cr loop ;
>
> \ these 2 words are for randomly shuffling the array
> : exch ( n1 n2 -- ) \ swap locations n1 and n2 in array
>     2dup n-get >r n-get n-set r> n-set ;
> : shuffle ( -- )
>     24 0 do   get-rand 24 mod   i exch loop
>     pvec pnext ! ;
>
> : next-msg ( -- addr u ) \ get next message from the array
>     pnext @ dup 1 cells + pnext ! @ count ;
>
> : tr ( -- ) \ start a row
>     ."       <tr>" cr ;
> : /tr ( -- ) \ end a row
>     ."       </tr>" cr ;
> : td/ ( addr u -- )
>     ."         <td>" type ." </td>" cr ;
>
> \ print first part of webpage
> : p-header  ( -- )
>      cr
>      ." <HTML>" cr
>      ."   <BODY>" cr
>      ."     <TABLE border=1 height=500 width=500>" cr
>      ."       <TR style='color:red;'>" cr
>      ."         <TH width='20%'>B</TH>" cr
>      ."         <TH width='20%'>I</TH>" cr
>      ."         <TH width='20%'>N</TH>" cr
>      ."         <TH width='20%'>G</TH>" cr
>      ."         <TH width='20%'>O</TH></TR>" cr ;
>
> \ print last part of webpage
> : p-footer  ( -- )
>      cr ."     </TABLE>"
>      cr ."   </BODY>"
>      cr ."  </HTML>"
>      cr ;
>
> : dprint ( -- ) \ get next message and print it
>     next-msg td/ ;
>
> : x-row ( -- ) \ print regular row
>     tr dprint dprint dprint dprint dprint  /tr ;
>
> : centerprint s" Free Square" td/ ;
> : center-row ( -- ) \ print center row
>     tr dprint dprint centerprint dprint dprint /tr ;
>
> : make-card ( -- )
>     shuffle
>     p-header
>     x-row x-row center-row x-row x-row
>     p-footer ;
>
> : .cards ( n -- ) \ print n cards
>     init-pvec
>     0 do make-card loop ;
>
> 1 .cards
> bye

You do make a good point that Steve's packed counted-string array was
clumsy.

Your Valentine program is not robust though, because it has the array
size (25) hard-coded into the program (and the phrases also hard-
coded). If you had used lists, your program would have been more
robust in that the number of phrases could be easily changed (just
edit the PHRASES.TXT file) without having to modify or recompile the
program itself. This would have actually improved your Valentine
program significantly. If you are restricted to 25 phrases and your
cards have 24 squares (not counting the middle square), your bingo
games are going to last about 5 minutes because every player will mark
a square for every phrase that is called out --- you really need more
phrases to make the game at all interesting (at least as interesting
as bingo can be). If every card has every phrase on it, then there are
going to be cases in which multiple players call out bingo
simultaneously. Who will get the prize? You could resolve this
conflict by having the children fight each other with their fists, and
the last one standing gets the valentine. On the other hand, if you
had more phrases as I recommended, the conflict would be less likely
to arise in the first place. It is also possible to write the program
in such a way that the conflict is guaranteed to never occur.

For the most part, I aim for robustness first, and don't worry about
speed too much. In general, lists are more robust than arrays in that
you can do more with them (like dynamically resize) --- I pretty much
use lists for everything, unless there is some compelling reason to
use a different data-structure --- that is why my novice package has
so much support for lists. With modern computers, speed is not
generally an issue --- my slide-rule program has several lists of over
15000 elements, and it is pretty fast --- now that I have LLRB trees,
I could rewrite the program to use them (the data has to be kept
sorted, so trees are a good choice), but I doubt that there would be
much if any speed boost.

Also, you really ought to stick with ANS-Forth. What is the point of
having a standard if even simple programs such as this are compiler-
specific?

If you want to shuffle an array (which is theoretically more
efficient), you are still better off to read the phrases into a list
(with READ-SEQ) so that your program doesn't have to know ahead of
time how many phrases there are, and then convert the list into an
array (with LIST>ARRAY). Use the novice package --- it will make your
programs a lot shorter and simpler. This Valentine application is very
easy, and yet your program is quite long and difficult to follow ---
imagine what kind of complexity explosion you are going to have if you
use this same style in a bigger program. You once described my slide-
rule program as being a lot of tedious work that most programmers
would not have bothered with. Actually, if you had written it the same
way that you wrote this program, you would still be debugging it
months later --- my novice package really does simplify big programs a
lot.

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


#9463

FromSteve Graham <jsgrahamus@yahoo.com>
Date2012-02-08 07:53 -0700
Message-ID<jgu29k$rgd$1@speranza.aioe.org>
In reply to#9371
Paul Rubin wrote:
> Steve Graham<jsgrahamus@yahoo.com>  writes:
>> Here is the finished (for now) program which prints out 1 or more
>> Valentine Bingo Cards.  I'd be interested in any comments on style,
>> etc.
>
> I'm no Forth wizard either, but generally code in any language should
> follow the DRY (Don't Repeat Yourself) principle.  Seeing the same set
> of strings in two places in the program is a "code smell".  I also
> felt that the weird packed c-addr format and the linear jumping
> through it on each output square was a bit clumsy, though it's an
> artifact of how ," works.  ," is present in gforth by the way, but
> undocumented, so I had to spend a while figuring out what it did.
>
> As an exercise for myself I wrote my own version, partly adapted
> from yours.  This works in gforth 0.7.  Gforth doesn't have
> the "choose" function or any other built-in random number generator
> as far as I can tell, so I had to write a simple one.  I used
> gforth's "utime" function (current time in microseconds) to
> seed it -- I don't know if VFX has that, but there is probably
> something similar.
>
> ================================================================
>
> create packed-messages
>       ," Be Mine"
>       ," Love"
>       ," It's Love"
>       ," All Mine"
>       ," Kiss Me"
>       ," You&  Me"
>       ," Awesome"
>       ," My Baby"
>       ," Love Me"
>       ," All Star"
>       ," My Way"
>       ," Love You"
>       ," For You"
>       ," Cool"
>       ," I Hope"
>       ," Love Life"
>       ," Angel"
>       ," Sweet Talk"
>       ," True Love"
>       ," Be Good"
>       ," How Nice"
>       ," Let's Kiss"
>       ," #1 Fan"
>       ," Be True"
>       ," Love Her"
>       0 ,
>
> create pvec 24 cells allot \ array of c-addrs that point to messages
> variable pnext             \ pointer to next slot in pvec
>
> \ simple random number generator.  utime is a gforth word that
> \ gets the number of microseconds since some epoch, as 2 words
> \ on the stack, used to initialize the RNG seed.
> variable rand-seed   utime drop rand-seed !
> : get-rand ( -- n )
>      rand-seed @ 1103515245 * 12345 + dup rand-seed ! ;
>
>
> : n-get ( n -- n ) \ get word at location n from array
>      cells pvec + @ ;
> : n-set ( n v -- ) \ set word at location n in array to v
>      swap cells pvec + ! ;
>
> \ create a randomly addressible array of the c-addrs by
> \ jumping through the packed vector
> : init-pvec ( -- )
>      packed-messages
>      24 0 do i over n-set dup c@ + 1+ aligned loop
>      pvec pnext !
>      drop ;
>
> : dump-pvec \ for debugging
>      cr 24 0 do i . i n-get count type cr loop ;
>
> \ these 2 words are for randomly shuffling the array
> : exch ( n1 n2 -- ) \ swap locations n1 and n2 in array
>      2dup n-get>r n-get n-set r>  n-set ;
> : shuffle ( -- )
>      24 0 do   get-rand 24 mod   i exch loop
>      pvec pnext ! ;
>
> : next-msg ( -- addr u ) \ get next message from the array
>      pnext @ dup 1 cells + pnext ! @ count ;
>
> : tr ( -- ) \ start a row
>      ."<tr>" cr ;
> : /tr ( -- ) \ end a row
>      ."</tr>" cr ;
> : td/ ( addr u -- )
>      ."<td>" type ."</td>" cr ;
>
> \ print first part of webpage
> : p-header  ( -- )
>       cr
>       ."<HTML>" cr
>       ."<BODY>" cr
>       ."<TABLE border=1 height=500 width=500>" cr
>       ."<TR style='color:red;'>" cr
>       ."<TH width='20%'>B</TH>" cr
>       ."<TH width='20%'>I</TH>" cr
>       ."<TH width='20%'>N</TH>" cr
>       ."<TH width='20%'>G</TH>" cr
>       ."<TH width='20%'>O</TH></TR>" cr ;
>
> \ print last part of webpage
> : p-footer  ( -- )
>       cr ."</TABLE>"
>       cr ."</BODY>"
>       cr ."</HTML>"
>       cr ;
>
> : dprint ( -- ) \ get next message and print it
>      next-msg td/ ;
>
> : x-row ( -- ) \ print regular row
>      tr dprint dprint dprint dprint dprint  /tr ;
>
> : centerprint s" Free Square" td/ ;
> : center-row ( -- ) \ print center row
>      tr dprint dprint centerprint dprint dprint /tr ;
>
> : make-card ( -- )
>      shuffle
>      p-header
>      x-row x-row center-row x-row x-row
>      p-footer ;
>
> : .cards ( n -- ) \ print n cards
>      init-pvec
>      0 do make-card loop ;
>
> 1 .cards
> bye
>

Paul,

    You said:

Seeing the same set of strings in two places in the program is a "code 
smell".

To which section of my code are you referring?

I could have padded each phrase with spaces, making them the same length 
and been able to calculate the address of the nth space.  Better on 
time, worse on space, perhaps easier to code the calculation, adding 
code to erase the trailing spaces (-spaces ?)

VFX Forth includes CHOOSE for generating a random number.  Not sure why 
the ANSI standard does not.

I like the way you made words for td and tr.  Perhaps that is what you 
meant by the smell test.

Thanks, Steve

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


#9470

FromPaul Rubin <no.email@nospam.invalid>
Date2012-02-08 10:59 -0800
Message-ID<7x8vkdqhhn.fsf@ruckus.brouhaha.com>
In reply to#9463
Steve Graham <jsgrahamus@yahoo.com> writes:
> Seeing the same set of strings in two places in the program is a "code
> smell".
>
> To which section of my code are you referring?

Whoops, when I first looked at your post, I saw all the phrases
repeated, but didn't notice that the second occurrence was the output of
the program.  I thought it was some kind of HTML template or something.
I didn't figure it out til after looking more closely while coding my
own version, and at that point I forgot to edit that part of the post I
was writing.  Sorry.

The code I posted has its own problems, of course.  It occurred to me
afterwards that it might have been nicer to write a parsing word that
copied a string's caddr to the pvec array instead of making those
contiguous packed strings.  So the message list would look something
like:
   <" Be Mine>  <" Love>  <" It's Love> 
etc. and each of those would allot some space and copy the parsed
string to it.  But those parsing words are themselves pretty messy
to write.

> I could have padded each phrase with spaces, making them the same
> length and been able to calculate the address of the nth space.

Nah, the computer should do that, not a person.

> VFX Forth includes CHOOSE for generating a random number.  Not sure
> why the ANSI standard does not.

Yeah, I coded a simple RNG, but my shuffling routine is slightly
mathematically wrong (doesn't generate all permutations with equal
probability).  I didn't carefully check yours.

> I like the way you made words for td and tr.  Perhaps that is what you
> meant by the smell test.

I didn't have that in mind but it's a slight issue.

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


#9380

Fromcrc <charles.childers@gmail.com>
Date2012-02-03 11:35 -0800
Message-ID<1699fbb9-eb55-4dff-ab74-538e437028f7@db5g2000vbb.googlegroups.com>
In reply to#9243
This seemed interesting enough that I was curious as to how it'd work
in my non-standard dialect of Forth.

needs array'

[ "Be Mine"
  "Love"
  "It's Love"
  "All Mine"
  "Kiss Me"
  "You & Me"
  "Awesome"
  "My Baby"
  "Love Me"
  "All Star"
  "My Way"
  "Love You"
  "For You"
  "Cool"
  "I Hope"
  "Love Life"
  "Angel"
  "Sweet Talk"
  "True Love"
  "Be Good"
  "How Nice"
  "Let's Kiss"
  "#1 Fan"
  "Be True"
  "Love Her" ] ^array'fromQuote constant WORDS

WORDS ^array'length constant #WORDS

create CARD
  #WORDS dup , allot

: nth  ( na-$ )   1+ + @ ;
: rnd  ( -n )     random #WORDS mod ;

: obtain  ( -$ )
  0 [ drop rnd WORDS nth dup CARD ^array'stringIn? ] while ;

: populate  ( - )
  CARD 1+ #WORDS [ obtain swap !+ ] times drop "Free Square" CARD 13
+ ! ;


( This should probably be split into smaller functions... )
: card  ( - )
  populate CARD 1+
  5 [ "<tr align='center'>" puts 5 [ @+ "<td>%s</td>" puts cr ] times
"</td>" puts ] times cr ;

( HTML boilerplate )
: header  ( - )
  "\n<html>\n" puts
  "<body>\n" puts
  "<table border=1 height=500 width=500>\n" puts
  "<tr style='color: red'>\n" puts
  "<th width='20\%'>B</th>\n" puts
  "<th width='20\%'>I</th>\n" puts
  "<th width='20\%'>N</th>\n" puts
  "<th width='20\%'>G</th>\n" puts
  "<th width='20\%'>O</th>\n" puts
  "</tr>\n" puts ;

: footer  ( - )
  "</table>\n" puts
  "</body>\n" puts
  "</html>\n" puts ;

: bingo  ( - )
  header card footer ;

( Since it generates HTML, we may as well make it a trivial web app )
( Running at http://rx-core.org/dev/bingo )

needs casket'
with casket'
: /bingo  ( - )
  Content-type: text/html
  bingo ;

[ ( -$ ) "/home/crc/apps/bingo/" ] is casket:root
[ ( -$ ) "http://rx-core.org/dev/bingo" ] is casket:url
&/bingo is /
&dispatch is boot
save bye

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


#9425

FromSteve Graham <jsgrahamus@yahoo.com>
Date2012-02-07 07:39 -0700
Message-ID<jgrd3o$evp$1@speranza.aioe.org>
In reply to#9243
Hugh/Paul:

Thank you for your interest and comments.  Always there is more than 1 
way to code a solution to problems, including this one.  Below is my 
final solution.  I ended up using some of Stephen Pelc's code, because 
it was better/shorter/more succinct than my own.  Also, I made the final 
output such that there were 2 cards per page.  Earlier I had been 
outputting this from Chrome, but with this final change I used Firefox 
instead.  Finally I included a heart for the free square in the middle: 
  It was for Valentine's Day.


Steve

---

\
\ Valentine Bingo
\

create wordarr
     ," Be Mine"
     ," Love"
     ," It's Love"
     ," All Mine"
     ," Kiss Me"
     ," You & Me"
     ," Awesome"
     ," My Baby"
     ," Love Me"
     ," All Star"
     ," My Way"
     ," Love You"
     ," For You"
     ," Cool"
     ," I Hope"
     ," Love Life"
     ," Angel"
     ," Sweet Talk"
     ," True Love"
     ," Be Good"
     ," How Nice"
     ," Let's Kiss"
     ," #1 Fan"
     ," Be True"
     ," Love Her"
     0 ,

\ number of phrases
25 constant #wordarr

\ which numbers chosen
create chosen-bingo-numbers #wordarr allot

\ chosen numbers in order
create ordered-bingo-numbers #wordarr allot

\ jump from one phrase to the next
: jumper	        \ addr -- addr'
   count + aligned
;

\ get nth phrase
: nth$		\ n base -- addr
   swap 0 ?do  jumper  loop
;

\ print phrases
: .tab		\ base --
   begin
     dup @
    while
     dup count cr type  jumper
   repeat
   drop
;

\ print first part of webpage
: .top-html          \ --
     cr
     cr ." <HTML>"
     cr ."   <BODY>"
     cr ."     <TABLE>"
;

\ print last part of webpage
: .bottom-html          \ --
     cr ."     </TABLE>"
     cr ."     <BR>"
     cr ."   </BODY>"
     cr ."  </HTML>"
     cr
  ;

\ get 24 random non-repeating numbers in order
: get-bingo-numbers  \ --
     #wordarr chosen-bingo-numbers over erase
     ordered-bingo-numbers over erase
     24 0 do
        dup choose
        begin
          dup chosen-bingo-numbers + c@ 0 >
         while
            drop dup choose
        repeat
        chosen-bingo-numbers over + 1 swap c!
        ordered-bingo-numbers i + c!
     loop
     drop
;

\ print nth square's phrase given proper number
: (.square)         \ n --
     ordered-bingo-numbers + c@
     wordarr nth$ count type
;

\ print nth square's phrase given any number
: .square           \ n --
     dup 12 <
     if
       (.square)
     else
       dup 12 =
       if
         drop ." <img src='heart.png' alt='Heart' height='70' width='70'/>"
       else 1- (.square)
       then
     then
;

\ print card
: .card              \ --
     get-bingo-numbers
     cr ."           <TABLE border=1 height=673 width=446>"
     cr ."             <TR height='20%' style='color:red;'>"
     cr ."               <TH style='font-size:200%' width='20%'>B</TH>"
     cr ."               <TH style='font-size:200%' width='20%'>I</TH>"
     cr ."               <TH style='font-size:200%' width='20%'>N</TH>"
     cr ."               <TH style='font-size:200%' width='20%'>G</TH>"
     cr ."               <TH style='font-size:200%' width='20%'>O</TH>"
     cr ."             </TR>"
     5 0 do
       cr ."             <TR align='center' height='16%'>"
       5 0 do
         cr ."               <TD>"
         j 5 * i +
         .square
         ." </TD>"
       loop
       cr ."             </TR>"
   loop
   cr ."           </TABLE>"
;

\ print n bingo cards
: .cards             \ n --
     .top-html
     0 do
       i dup 2 mod 0=
       if
            cr ."       <TR>"
       then
       cr ."         <TD>"
       .card
       cr ."         </TD>"
       2 mod
       if
            cr ."       </TR>"
       then
     loop
     .bottom-html
;

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


#9792

From"WJ" <w_a_x_man@yahoo.com>
Date2012-03-03 05:32 +0000
Message-ID<jisacq0icb@enews1.newsguy.com>
In reply to#9243
Steve Graham wrote:

> 
> create wordarr
>     ," Be Mine"
>     ," Love"
>     ," It's Love"
>     ," All Mine"
>     ," Kiss Me"
>     ," You & Me"
>     ," Awesome"
>     ," My Baby"
>     ," Love Me"
>     ," All Star"
>     ," My Way"
>     ," Love You"
>     ," For You"
>     ," Cool"
>     ," I Hope"
>     ," Love Life"
>     ," Angel"
>     ," Sweet Talk"
>     ," True Love"
>     ," Be Good"
>     ," How Nice"
>     ," Let's Kiss"
>     ," #1 Fan"
>     ," Be True"
>     ," Love Her"
>     0 ,
> 
> \ number of phrases
> 25 constant #wordarr

This is a good example of the extreme primitiveness of ANS
Forth. An array of strings is created, but the language is
too brain-dead to be able to count the number of items in
the array.

So the programmer has to tell ANS Forth how many strings
there are. (After all, we can't expect ANS Forth to be
able to do something as taxing as counting to 25.)  Later,
when the programmer adds to the string list, he has
to change the constant #wordarr.  It's as
bad as or worse than assembly language.

ANS Forth is designed only to be used for very low-level
tasks such as programming an embedded controller that
flushes a toilet.

For the bingo job, it would be wise to use a higher-level
language such as Ruby.


phrases =
 "Be Mine
  Love
  It's Love
  All Mine
  Kiss Me
  You & Me
  Awesome
  My Baby
  Love Me
  All Star
  My Way
  Love You
  For You
  Cool
  I Hope
  Love Life
  Angel
  Sweet Talk
  True Love
  Be Good
  How Nice
  Let's Kiss
  #1 Fan
  Be True
  Love Her".split( /\s*\n\s*/ )
 
sorted = phrases.sort_by{ rand }

our_phrases = sorted[0,12] + ["Free Square"] + sorted[-12,12]

puts "
<HTML>
  <BODY>
    <TABLE border=1 height=500 width=500>
      <TR style='color:red;'>
        <TH width='20%'>B</TH>
        <TH width='20%'>I</TH>
        <TH width='20%'>N</TH>
        <TH width='20%'>G</TH>
        <TH width='20%'>O</TH></TR>"

5.times{
  puts "      <TR align='center'>"
  puts "        <td>" +
    our_phrases.pop(5).join( "</td>\n        <td>" ) + "</td>"
  puts "      </TR>"
}

puts "
    </TABLE>
  </BODY>
</HTML>"


===== output =====

<HTML>
  <BODY>
    <TABLE border=1 height=500 width=500>
      <TR style='color:red;'>
        <TH width='20%'>B</TH>
        <TH width='20%'>I</TH>
        <TH width='20%'>N</TH>
        <TH width='20%'>G</TH>
        <TH width='20%'>O</TH></TR>
      <TR align='center'>
        <td>Be Mine</td>
        <td>Sweet Talk</td>
        <td>True Love</td>
        <td>Love Life</td>
        <td>Love Me</td>
      </TR>
      <TR align='center'>
        <td>Awesome</td>
        <td>#1 Fan</td>
        <td>Love You</td>
        <td>Cool</td>
        <td>Be Good</td>
      </TR>
      <TR align='center'>
        <td>I Hope</td>
        <td>Be True</td>
        <td>Free Square</td>
        <td>My Way</td>
        <td>You & Me</td>
      </TR>
      <TR align='center'>
        <td>My Baby</td>
        <td>For You</td>
        <td>Love Her</td>
        <td>How Nice</td>
        <td>It's Love</td>
      </TR>
      <TR align='center'>
        <td>Angel</td>
        <td>Love</td>
        <td>Let's Kiss</td>
        <td>Kiss Me</td>
        <td>All Star</td>
      </TR>

    </TABLE>
  </BODY>
</HTML>

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


#9796

From"Elizabeth D. Rather" <erather@forth.com>
Date2012-03-02 21:00 -1000
Message-ID<GvadnStEdYoOXMzSnZ2dnUVZ_vOdnZ2d@supernews.com>
In reply to#9792
On 3/2/12 7:32 PM, WJ wrote:
> Steve Graham wrote:
>
>>
>> create wordarr
>>      ," Be Mine"
>>      ," Love"
>>      ," It's Love"
>>      ," All Mine"
>>      ," Kiss Me"
>>      ," You&  Me"
>>      ," Awesome"
>>      ," My Baby"
>>      ," Love Me"
>>      ," All Star"
>>      ," My Way"
>>      ," Love You"
>>      ," For You"
>>      ," Cool"
>>      ," I Hope"
>>      ," Love Life"
>>      ," Angel"
>>      ," Sweet Talk"
>>      ," True Love"
>>      ," Be Good"
>>      ," How Nice"
>>      ," Let's Kiss"
>>      ," #1 Fan"
>>      ," Be True"
>>      ," Love Her"
>>      0 ,
>>
>> \ number of phrases
>> 25 constant #wordarr
>
> This is a good example of the extreme primitiveness of ANS
> Forth. An array of strings is created, but the language is
> too brain-dead to be able to count the number of items in
> the array.

If you need to count, it's trivially easy to do:

Variable #strings
: ,"   ( n -- n+1 )   1+  ," ;  / Counting version

create wordarr  0
	," Be Mine"
         ," Love"
         ," It's Love"
/ etc.

#strings !


> So the programmer has to tell ANS Forth how many strings
> there are. (After all, we can't expect ANS Forth to be
> able to do something as taxing as counting to 25.)  Later,
> when the programmer adds to the string list, he has
> to change the constant #wordarr.  It's as
> bad as or worse than assembly language.

Forth is an application-oriented language. It's incredibly easy to 
modify it to do what your app needs, and doesn't burden you with a lot 
of complexity you don't need. If you tend to do the same sorts of apps 
over and over, you develop your own library of application-specific things.

I have never heard a professional programmer complain about this sort of 
adaptation being hard or burdensome. On the contrary, the professional 
Forthers I worked with for 30 years were vastly more productive than 
their peers using other languages.  It's mostly the newbies who get 
culture-shock.

> ANS Forth is designed only to be used for very low-level
> tasks such as programming an embedded controller that
> flushes a toilet.

Hilarious. If only you knew...

> For the bingo job, it would be wise to use a higher-level
> language such as Ruby.

Sure. In fact, as John Passaniti frequently points out, every language 
has a particular target set of applications for which it is best suited. 
Valentine Bingo isn't really the kind of app that Forth is aimed at, 
though it's a cool example of how to do some stuff. I would agree that 
Forth is mainly aimed at embedded systems. But to assume they're all 
idiot simple is plain ignorance.  Most of the electric power grid in 
North America is managed by Forth, to give just one example.

Cheers,
Elizabeth

-- 
==================================================
Elizabeth D. Rather   (US & Canada)   800-55-FORTH
FORTH Inc.                         +1 310.999.6784
5959 West Century Blvd. Suite 700
Los Angeles, CA 90045
http://www.forth.com

"Forth-based products and Services for real-time
applications since 1973."
==================================================

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


#9797

From"WJ" <w_a_x_man@yahoo.com>
Date2012-03-03 09:21 +0000
Message-ID<jisnqs015k9@enews4.newsguy.com>
In reply to#9792
WJ wrote:

> 5.times{
>   puts "      <TR align='center'>"
>   puts "        <td>" +
>     our_phrases.pop(5).join( "</td>\n        <td>" ) + "</td>"
>   puts "      </TR>"
> }

Better:


5.times{
  puts "      <TR align='center'>"
  puts our_phrases.pop(5).map{|s| "        <td>#{ s }</td>" }
  puts "      </TR>"
}

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


#9798

FromPaul Rubin <no.email@nospam.invalid>
Date2012-03-03 01:26 -0800
Message-ID<7xd38uqbky.fsf@ruckus.brouhaha.com>
In reply to#9797
"WJ" <w_a_x_man@yahoo.com> writes:
> Better:
> 5.times{ ... 

Really, the Ruby newsgroup is that way ------>  comp.lang.ruby
Those who want Ruby know where to find it.

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


#9802

FromJosh Grams <josh@qualdan.com>
Date2012-03-03 12:52 +0000
Message-ID<4f521411$0$5846$882e7ee2@usenet-news.net>
In reply to#9798
Paul Rubin wrote: <7xd38uqbky.fsf@ruckus.brouhaha.com>
> "WJ" <w_a_x_man@yahoo.com> writes:
>> Better:
>> 5.times{ ... 
>
> Really, the Ruby newsgroup is that way ------>  comp.lang.ruby
> Those who want Ruby know where to find it.

Heh.  Good luck with that.  He has been coming around here and doing
this periodically for most of the time that Ruby has existed.  Just
ignore him -- he will get bored shortly and move on if he doesn't get a
rise out of anybody.

--Josh

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


#9819

FromJohn Passaniti <john.passaniti@gmail.com>
Date2012-03-03 14:08 -0800
Message-ID<e4bbbfdc-738c-4df7-9ea0-f5615d41b089@eb6g2000vbb.googlegroups.com>
In reply to#9802
On Mar 3, 7:52 am, Josh Grams <j...@qualdan.com> wrote:
> Heh.  Good luck with that.  He has been coming around here
> and doing this periodically for most of the time that Ruby
> has existed.  Just ignore him -- he will get bored shortly
> and move on if he doesn't get a rise out of anybody.

I think the guy is silly and I don't understand his motivation for
posting here.

But it would be a mistake to ignore him.  Yes, this is a Forth
newsgroup.  But I see nothing wrong with pointing out areas of Forth
that some consider weak and expressing that perspective.  I don't
think there is any danger of Forth turning into Ruby.  But gosh, maybe
some of the folks here who think Forth walks on water might be
intrigued by the brevity and expressiveness of Ruby and other
languages, and think how the experience of other programmers in other
languages might help Forth evolve.

One of the most annoying things about comp.lang.forth to me is that
people here tend to be pretty binary in their thinking.  It's like
there is no middle ground.  Ruby-guy comes in here and the knee-jerk
reaction is to say that Ruby isn't appropriate for all problems, much
less the problems one typically uses Forth for.  Well, duh.  Wouldn't
it be more interesting to not look at other languages (like Ruby) as
some monolithic whole and instead look at specific features it offers
and think how they might be useful in Forth?  Wouldn't it be a great
demonstration of the flexibility of Forth that you could take
essential features in a high-level object-oriented language like Ruby
and not just recreate the functionality, but the brevity and
expressiveness?

I see one other value of Ruby-guy's posts.  Many times when people use
the phrase "other languages" here, they don't really mean that.  Far
more often than not, when the phrase "other languages" is used, it's a
placeholder for C.  And sure, that makes some sense historically, at
least in the embedded systems world.  But a funny thing happened in
the past THIRTY FREAKIN' YEARS.  There is much more than just C out
there.  And in fact, many of the languages that are in common use
today have many of the same capabilities that Forth programmers
value.  It's very easy to point out that C isn't interactive and
extensible.  But Ruby and a bunch of other languages are.  It's very
easy to point out that C has no concept of compilation at run-time.
But plenty of languages these days do.

Over the years, I've gotten increasingly bored with many in the
comp.lang.forth community who think the year is still 1980.  Value the
past, learn from it, but don't live there.

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


#9820

FromPaul Rubin <no.email@nospam.invalid>
Date2012-03-03 14:41 -0800
Message-ID<7x1up9s3xj.fsf@ruckus.brouhaha.com>
In reply to#9819
John Passaniti <john.passaniti@gmail.com> writes:
> more often than not, when the phrase "other languages" is used, it's a
> placeholder for C.  And sure, that makes some sense historically, at
> least in the embedded systems world.  But a funny thing happened in
> the past THIRTY FREAKIN' YEARS.  There is much more than just C out
> there. 

Heh, 30 years ago was the 1980's, the heyday of Lisp, and Lispers were
saying the same things about C back then, that the Ruby guy says about
Forth now.  As far as I can tell, Ruby is (like Python and Javascript,
to be fair) a somewhat lobotomized Lisp with some creature comforts
added.  So I don't think the Ruby guy is really bringing much in
language technology that hasn't been around for longer than Forth.
Chuck has said more than once that Forth was inspired partly by Lisp.

I'd conclude that Forth users either aren't terribly interested in
language technlogy for its own sake (e.g. because their real profession
is hardware engineering or something like that, and Forth does what they
need), or else they're programming under constraints were Lisp or Ruby
wouldn't work (I'd like to see the Ruby guy port Ruby to an 8 bit
micro), or else they're perfectly aware of Ruby's ilk but have their own
reasons for being interested in Forth.

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


#9825

FromJohn Passaniti <john.passaniti@gmail.com>
Date2012-03-03 17:39 -0800
Message-ID<71043369-cc30-41c3-bc6b-f0674e2cabfa@w9g2000vbv.googlegroups.com>
In reply to#9820
On Mar 3, 5:41 pm, Paul Rubin <no.em...@nospam.invalid> wrote:
> Heh, 30 years ago was the 1980's, the heyday of Lisp, and Lispers
> were saying the same things about C back then, that the Ruby guy
> says about Forth now.  As far as I can tell, Ruby is (like Python
> and Javascript, to be fair) a somewhat lobotomized Lisp with some
> creature comforts added.  So I don't think the Ruby guy is really
> bringing much in language technology that hasn't been around for
> longer than Forth. Chuck has said more than once that Forth was
> inspired partly by Lisp.

Ruby is far more like Smalltalk than it is like Lisp.  Python has some
limited functional aspects, but that never got top billing.  Both are
firmly in the camp of object-oriented dynamically typed languages.
Their functional aspects aren't significant, either to their history
or to their predominate use.

Forth may have been "inspired" by Lisp, but there is very little left
of that in it.  Lists were replaced with arrays, recursion was
replaced with iteration, treating programs as data was only ever
possible with carnal knowledge, and homoiconicity is completely
ignored.

> I'd conclude that Forth users either aren't terribly interested
> in language technlogy for its own sake (e.g. because their real
> profession is hardware engineering or something like that, and
> Forth does what they need), or else they're programming under
> constraints were Lisp or Ruby wouldn't work (I'd like to see
> the Ruby guy port Ruby to an 8 bit micro), or else they're
> perfectly aware of Ruby's ilk but have their own reasons for
> being interested in Forth.

I'm not suggesting that people should be interested in programming
languages technology "for its own sake."  Instead, I would hope people
would show a bit of intellectual curiosity when viewing other
languages and their features.  The mere existence of other programming
languages isn't significant, but the features they provide and the
differences in the way they direct programmers to solutions can be
quite valuable.

I'm firmly in the embedded systems camp.  It's what I'm paid to do,
and it's what I'm best at.  But that doesn't stop me from seeing
what's up in other fields and seeing how I can apply what others are
working on.  For example, I enjoy watching the presentations over on
infoq.com, even though I'm not writing "enterprise" applications.
Why?  I'm not writing financial trade applications in Java, but I have
found some of the techniques used to maintain high-throughput have
direct application to the network processing in my embedded systems.
I have yet to use a "no-SQL" distributed document-centered database
for anything, but the discussions about some of the underlying
technologies introduced me to vector clocks, which have direct
application to versioning of data in our distributed systems.

Often some of the technologies introduced don't have any direct
application.  But given that these days, an "embedded system" might be
a $6 ARM SoC running Linux with loads of resources, it starts to bring
into question past assumptions.  For example, in an upcoming system,
we need to create a desktop user interface.  We're going to target web
browsers because they are ubiquitous.  And in doing that, we're
reviewing the wealth of both server-side and client-side languages,
tools, and libraries available.  Thankfully, we don't have to start
from scratch.  The enterprise computing community has been there for
some time, and they've already been through various fads and silver
bullets.  Paying attention to what they've experienced isn't
technology for technology's sake.  It's building off their experience
and not making the same mistakes they've made.

The lines between "embedded" and other problem domains is growing
increasingly fuzzy.  I think that's a good thing.

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


#9827

FromPaul Rubin <no.email@nospam.invalid>
Date2012-03-03 19:18 -0800
Message-ID<7xfwdpvysv.fsf@ruckus.brouhaha.com>
In reply to#9825
John Passaniti <john.passaniti@gmail.com> writes:
> Ruby is far more like Smalltalk than it is like Lisp.  Python has some
> limited functional aspects, but that never got top billing.  Both are
> firmly in the camp of object-oriented dynamically typed languages.

Lisp also is OO (as in CLOS and its predecessors).

> Their functional aspects aren't significant, either to their history
> or to their predominate use.

I don't know about Ruby.  With Python, it's a matter of programming
style and the predominance of "functional" aspects depends on who's
writing the code.

> Forth may have been "inspired" by Lisp, but there is very little left
> of that in it. 

Sure.  It just shows that Lisp wasn't some weird alien development that
came along later.

> The lines between "embedded" and other problem domains is growing
> increasingly fuzzy.  I think that's a good thing.

Yes, though the examples you mentioned don't involve much direct
hardware control.

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


#9863

Fromvandys@vsta.org
Date2012-03-05 17:27 +0000
Message-ID<9rkbcmFfnrU1@mid.individual.net>
In reply to#9827
Paul Rubin <no.email@nospam.invalid> wrote:
> Lisp also is OO (as in CLOS and its predecessors).

That's like saying C is Forth, because I can implement a stack and word list
in C.  Bolting on something to a language is rarely compelling, although it
might find favor with those who are already committed to that language.  So
Python bolts on lambda, which is no selling point to the Lisp crowd (although
it's heavily used by Python coders).  And I've never heard of a Smalltalk'er
who jumped to Lisp because of CLOS.

-- 
Andy Valencia
Home page: http://www.vsta.org/andy/
To contact me: http://www.vsta.org/contact/andy.html

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


#9828

From"Elizabeth D. Rather" <erather@forth.com>
Date2012-03-03 17:51 -1000
Message-ID<wZOdnZpPn7ZNe8_SnZ2dnUVZ_oCdnZ2d@supernews.com>
In reply to#9819
On 3/3/12 12:08 PM, John Passaniti wrote:
> On Mar 3, 7:52 am, Josh Grams<j...@qualdan.com>  wrote:
>> Heh.  Good luck with that.  He has been coming around here
>> and doing this periodically for most of the time that Ruby
>> has existed.  Just ignore him -- he will get bored shortly
>> and move on if he doesn't get a rise out of anybody.
>
> I think the guy is silly and I don't understand his motivation for
> posting here.
>
> But it would be a mistake to ignore him.  Yes, this is a Forth
> newsgroup.  But I see nothing wrong with pointing out areas of Forth
> that some consider weak and expressing that perspective.

Of course, in principle that's quite true, but this is more of a "drive 
by egg throwing", not someone who's taken some time to look at Forth and 
offer a considered opinion. I think we're pretty good at discussing 
thoughtful criticisms.

...
>
> One of the most annoying things about comp.lang.forth to me is that
> people here tend to be pretty binary in their thinking.  It's like
> there is no middle ground.  Ruby-guy comes in here and the knee-jerk
> reaction is to say that Ruby isn't appropriate for all problems, much
> less the problems one typically uses Forth for.  Well, duh.  Wouldn't
> it be more interesting to not look at other languages (like Ruby) as
> some monolithic whole and instead look at specific features it offers
> and think how they might be useful in Forth?  Wouldn't it be a great
> demonstration of the flexibility of Forth that you could take
> essential features in a high-level object-oriented language like Ruby
> and not just recreate the functionality, but the brevity and
> expressiveness?

In fact, I didn't hear a knee-jerk response except to recognize that 
this guy has been here with almost the same word-for-word troll, to wit, 
"ANS Forth is designed only to be used for very low-level tasks such as 
programming an embedded controller that flushes a toilet."  Had he 
*asked* how one might count strings in that example, he'd have gotten a 
lot more respect. As it is, I tried to answer the question he didn't 
ask, in case someone else might be interested.

> I see one other value of Ruby-guy's posts.  Many times when people use
> the phrase "other languages" here, they don't really mean that.  Far
> more often than not, when the phrase "other languages" is used, it's a
> placeholder for C.  And sure, that makes some sense historically, at
> least in the embedded systems world.  But a funny thing happened in
> the past THIRTY FREAKIN' YEARS.  There is much more than just C out
> there.  And in fact, many of the languages that are in common use
> today have many of the same capabilities that Forth programmers
> value.  It's very easy to point out that C isn't interactive and
> extensible.  But Ruby and a bunch of other languages are.  It's very
> easy to point out that C has no concept of compilation at run-time.
> But plenty of languages these days do.
>
> Over the years, I've gotten increasingly bored with many in the
> comp.lang.forth community who think the year is still 1980.  Value the
> past, learn from it, but don't live there.

I really don't think most of us are that ignorant. Those of us who are 
happy using Forth for the work we do may not make the investment in 
learning some of the newer languages, particularly those designed for 
other application domains, but I'm pretty sure most folks here know they 
exist.

Cheers,
Elizabeth

-- 
==================================================
Elizabeth D. Rather   (US & Canada)   800-55-FORTH
FORTH Inc.                         +1 310.999.6784
5959 West Century Blvd. Suite 700
Los Angeles, CA 90045
http://www.forth.com

"Forth-based products and Services for real-time
applications since 1973."
==================================================

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


#9833

FromJosh Grams <josh@qualdan.com>
Date2012-03-04 12:29 +0000
Message-ID<4f536015$0$29766$882e7ee2@usenet-news.net>
In reply to#9819
John Passaniti wrote:
> On Mar 3, 7:52 am, Josh Grams <j...@qualdan.com> wrote:
>> Heh.  Good luck with that.  He has been coming around here
>> and doing this periodically for most of the time that Ruby
>> has existed.  Just ignore him -- he will get bored shortly
>> and move on if he doesn't get a rise out of anybody.
>
> I think the guy is silly and I don't understand his motivation for
> posting here.
>
> But it would be a mistake to ignore him.  Yes, this is a Forth
> newsgroup.  But I see nothing wrong with pointing out areas of Forth
> that some consider weak and expressing that perspective.

Yeah, but I think the history shows pretty clearly that he's not
interested in a real dialogue either.  He just comes by and periodically
and posts Ruby code with an inflammatory paragraph or two.

> One of the most annoying things about comp.lang.forth to me is that
> people here tend to be pretty binary in their thinking.  It's like
> there is no middle ground.  Ruby-guy comes in here and the knee-jerk
> reaction is to say that Ruby isn't appropriate for all problems, much
> less the problems one typically uses Forth for.

Yes, and I'm not endorsing that.  I'm familiar with Ruby and have used
it for several small projects.  My only issue is that it seems to be
very slow. :(  Every time I try to use it on any volume of data it is
slower than I feel like waiting for and I wind up going back to Perl.  I
suppose I should try it again -- it has been a year or two and maybe
they have made improvements.  Python was horribly slow for *years* and
they eventually fixed that...

At any rate, I don't have a problem with Ruby-guy posting here; I just
think it's probably a waste of time to expect him to engage in any
meaningful debate.

--Josh

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


Page 1 of 2  [1] 2  Next page →

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


csiph-web