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


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

Looking for some help with this gforth program. Thanks!

Started bymurphy.darin@gmail.com
First post2016-05-11 13:54 -0700
Last post2016-05-16 05:35 +0000
Articles 20 on this page of 91 — 18 participants

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


Contents

  Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-11 13:54 -0700
    Re: Looking for some help with this gforth program. Thanks! all2001@spambog.com (Wolfgang Allinger) - 2016-05-11 17:59 -0300
      Re: Looking for some help with this gforth program. Thanks! hughaguilar96@gmail.com - 2016-05-11 19:16 -0700
        Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-11 19:40 -0700
          Re: Looking for some help with this gforth program. Thanks! Paul Rubin <no.email@nospam.invalid> - 2016-05-11 23:22 -0700
            Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-12 00:01 -0700
              Re: Looking for some help with this gforth program. Thanks! hughaguilar96@gmail.com - 2016-05-12 00:08 -0700
                Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-12 12:09 -0700
              Re: Looking for some help with this gforth program. Thanks! rickman <gnuarm@gmail.com> - 2016-05-12 20:48 -0400
                Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-12 18:04 -0700
                  Re: Looking for some help with this gforth program. Thanks! rickman <gnuarm@gmail.com> - 2016-05-12 21:21 -0400
                  Re: Looking for some help with this gforth program. Thanks! Cecil Bayona <cbayona@cbayona.com> - 2016-05-12 20:27 -0500
                    Re: Looking for some help with this gforth program. Thanks! Paul Rubin <no.email@nospam.invalid> - 2016-05-12 18:46 -0700
                      Re: Looking for some help with this gforth program. Thanks! Cecil Bayona <cbayona@cbayona.com> - 2016-05-12 23:28 -0500
                        Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-13 00:52 -0700
                          Re: Looking for some help with this gforth program. Thanks! Pablo Hugo Reda <pabloreda@gmail.com> - 2016-05-13 04:07 -0700
                          Re: Looking for some help with this gforth program. Thanks! rickman <gnuarm@gmail.com> - 2016-05-14 00:42 -0400
                            Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-14 00:05 -0700
                              Re: Looking for some help with this gforth program. Thanks! rickman <gnuarm@gmail.com> - 2016-05-15 00:10 -0400
                                Re: Looking for some help with this gforth program. Thanks! anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-15 10:34 +0000
                                  Re: Looking for some help with this gforth program. Thanks! rickman <gnuarm@gmail.com> - 2016-05-15 09:43 -0400
                                    Re: Looking for some help with this gforth program. Thanks! anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-16 12:21 +0000
                                      Re: Looking for some help with this gforth program. Thanks! hughaguilar96@gmail.com - 2016-05-16 07:38 -0700
                                        Re: Looking for some help with this gforth program. Thanks! anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-16 14:56 +0000
                                      Re: Looking for some help with this gforth program. Thanks! rickman <gnuarm@gmail.com> - 2016-05-16 12:07 -0400
                                      Re: Looking for some help with this gforth program. Thanks! Paul Rubin <no.email@nospam.invalid> - 2016-05-16 09:18 -0700
                                      Re: Looking for some help with this gforth program. Thanks! Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-05-16 13:19 -0500
                                        Re: Looking for some help with this gforth program. Thanks! anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-17 12:39 +0000
                                          Re: Looking for some help with this gforth program. Thanks! Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-05-17 10:34 -0500
                                            Re: Looking for some help with this gforth program. Thanks! anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-17 15:54 +0000
                                              Re: Looking for some help with this gforth program. Thanks! mhx@iae.nl - 2016-05-17 12:44 -0700
                                  Re: Looking for some help with this gforth program. Thanks! hughaguilar96@gmail.com - 2016-05-15 11:03 -0700
                                    Re: Looking for some help with this gforth program. Thanks! rickman <gnuarm@gmail.com> - 2016-05-15 21:56 -0400
                                      Re: Looking for some help with this gforth program. Thanks! Paul Rubin <no.email@nospam.invalid> - 2016-05-15 19:02 -0700
                                        Re: Looking for some help with this gforth program. Thanks! hughaguilar96@gmail.com - 2016-05-15 20:03 -0700
                                        Re: Looking for some help with this gforth program. Thanks! rickman <gnuarm@gmail.com> - 2016-05-16 02:13 -0400
                                          Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-16 00:37 -0700
                                            Re: Looking for some help with this gforth program. Thanks! anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-16 13:41 +0000
                                              Re: Looking for some help with this gforth program. Thanks! Bernd Paysan <bernd.paysan@gmx.de> - 2016-05-16 21:42 +0000
                                                Re: Looking for some help with this gforth program. Thanks! hughaguilar96@gmail.com - 2016-05-16 16:23 -0700
                                                Re: Looking for some help with this gforth program. Thanks! Paul Rubin <no.email@nospam.invalid> - 2016-05-16 16:41 -0700
                                                  Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-16 20:32 -0700
                                                  Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-16 20:47 -0700
                                                  Re: Looking for some help with this gforth program. Thanks! anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-17 06:32 +0000
                                                    Re: Looking for some help with this gforth program. Thanks! Paul Rubin <no.email@nospam.invalid> - 2016-05-17 07:56 -0700
                                                  Re: Looking for some help with this gforth program. Thanks! Bernd Paysan <bernd.paysan@gmx.de> - 2016-05-17 23:05 +0000
                                                    Re: Looking for some help with this gforth program. Thanks! Paul Rubin <no.email@nospam.invalid> - 2016-05-17 21:16 -0700
                                                      Re: Looking for some help with this gforth program. Thanks! Bernd Paysan <bernd.paysan@gmx.de> - 2016-06-04 22:44 +0000
                                                Re: Looking for some help with this gforth program. Thanks! anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-17 13:42 +0000
                                                  Re: Looking for some help with this gforth program. Thanks! Bernd Paysan <bernd.paysan@gmx.de> - 2016-05-17 22:31 +0000
                                                    Re: Looking for some help with this gforth program. Thanks! anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-18 16:43 +0000
                                        Re: Looking for some help with this gforth program. Thanks! Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-05-16 10:38 -0500
                                          Re: Looking for some help with this gforth program. Thanks! Paul Rubin <no.email@nospam.invalid> - 2016-05-16 10:10 -0700
                                            Re: Looking for some help with this gforth program. Thanks! Cecil Bayona <cbayona@cbayona.com> - 2016-05-16 12:29 -0500
                                            Re: Looking for some help with this gforth program. Thanks! Cecil Bayona <cbayona@cbayona.com> - 2016-05-16 12:34 -0500
                                            Re: Looking for some help with this gforth program. Thanks! Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-05-16 13:27 -0500
                                              Re: Looking for some help with this gforth program. Thanks! Paul Rubin <no.email@nospam.invalid> - 2016-05-17 16:11 -0700
                                                Re: Looking for some help with this gforth program. Thanks! Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-05-18 04:31 -0500
                                        Re: Looking for some help with this gforth program. Thanks! Albert van der Horst <albert@cherry.spenarnc.xs4all.nl> - 2016-05-16 18:46 +0000
                            Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-14 00:07 -0700
                              Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-14 00:20 -0700
                                Re: Looking for some help with this gforth program. Thanks! Paul Rubin <no.email@nospam.invalid> - 2016-05-14 01:23 -0700
                                  Re: Looking for some help with this gforth program. Thanks! rickman <gnuarm@gmail.com> - 2016-05-15 00:13 -0400
                                    Re: Looking for some help with this gforth program. Thanks! Paul Rubin <no.email@nospam.invalid> - 2016-05-14 21:55 -0700
    Re: Looking for some help with this gforth program. Thanks! Paul Rubin <no.email@nospam.invalid> - 2016-05-11 17:08 -0700
      Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-11 17:40 -0700
        Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-11 18:54 -0700
          Re: Looking for some help with this gforth program. Thanks! Doug Hoffman <glidedog@gmail.com> - 2016-05-13 06:55 -0400
            Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-13 11:07 -0700
            Re: Looking for some help with this gforth program. Thanks! hughaguilar96@gmail.com - 2016-05-13 20:42 -0700
              Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-13 20:57 -0700
              Re: Looking for some help with this gforth program. Thanks! Doug Hoffman <glidedog@gmail.com> - 2016-05-14 05:54 -0400
                Re: Looking for some help with this gforth program. Thanks! hughaguilar96@gmail.com - 2016-05-14 15:20 -0700
                  Re: Looking for some help with this gforth program. Thanks! Doug Hoffman <glidedog@gmail.com> - 2016-05-15 05:45 -0400
                    Re: Looking for some help with this gforth program. Thanks! hughaguilar96@gmail.com - 2016-05-15 11:21 -0700
                      Re: Looking for some help with this gforth program. Thanks! hughaguilar96@gmail.com - 2016-05-15 11:39 -0700
      Re: Looking for some help with this gforth program. Thanks! hughaguilar96@gmail.com - 2016-05-11 20:45 -0700
        Re: Looking for some help with this gforth program. Thanks! hughaguilar96@gmail.com - 2016-05-11 23:05 -0700
          Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-11 23:15 -0700
            Re: Looking for some help with this gforth program. Thanks! rickman <gnuarm@gmail.com> - 2016-05-12 22:34 -0400
        Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-11 23:11 -0700
    Re: Looking for some help with this gforth program. Thanks! november.nihal@gmail.com - 2016-05-11 19:00 -0700
      Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-11 19:14 -0700
    Re: Looking for some help with this gforth program. Thanks! humptydumpty <ouatubi@gmail.com> - 2016-05-12 01:48 -0700
      Re: Looking for some help with this gforth program. Thanks! Doug Hoffman <glidedog@gmail.com> - 2016-05-12 07:43 -0400
        Re: Looking for some help with this gforth program. Thanks! humptydumpty <ouatubi@gmail.com> - 2016-05-12 10:21 -0700
      Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-12 12:11 -0700
    Re: Looking for some help with this gforth program. Thanks! "Ala'a" <amalawi@gmail.com> - 2016-05-12 14:34 -0700
      Re: Looking for some help with this gforth program. Thanks! murphy.darin@gmail.com - 2016-05-12 16:20 -0700
    Re: Looking for some help with this gforth program. Thanks! Marcos Cruz <use_the_contact_page@programandala.net> - 2016-05-14 12:27 +0000
    Re: Looking for some help with this gforth program. Thanks! "WJ" <w_a_x_man@yahoo.com> - 2016-05-16 05:35 +0000

Page 1 of 5  [1] 2 3 4 5  Next page →


#47022 — Looking for some help with this gforth program. Thanks!

Frommurphy.darin@gmail.com
Date2016-05-11 13:54 -0700
SubjectLooking for some help with this gforth program. Thanks!
Message-ID<6548d185-2c31-40a4-bfa9-a3c353e9fa5d@googlegroups.com>
Sorry if this isn't appropriate question on this forum, but I am unable to find one specifically for "gforth" questions, but I am trying to learn forth and gforth is the only free, and actively supported by the developer forth that runs under on my Google Pixel C tablet.  Anyway here's the program:

: penny   ( n -- ) dup 1 > if . ." pennies" else dup 0 > if . ." penny" then then ;
: nickel   ( n -- n ) 5 /mod ?dup 0= if penny else . ." nickel" then ?dup 0 > if ." , " penny then ;
: dime   ( n -- n ) 10 /mod ?dup 0= if nickel else dup 1 > if . ." dimes" else . ." dime" then then ?dup 0 > if ." , " nickel then ;
: quarter ( n -- n ) 25 /mod ?dup 0= if dime else dup 1 > if . ." quarters" else . ." quarter" then then ?dup 0 > if ." , " dime then ;
: dollar ( n -- n ) 100 /mod ?dup 0= if quarter else dup 1 > if . ." dollars" else . ." dollar" then then ?dup 0 > if ." , " quarter then ;
: 5-dollar   ( n -- n ) 500 /mod ?dup 0= if dollar else dup 1 > if . ." fives" else . ." five" then then ?dup 0 > if ." , " dollar then ;
: 10-dollar   ( n -- n ) 1000 /mod ?dup 0= if 5-dollar else dup 1 > if . ." tens" else . ." ten" then then ?dup 0 > if ." , " 5-dollar then ;
: 20-dollar   ( n -- n ) 2000 /mod ?dup 0= if 10-dollar else dup 1 > if . ." twenties" else . ." twenty" then then ?dup 0 > if ." , " 10-dollar then ;
: 50-dollar   ( n -- n ) 5000 /mod ?dup 0= if 20-dollar else dup 1 > if . ." fifties" else . ." fifty" then then ?dup 0 > if ." , " 20-dollar then ;
: 100-dollar  ( n -- n ) 10000 /mod ?dup 0= if 50-dollar else dup 1 > if . ." hundreds" else . ." hundred" then then ?dup 0 > if ." , " 50-dollar then ;

: pennies-exchange   ( n -- ) ?dup 0= if ." ERROR - Must enter a number greater than 0!" else 100-dollar then ;

I've rewritten this program about a dozen times and have removed a elusive 0 that was being left on the stack, but now it sometimes works fine, while other times I get garbage and a "stack underflow" error.  I am also very new to programming in forth period, so I'm sure this program could be factored more efficiently, but I'm learning.  Anyway, if any of you would look at this program, maybee run it in and what I am doing wrong or any other advice on how to improve it, I would be very, very grateful.  I think forth is such an amazing and underrate language and really want to understand and utilitize it for all my programming needs.  Additionally I do understand the basics of programming (i.e., sequential, branching and iterative ), though I'm still very much a newbie in anything else. Thanks in advance for any assistance, opinions, advice given. Take care now.

[toc] | [next] | [standalone]


#47023

Fromall2001@spambog.com (Wolfgang Allinger)
Date2016-05-11 17:59 -0300
Message-ID<Dde4X7AEQoB@allinger-307049.user.uni-berlin>
In reply to#47022
 On 11 May 16 at group /comp/lang/forth in article 6548d185-2c31-40a4-bfa9-a3c353e9fa5d@googlegroups.com
 <murphy.darin@gmail.com>   wrote:

>Sorry if this isn't appropriate question on this forum, but I am
>unable to find one specifically for "gforth" questions, but I am
>trying to learn forth and gforth is the only free, and actively
>supported by the developer forth that runs under on my Google Pixel C
>tablet.  Anyway here's the program:
>
>: penny   ( n -- ) dup 1 > if . ." pennies" else dup 0 > if . ."
>penny" then then ;

>: nickel   ( n -- n ) 5 /mod ?dup 0= if penny else .
>." nickel" then ?dup 0 > if ." , " penny then ; : dime   ( n -- n ) 10
>/mod ?dup 0= if nickel else dup 1 > if . ." dimes" else . ." dime" then
>then ?dup 0 > if ." , " nickel then ; : quarter ( n -- n ) 25 /mod ?dup
>0= if dime else dup 1 > if . ." quarters" else . ." quarter" then then
>?dup 0 > if ." , " dime then ; : dollar ( n -- n ) 100 /mod ?dup 0= if
>quarter else dup 1 > if . ." dollars" else . ." dollar" then then ?dup
>0 > if ." , " quarter then ; : 5-dollar   ( n -- n )
>500 /mod ?dup 0= if dollar else dup 1 > if . ." fives" else . ." five"
>then then ?dup 0 > if ." , " dollar then ; : 10-dollar   ( n -- n )
>1000 /mod ?dup 0= if 5-dollar else dup 1 > if . ." tens" else . ." ten"
>then then ?dup 0 > if ." , " 5-dollar then ; : 20-dollar   ( n --n )
>2000 /mod ?dup 0= if 10-dollar else dup 1 > if . ." twenties" else . ."
>twenty" then then ?dup 0 > if ." , " 10-dollar then ; : 50-dollar ( n
>-- n ) 5000 /mod ?dup 0= if 20-dollar else dup 1 > if . ." fifties"
>else . ." fifty" then then ?dup 0 > if ." , " 20-dollar then ; : 100-
>dollar  ( n -- n ) 10000 /mod ?dup 0= if 50-dollar else dup 1
>> if . ." hundreds" else . ." hundred" then then ?dup 0 > if ." , "
>50-dollar then ;
>
>: pennies-exchange   ( n -- ) ?dup 0= if ." ERROR - Must enter a
>number greater than 0!" else 100-dollar then ;
>
>I've rewritten this program about a dozen times and have removed a
>elusive 0 that was being left on the stack, but now it sometimes works
>fine, while other times I get garbage and a "stack underflow" error.

Test the `penny` interactive, and look for
-1 penny
0 penny
1 penny
2 penny
and check the stack afterwards, with .s


Also the other declarations doesn`t follow your assumed stack comments.
I didn`t check it correctly, it`s your job :)
Check them also interactive.

For a beginner it`s more readable in not to use single line.
Also write stack comments for every line.

: penny ( n -- )
        dup 1 > if
            . ." pennies"
        else
            dup 0> if
                . ." penny"
            then
        then
 ;

You should add the stack comments after each line and hopefully you find
the place, where the stack goes wrong. A debugger in single step will  
also help.

Do this with all your definitions.

Also check for
-1 pennies-exchange
or even
pennies-exchange (yes nothing on stack before!)

Also good practise: write one definition and check interactively, then  
the next one...


Saludos (an alle Vernünftigen, Rest sh. sig)
Wolfgang

-- 
Wolfgang Allinger, anerkannter Trollallergiker :) reply Adresse gesetzt!
Ich diskutiere zukünftig weniger mit Idioten, denn sie ziehen mich auf
ihr Niveau herunter und schlagen mich dort mit ihrer Erfahrung! :p
(lt. alter usenet Weisheit)      iPod, iPhone, iPad, iTunes, iRak, iDiot

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


#47029

Fromhughaguilar96@gmail.com
Date2016-05-11 19:16 -0700
Message-ID<715a06d1-026f-4c2d-8cf3-5075eeeeb04e@googlegroups.com>
In reply to#47023
On Wednesday, May 11, 2016 at 3:01:48 PM UTC-7, Wolfgang Allinger wrote:
> On 11 May 16 at group /comp/lang/forth in article 6548d185-2c31-40a4-bfa9-a3c353e9fa5d@googlegroups.com
>  <murphy.darin@gmail.com>   wrote:
> 
> >Sorry if this isn't appropriate question on this forum, but I am
> >unable to find one specifically for "gforth" questions, but I am
> >trying to learn forth and gforth is the only free, and actively
> >supported by the developer forth that runs under on my Google Pixel C
> >tablet.  

Your question is appropriate here. You don't need gForth-specific information --- this is just basic Forth programming.

> >Anyway here's the program:
> >
> >: penny   ( n -- ) dup 1 > if . ." pennies" else dup 0 > if . ."
> >penny" then then ;
> 
> >: nickel   ( n -- n ) 5 /mod ?dup 0= if penny else .
> >." nickel" then ?dup 0 > if ." , " penny then ; : dime   ( n -- n ) 10
> >/mod ?dup 0= if nickel else dup 1 > if . ." dimes" else . ." dime" then
> >then ?dup 0 > if ." , " nickel then ; : quarter ( n -- n ) 25 /mod ?dup
> >0= if dime else dup 1 > if . ." quarters" else . ." quarter" then then
> >?dup 0 > if ." , " dime then ; : dollar ( n -- n ) 100 /mod ?dup 0= if
> >quarter else dup 1 > if . ." dollars" else . ." dollar" then then ?dup
> >0 > if ." , " quarter then ; : 5-dollar   ( n -- n )
> >500 /mod ?dup 0= if dollar else dup 1 > if . ." fives" else . ." five"
> >then then ?dup 0 > if ." , " dollar then ; : 10-dollar   ( n -- n )
> >1000 /mod ?dup 0= if 5-dollar else dup 1 > if . ." tens" else . ." ten"
> >then then ?dup 0 > if ." , " 5-dollar then ; : 20-dollar   ( n --n )
> >2000 /mod ?dup 0= if 10-dollar else dup 1 > if . ." twenties" else . ."
> >twenty" then then ?dup 0 > if ." , " 10-dollar then ; : 50-dollar ( n
> >-- n ) 5000 /mod ?dup 0= if 20-dollar else dup 1 > if . ." fifties"
> >else . ." fifty" then then ?dup 0 > if ." , " 20-dollar then ; : 100-
> >dollar  ( n -- n ) 10000 /mod ?dup 0= if 50-dollar else dup 1
> >> if . ." hundreds" else . ." hundred" then then ?dup 0 > if ." , "
> >50-dollar then ;
> >
> >: pennies-exchange   ( n -- ) ?dup 0= if ." ERROR - Must enter a
> >number greater than 0!" else 100-dollar then ;
> >
> >I've rewritten this program about a dozen times and have removed a
> >elusive 0 that was being left on the stack, but now it sometimes works
> >fine, while other times I get garbage and a "stack underflow" error.
> 
> Test the `penny` interactive, and look for
> -1 penny
> 0 penny
> 1 penny
> 2 penny
> and check the stack afterwards, with .s
> 
> 
> Also the other declarations doesn`t follow your assumed stack comments.
> I didn`t check it correctly, it`s your job :)
> Check them also interactive.

Wolfgang's advise is very good. The primary virtue of Forth is interactive debugging. This is also the point of factoring. You have simple low-level words such as PENNY and you test them interactively to make sure they work. Then you interactively test the slightly higher-level words that are based on those low-level words to make sure they work. This job is made easy because you already know that the low-level words work, so if these words don't work you don't have to wonder if the bug is in a low-level word but you know that the bug is right in front of you. Work up like this and you will get your program working in short order.

If you write an entire program and then find that it doesn't work, you don't have any idea where the bug is. Because the program is large, you will feel despair in finding the bug, and you will likely give up. Or you will just sit there staring at the whole program but not attacking the problem from any particular direction. You have to attack the problem from the bottom up --- that is the correct approach.

Forth has a REPL, so use it for testing. PENNY only takes one parameter, so there aren't many combinations of parameters to test. This should do it:

2 PENNY
1 PENNY
0 PENNY
-1 PENNY

This pretty much covers everything that could be done with PENNY. The 2 is just an arbitrary positive number other than 1 --- you won't learn anything further by testing with 3 and 4 etc.. Similarly, you don't need to test a variety of negative numbers, as they are all invalid and should all result in an error.

> For a beginner it`s more readable in not to use single line.
> Also write stack comments for every line.
> 
> : penny ( n -- )
>         dup 1 > if
>             . ." pennies"
>         else
>             dup 0> if
>                 . ." penny"
>             then
>         then
>  ;
> 
> You should add the stack comments after each line and hopefully you find
> the place, where the stack goes wrong. A debugger in single step will  
> also help.

I don't agree with this. All those levels of indentation make it look like Pascal (I've heard that Python actually requires such indentation. OMG!). I can't even tell at a glance if Wolfgang's code is correct or not, because it is over-complicated.

I would write PENNY like this:

: penny ( n -- )
    dup 1 > if  . ." pennies"  exit then
    dup 1 = if  . ." penny"    exit then
    dup 0 = if  drop           exit then
    true abort" *** PENNY given a negative number ***" ;

This is super-simple --- anybody can tell at a glance that this is correct --- it covers every possibility, one per line, so what could be easier?

In general, the rule-of-thumb is that all functions should be 7 or fewer lines, and that most should be 3 or fewer --- but Wolfgang gratuitously made his function long and complicated-looking.

BTW: A little error-checking also helps --- calling PENNY with a negative is the only way to screw-up PENNY, so you might as well abort with an error-message in this circumstance.

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


#47030

Frommurphy.darin@gmail.com
Date2016-05-11 19:40 -0700
Message-ID<7391a6a3-1244-433a-87c3-35ff635b72d7@googlegroups.com>
In reply to#47029
Thanks hughag. It's great having you all here to learn from.  I also agree with you about the indentations, even though in 5 weeks I'll be head deep in them (starting UoPeople's C.S. program, which starts with python :/).  Anyway I have been reading this forum now for a couple of months learning and seeing what the real forth community has been doing.  Though small I think this community is like a family. There are arguements and a few very heated words, but all and all it's good to see this amazing and very misunderstood language a live and well.  I will be working on breaking things down and testing as I go one word at a time, even though I'm not a big fan of gforth even though for android it's really the only game in town.  Anyway thanks again for your advice and suggestions hughag. I really am grateful. Take care now.

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


#47035

FromPaul Rubin <no.email@nospam.invalid>
Date2016-05-11 23:22 -0700
Message-ID<87twi36biu.fsf@jester.gateway.pace.com>
In reply to#47030
murphy.darin@gmail.com writes:
> even though for android it's really the only game in town.

If you're getting interested in programming and planning to do more of
it and take classes and stuff, you should probably get a Linux system of
some kind.  If you're on the cheap you can scrounge an old laptop from a
relative or buy one on craigslist, then install Debian on it.  That will
be a much saner development environment than Android, which is primarily
a media consumption platform.

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


#47036

Frommurphy.darin@gmail.com
Date2016-05-12 00:01 -0700
Message-ID<1f0a9579-b955-4de5-85be-3b26aa0f9723@googlegroups.com>
In reply to#47035
Thanks Paul for the suggestion.  I have a Raspberry PI 3, which I'll be using for my UoPeople classes (Python/Java developement), which I have already installed gforth for though I would rather use something more like pre-ANSI since "Starting Forth" is clearing than the ANSI. I'm also looking around for a open source board perhaps Banana PI, Orange PI, etc if anyone has gotten Forth working on any of those.  My Raspberry PI 3 is fine for school, but I don't like using it for serious developement due to it's blob to GPU and it's close sourceness.  Basically my ideal would be a bare metal forth on a open source 64 Bit HW board with a GPU and Wifi to remote in from my tablet or phone. If you know something like that please post me a link.  I really don't have the space for a desk & chair, keyboard, mouse, display (other than my 55" TV).  If not I'll just have to keep using gforth until I'm experienced enough to move to assembly, which I have played with in the past (8088/8086). Anyway I don't want to get too ahead of myself, because I get distracted too easy on the big picture and forget all of the billions of tiny pieces that need to be done first. Thanks again Paul for the info. Take care now.

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


#47037

Fromhughaguilar96@gmail.com
Date2016-05-12 00:08 -0700
Message-ID<6d5ec111-b08a-44be-9d56-fe1d09037b20@googlegroups.com>
In reply to#47036
On Thursday, May 12, 2016 at 12:01:11 AM UTC-7, murphy...@gmail.com wrote:
> Thanks Paul for the suggestion.  I have a Raspberry PI 3, which I'll be using for my UoPeople classes (Python/Java developement), which I have already installed gforth for though I would rather use something more like pre-ANSI since "Starting Forth" is clearing than the ANSI. I'm also looking around for a open source board perhaps Banana PI, Orange PI, etc if anyone has gotten Forth working on any of those.  My Raspberry PI 3 is fine for school, but I don't like using it for serious developement due to it's blob to GPU and it's close sourceness.  Basically my ideal would be a bare metal forth on a open source 64 Bit HW board with a GPU and Wifi to remote in from my tablet or phone. If you know something like that please post me a link.  I really don't have the space for a desk & chair, keyboard, mouse, display (other than my 55" TV).  If not I'll just have to keep using gforth until I'm experienced enough to move to assembly, which I have played with in the past (8088/8086). Anyway I don't want to get too ahead of myself, because I get distracted too easy on the big picture and forget all of the billions of tiny pieces that need to be done first. Thanks again Paul for the info. Take care now.

Trade the TV for a laptop --- so you will not only gain a laptop, but you will save your mind from TV-rot --- a double-win for you!

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


#47053

Frommurphy.darin@gmail.com
Date2016-05-12 12:09 -0700
Message-ID<a4bf9138-9040-4777-910b-ad67c1c7be65@googlegroups.com>
In reply to#47037
Thanks for the suggestion hughag, but the TV is used in the late at time to watch netflix with my disabled fiancee (I'm also her caregiver). Was wondering if any you may have tried pijFORTHos (Forth on Bare Metal for Raspberry PI)?

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


#47065

Fromrickman <gnuarm@gmail.com>
Date2016-05-12 20:48 -0400
Message-ID<nh381l$f82$1@dont-email.me>
In reply to#47036
On 5/12/2016 3:01 AM, murphy.darin@gmail.com wrote:
> Thanks Paul for the suggestion.  I have a Raspberry PI 3, which I'll
> be using for my UoPeople classes (Python/Java developement), which I
> have already installed gforth for though I would rather use something
> more like pre-ANSI since "Starting Forth" is clearing than the ANSI.
> I'm also looking around for a open source board perhaps Banana PI,
> Orange PI, etc if anyone has gotten Forth working on any of those.
> My Raspberry PI 3 is fine for school, but I don't like using it for
> serious developement due to it's blob to GPU and it's close
> sourceness.  Basically my ideal would be a bare metal forth on a open
> source 64 Bit HW board with a GPU and Wifi to remote in from my
> tablet or phone. If you know something like that please post me a
> link.  I really don't have the space for a desk & chair, keyboard,
> mouse, display (other than my 55" TV).  If not I'll just have to keep
> using gforth until I'm experienced enough to move to assembly, which
> I have played with in the past (8088/8086). Anyway I don't want to
> get too ahead of myself, because I get distracted too easy on the big
> picture and forget all of the billions of tiny pieces that need to be
> done first. Thanks again Paul for the info. Take care now.

I had a discussion about the GPU "blob" on the rPi SoC and it is not the 
only part that is not fully documented.  I was told all current SoC 
products contain IP purchased from vendors which do not make public full 
documentation, but rather provide binary drivers.  So you will be hard 
pressed to find a SoC CPU that doesn't have the same or similar issues 
to the rPi.

If you want to work with a "more" open single board computer (SBC), the 
Beagle Bone Black (BBB) seems to be a good candidate.  They provide 
schematics and I think even the Gerbers so you can build your own boards 
from scratch if you like.

Not sure why you would prefer to use a bare metal forth.  That would 
require you to come up with drivers for every part of the SoC you want 
to use.  Is that what you want to do?

As someone else has said, a laptop makes a good interface.  They can be 
pretty small and can be bought pretty cheaply.  If you want to use your 
phone as a user interface, why bother with the SBC?  An android phone 
will run Forth I believe.

One final comment, not sure what you are saying about Starting Forth and 
ANSI Forth.  Starting Forth has been reworked so the examples are all 
workable on an ANSI system, no?

-- 

Rick C

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


#47067

Frommurphy.darin@gmail.com
Date2016-05-12 18:04 -0700
Message-ID<c763693d-324f-440d-a37a-2bbee64a607e@googlegroups.com>
In reply to#47065
Hey Rick C, thanks for your reply.  Well the reason I'm looking for a SOC running a barebone forth is because I can't afford cheap laptop and really don't want to use Linux, Apple and especially Microsoft (20+ years in the IT Industry supporting that mess). I do have a very good tablet (Google Pixel C running Marshmallow), but Android is also a mess, even though it's very functional for a lot of things (games, word processing, programming) it's not really good using forth with directly. Gforth is the only functional game in town and it's not without it's problems.  I also have a Raspberry PI 3 which I can run Linux on, work on my classes in UoPeople (Java/Python), but I don't want to use forth with it. Anyway thanks for asking Rick. Take care now.

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


#47068

Fromrickman <gnuarm@gmail.com>
Date2016-05-12 21:21 -0400
Message-ID<nh39vg$jib$2@dont-email.me>
In reply to#47067
On 5/12/2016 9:04 PM, murphy.darin@gmail.com wrote:
> Hey Rick C, thanks for your reply.  Well the reason I'm looking for a SOC running a barebone forth is because I can't afford cheap laptop and really don't want to use Linux, Apple and especially Microsoft (20+ years in the IT Industry supporting that mess). I do have a very good tablet (Google Pixel C running Marshmallow), but Android is also a mess, even though it's very functional for a lot of things (games, word processing, programming) it's not really good using forth with directly. Gforth is the only functional game in town and it's not without it's problems.  I also have a Raspberry PI 3 which I can run Linux on, work on my classes in UoPeople (Java/Python), but I don't want to use forth with it. Anyway thanks for asking Rick. Take care now.

What exactly do you want to do with Forth?  If you don't need the things 
that you loose or become hard without the operating system, there are 
literally tons of SBCs out there even cheaper than the rPi.  I have 
several ARM CM4 boards that cost me around $10 I think.

-- 

Rick C

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


#47069

FromCecil Bayona <cbayona@cbayona.com>
Date2016-05-12 20:27 -0500
Message-ID<nh3abr$ll9$1@dont-email.me>
In reply to#47067
On 5/12/2016 8:04 PM, murphy.darin@gmail.com wrote:
> Hey Rick C, thanks for your reply.  Well the reason I'm looking for a SOC running a barebone forth is because I can't afford cheap laptop and really don't want to use Linux, Apple and especially Microsoft (20+ years in the IT Industry supporting that mess). I do have a very good tablet (Google Pixel C running Marshmallow), but Android is also a mess, even though it's very functional for a lot of things (games, word processing, programming) it's not really good using forth with directly. Gforth is the only functional game in town and it's not without it's problems.  I also have a Raspberry PI 3 which I can run Linux on, work on my classes in UoPeople (Java/Python), but I don't want to use forth with it. Anyway thanks for asking Rick. Take care now.
>
I bought several  Raspberry B+ for $10 each including shipping from 
Newegg while on sale, use something like that for bare Forth machine.

-- 
Cecil - k5nwa

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


#47070

FromPaul Rubin <no.email@nospam.invalid>
Date2016-05-12 18:46 -0700
Message-ID<87wpmy4tno.fsf@jester.gateway.pace.com>
In reply to#47069
Cecil Bayona <cbayona@cbayona.com> writes:
> I bought several Raspberry B+ for $10 each including shipping from
> Newegg while on sale

Doggone, I missed that.  I'd have taken some.

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


#47072

FromCecil Bayona <cbayona@cbayona.com>
Date2016-05-12 23:28 -0500
Message-ID<nh3ku3$fna$1@dont-email.me>
In reply to#47070
On 5/12/2016 8:46 PM, Paul Rubin wrote:
> Cecil Bayona <cbayona@cbayona.com> writes:
>> I bought several Raspberry B+ for $10 each including shipping from
>> Newegg while on sale
>
> Doggone, I missed that.  I'd have taken some.
>
I bought 3 but have not used them yet, not sure what I will do with them.

It's the NewEggFlash, I was going through the sales items when I spotted 
it, I wish I had bought a whole lot more, I could have sold them to some 
friends at cost.

http://flash.newegg.com/

-- 
Cecil - k5nwa

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


#47077

Frommurphy.darin@gmail.com
Date2016-05-13 00:52 -0700
Message-ID<df3a180c-7f6b-4cad-86ba-307bbb01e6dc@googlegroups.com>
In reply to#47072
Thanks for your suggestions Rick, Paul and Cecil. I'm looking for a SBC with enough power to create network 3d games with, that open source and hardware documented well enough that if I need to build my own drivers or OS, I can.  Now I don't know if I'll ever build something as complex as an OS or a 3D game, but I am looking for something I can do it. Where the only limitation is my inpatience and ignorance. I don't have a ton of money or space for a desktop or even a laptop since I have my tablet here so something like a raspberry PI 2 but documented enough and accessible would fit the build. If that's not possible than maybe a smaller and more limited board but one that can be access to everything and only ran a forth would be cool too, since I first need to crawl before I can walk. I don't mine serial into it if my raspberry PI 3 can do that, I still can access it from my tablet via Remote Ripple.  Perhaps that would be a better place to start. Something small and easier that I can use to learn forth better on, than work my way up from there.  Crawling is the hardest part to learn because I never learned that one as a baby according to my mom. She said I went from laying, seating to walking and bypassed it. Hehehe. Guess now it's time I learned it. Anyway I hope Paul, that answer wasn't too confusing or verbose. Thanks again for the help guys. Take care now.

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


#47081

FromPablo Hugo Reda <pabloreda@gmail.com>
Date2016-05-13 04:07 -0700
Message-ID<a7dbd0aa-6dfd-4b77-85b8-9d34c1b0323f@googlegroups.com>
In reply to#47077
Murphy
I do some work in 3d and games, perhaps this help for learn, but, I use my own version of forth, more close too colorforth, diferent  in many aspect.
My forth have versions for wine and for android (with limitations), the MV is in GCC, can be port to other cpus.
the lang:
https://github.com/phreda4/reda4
I have a forum too but in spanish
https://groups.google.com/forum/#!forum/reda4
good luck

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


#47109

Fromrickman <gnuarm@gmail.com>
Date2016-05-14 00:42 -0400
Message-ID<nh6a4i$d8s$1@dont-email.me>
In reply to#47077
On 5/13/2016 3:52 AM, murphy.darin@gmail.com wrote:
> Thanks for your suggestions Rick, Paul and Cecil. I'm looking for a
> SBC with enough power to create network 3d games with, that open
> source and hardware documented well enough that if I need to build my
> own drivers or OS, I can.  Now I don't know if I'll ever build
> something as complex as an OS or a 3D game, but I am looking for
> something I can do it. Where the only limitation is my inpatience and
> ignorance. I don't have a ton of money or space for a desktop or even
> a laptop since I have my tablet here so something like a raspberry PI
> 2 but documented enough and accessible would fit the build. If that's
> not possible than maybe a smaller and more limited board but one that
> can be access to everything and only ran a forth would be cool too,
> since I first need to crawl before I can walk. I don't mine serial
> into it if my raspberry PI 3 can do that, I still can access it from
> my tablet via Remote Ripple.  Perhaps that would be a better place to
> start. Something small and easier that I can use to learn forth
> better on, than work my way up from there.  Crawling is the hardest
> part to learn because I never learned that one as a baby according to
> my mom. She said I went from laying, seating to walking and bypassed
> it. Hehehe. Guess now it's time I learned it. Anyway I hope Paul,
> that answer wasn't too confusing or verbose. Thanks again for the
> help guys. Take care now.

I think I mentioned before that I have been told there are virtually (or 
actually) *no* devices as you describe that are completely documented 
enough for you to write your own drivers.  Every SoC made today uses 
someone's proprietary IP in some part of the chip.

I don't know for sure this applies to all the x86 products out there.  I 
know there are some very small motherboards which can be used in a very 
small package, perhaps not as small as an rPi, but no bigger than your 
text book.  They should be inexpensive too, but again, not as 
inexpensive as the rPis.  I just don't know so much about the support 
chips on such a board.  Some of them may not be fully documented and 
come with binary drivers.

-- 

Rick C

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


#47112

Frommurphy.darin@gmail.com
Date2016-05-14 00:05 -0700
Message-ID<bc9fdf8d-b53e-467f-9c35-4730dbd6bf39@googlegroups.com>
In reply to#47109
Thanks rick. I remember and so far as I've been able to tell. A Beagleboard seems to be the only thing that comees close, though I haven't looked at it enough yet to tell for certain. I agree there are several x86 tiny boards out there, but was hoping to go with arm since many things I've read suggests that x86 isn't the best option for forth as it's more desized for C based languages.  Thanks again for your help though. I am very grateful. Take care now.

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


#47132

Fromrickman <gnuarm@gmail.com>
Date2016-05-15 00:10 -0400
Message-ID<nh8skf$83l$2@dont-email.me>
In reply to#47112
On 5/14/2016 3:05 AM, murphy.darin@gmail.com wrote:
> Thanks rick. I remember and so far as I've been able to tell. A Beagleboard seems to be the only thing that comees close, though I haven't looked at it enough yet to tell for certain. I agree there are several x86 tiny boards out there, but was hoping to go with arm since many things I've read suggests that x86 isn't the best option for forth as it's more desized for C based languages.  Thanks again for your help though. I am very grateful. Take care now.

I have no idea why anyone would say a conventional processor designed to 
run C programs efficiently would not be suitable for running Forth.  I 
don't know of any reason why the two would be mutually exclusive.

-- 

Rick C

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


#47139

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2016-05-15 10:34 +0000
Message-ID<2016May15.123405@mips.complang.tuwien.ac.at>
In reply to#47132
rickman <gnuarm@gmail.com> writes:
>I have no idea why anyone would say a conventional processor designed to 
>run C programs efficiently would not be suitable for running Forth.  I 
>don't know of any reason why the two would be mutually exclusive.

Right.  Forth is a language that was designed to be close to the
machine, so it's unsurprising that it can be implemented efficiently
on existing machines.  It takes a more effort (and complexity) to
implement it very efficiently than a Forth implementation on a Forth
processor, though.  But if you are prepared to sacrifice some run-time
efficiency for simplicity, compilation can be very simple: see machine
Forth for the 386.

- 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 2016: http://www.euroforth.org/ef16/

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


Page 1 of 5  [1] 2 3 4 5  Next page →

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


csiph-web