Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #47362 > unrolled thread
| Started by | Darin Murphy <murphy.darin@gmail.com> |
|---|---|
| First post | 2016-05-20 13:09 -0700 |
| Last post | 2016-05-27 03:54 -0700 |
| Articles | 12 on this page of 32 — 8 participants |
Back to article view | Back to comp.lang.forth
How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-20 13:09 -0700
Re: How could have I factored this better? rickman <gnuarm@gmail.com> - 2016-05-20 16:18 -0400
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-20 10:25 -1000
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-20 13:39 -0700
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-20 21:33 -0400
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-20 10:23 -1000
Re: How could have I factored this better? Paul Rubin <no.email@nospam.invalid> - 2016-05-20 15:44 -0700
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-20 14:38 -1000
Re: How could have I factored this better? Paul Rubin <no.email@nospam.invalid> - 2016-05-20 17:49 -0700
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-20 14:57 -1000
Re: How could have I factored this better? Paul Rubin <no.email@nospam.invalid> - 2016-05-20 18:34 -0700
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-20 16:00 -1000
Re: How could have I factored this better? Paul Rubin <no.email@nospam.invalid> - 2016-05-20 20:08 -0700
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-20 17:24 -1000
Re: How could have I factored this better? hughaguilar96@gmail.com - 2016-05-21 18:15 -0700
Re: How could have I factored this better? Albert van der Horst <albert@cherry.spenarnc.xs4all.nl> - 2016-05-21 10:01 +0000
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-20 22:15 -0400
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-20 16:46 -1000
Re: How could have I factored this better? hughaguilar96@gmail.com - 2016-05-21 18:36 -0700
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-21 22:51 -0400
Re: How could have I factored this better? hughaguilar96@gmail.com - 2016-05-21 22:23 -0700
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-20 22:43 -0400
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-20 22:19 -0400
Re: How could have I factored this better? "WJ" <w_a_x_man@yahoo.com> - 2016-05-21 22:02 +0000
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-21 22:30 -0400
Re: How could have I factored this better? humptydumpty <ouatubi@gmail.com> - 2016-05-21 19:40 -0700
Re: How could have I factored this better? humptydumpty <ouatubi@gmail.com> - 2016-05-21 19:38 -0700
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-21 23:06 -0400
Re: How could have I factored this better? Paul Rubin <no.email@nospam.invalid> - 2016-05-21 20:59 -0700
Re: How could have I factored this better? Darin Murphy <murphy.darin@gmail.com> - 2016-05-22 03:30 -0400
Re: How could have I factored this better? "Elizabeth D. Rather" <erather@forth.com> - 2016-05-21 23:14 -1000
Re: How could have I factored this better? humptydumpty <ouatubi@gmail.com> - 2016-05-27 03:54 -0700
Page 2 of 2 — ← Prev page 1 [2]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2016-05-21 22:23 -0700 |
| Message-ID | <ff30b571-0092-47d4-9691-2dee0ad1f2c8@googlegroups.com> |
| In reply to | #47418 |
On Saturday, May 21, 2016 at 7:51:03 PM UTC-7, Darin Murphy wrote: > hughaguilar96@gmail.com Wrote in message: > > On Friday, May 20, 2016 at 7:15:57 PM UTC-7, Darin Murphy wrote: > >> Just trying to learn good documentation and factoring as early as > >> possible, so they will become habits by the time I start working > >> on larger programs. > > > > You should not factor just for the sake of factoring, or because you expect somebody on c.l.f. to say: "Good job on factoring!" > > Thank you Hugh for first explaining your view on "factoring" and I > agree that these little programs probably don't need factoring. > I am trying to understand what factoring is, when factoring is > needed and most of all how to factor, in regards to computer > programs and forth specifically. Also I wouldn't expect any one > to compliment me on factoring such a small program. Only to point > out what I am doing incorrectly and give me some suggestions or > examples. That example of master-keying was what really turned me on to Forth. I had been experimenting with Forth (as you are doing with your exercises), but I wasn't a Forth programmer and I could have moved on to other things easily. When I wrote that program, it didn't work. It was maybe 2 or 3 gigantic functions, and I had no idea where the bug was. I printed it out on paper and studied it, but I still didn't know. I was really going to despair of getting the program to work and just switch back to line-number BASIC that I already knew, and most likely I would not have returned to Forth again. Then it occurred to me that all the Forth programmers said to factor and debug from the bottom up, and maybe they weren't just blowing hot air but they actually knew what they were talking about. I did this and the program that had baffled me for days was working in about one hour. I though: "Factoring is strong magic!" I was amazed at how well debugging like that worked. Suddenly I could envision myself writing big programs, whereas previously I didn't really think I could and I didn't know how big programs got written but vaguely assumed that the programmers of the big programs were just a lot smarter than I was. With factoring though, I could see how big programs that work start out as small programs that work. > > You should really get going on a non-trivial program --- I think that you are ready --- you aren't learning much from these tiny trivial programs; > > Thank you also for your belief that I've grown enough to work on > something non-trivial, but I feel that I still need more time > working with the small programs before moving on to something > less trivial. Now your suggestion for me to move to something > non-trivial does lead me to a post I was going to do on asking > what everyone thought was what defines a program as a > non-trivial. I am guessing from my limited experience that it is > a program that takes many small trivial snippets or functions and > connects them together to form a more complicated program or > function. What do you think? I would say that a non-trivial program is one that has a design. Your examples, such as this one, are just exercising the language --- an exercise to show how BEGIN WHILE REPEAT works, or whatever --- but the design is obvious. With a non-trivial program, you have to think about the design and what algorithm you will use. You have enough data that you need some way to store it, which means that you need to choose a data-structure. BTW: Today, in 2016, the vast majority of locksmiths do master-keying by pencil-and-paper. They will do one building for a customer, then reuse the same system for another customer to save themselves the trouble of figuring out a new system. They also do it with all the master pins on top, rather than mix them up top and bottom, because it is simpler this way. The systems are very insecure! I had a secure system working on the Vic-20 with its 6502 and 5KB of RAM. Now we have quad-core 64-bit computers with gigabytes of RAM, but we still have insecure master-key systems the same as we did 30 years ago and for the same reasons. This is because people don't want to write programs themselves, but they want somebody smart to provide them with the programs, but the smart people want to get paid, hence nothing gets done. In the early 1980, there were a lot of programming enthusiasts, not just in Forth, but in Pascal, and in assembly-language too. At that time, the general vision of the future was that common people would write programs on their computers (power to the people!) --- now computers are appliances and people download apps (power and money to the corporations!) --- the computer revolution has been a flop.
[toc] | [prev] | [next] | [standalone]
| From | Darin Murphy <murphy.darin@gmail.com> |
|---|---|
| Date | 2016-05-20 22:43 -0400 |
| Message-ID | <nhohvu$1gv9$1@gioia.aioe.org> |
| In reply to | #47375 |
"Elizabeth D. Rather" <erather@forth.com> Wrote in message:
> On 5/20/16 12:44 PM, Paul Rubin wrote:
>> Darin Murphy <murphy.darin@gmail.com> writes:
>>> Hi everybody. I created the following program and would like to know
>>> how I could have factored and documented it better.
>>
>> Here's my version, which possibly uses some gforth words:
>>
>> : checkneg ( n -- ) 0 < abort" need a non-negative integer" ;
>> : star ( -- ) '*' emit ;
>> : stars ( n -- ) dup checkneg 0 ?do star loop ;
>> : solid-box-stars { cols rows } cr
>> cols checkneg
>> rows checkneg
>> rows 0 ?do
>> cols stars cr
>> loop ;
>>
>>
>> Differences from yours:
>>
>> 1. The stack comment in your STAR word is ( n -- ) but should be ( -- )
>> 2. I used ABORT to break out of the error check since the number
>> is invalid and there's no way to continue. In a bigger program
>> you might want to catch the error with CATCH.
>> 3. I checked for < 0 instead of < 1, since it seems perfectly ok to
>> me to print zero stars without it being an error. That meant
>> changing the loops to ?DO. The repeat/while stuff was clumsy.
>> 4. I used gforth locals for the args to solid-box-stars. Maybe
>> that's controversial but it avoids some stack juggling, assuming
>> you want the interface to stay what you wrote.
>>
>
> I don't see that the locals contributed anything. In fact, this is
> shorter, and avoids the need for code to manage the locals frame.
>
> : checkneg ( n -- ) 0 < abort" need a non-negative integer" ;
> : star ( -- ) '*' emit ;
> : stars ( n -- ) dup checkneg 0 ?do star loop ;
> : solid-box-stars ( cols rows ) cr
> dup checkneg 0 ?do
> dup stars cr
> loop drop ;
>
> In a real-world application, you should know where your arguments are
> coming from, and whether it's possible that one may be illegal. Often
> they're not; for example, if the boundaries of your box are specified in
> variables somewhere, the appropriate place to check would be where the
> variables are filled; thereafter, you know you have legal parameters.
>
> 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."
> ==================================================
>
Mrs. Rather, I think yours is the best version so far and a lot
easier to read than mine. Take care sharing.
Take care now,
--
Darin Murphy
----Android NewsGroup Reader----
http://usenet.sinaapp.com/
[toc] | [prev] | [next] | [standalone]
| From | Darin Murphy <murphy.darin@gmail.com> |
|---|---|
| Date | 2016-05-20 22:19 -0400 |
| Message-ID | <nhogjf$1flu$1@gioia.aioe.org> |
| In reply to | #47370 |
Paul Rubin <no.email@nospam.invalid> Wrote in message:
> Darin Murphy <murphy.darin@gmail.com> writes:
>> Hi everybody. I created the following program and would like to know
>> how I could have factored and documented it better.
>
> Here's my version, which possibly uses some gforth words:
>
> : checkneg ( n -- ) 0 < abort" need a non-negative integer" ;
> : star ( -- ) '*' emit ;
> : stars ( n -- ) dup checkneg 0 ?do star loop ;
> : solid-box-stars { cols rows } cr
> cols checkneg
> rows checkneg
> rows 0 ?do
> cols stars cr
> loop ;
>
>
> Differences from yours:
>
> 1. The stack comment in your STAR word is ( n -- ) but should be ( -- )
> 2. I used ABORT to break out of the error check since the number
> is invalid and there's no way to continue. In a bigger program
> you might want to catch the error with CATCH.
> 3. I checked for < 0 instead of < 1, since it seems perfectly ok to
> me to print zero stars without it being an error. That meant
> changing the loops to ?DO. The repeat/while stuff was clumsy.
> 4. I used gforth locals for the args to solid-box-stars. Maybe
> that's controversial but it avoids some stack juggling, assuming
> you want the interface to stay what you wrote.
>
Thanks Paul, sorry I didn't see your '*' emit even though looking
at it, I think it's a lot more readable than using ." *", so I
updated my example for future reviewing as I progress long the
"forth" learning path.
Take care now,
--
Darin Murphy
----Android NewsGroup Reader----
http://usenet.sinaapp.com/
[toc] | [prev] | [next] | [standalone]
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Date | 2016-05-21 22:02 +0000 |
| Message-ID | <nhqltk$rco$1@dont-email.me> |
| In reply to | #47362 |
Darin Murphy wrote:
> Hi everybody. I created the following program
> and would like to know how I could have factored
> and documented it better.
>
> : star ( n -- ) 42 emit ;
>
> : not-positive-integer ." ERROR - Value not a positive integer!" ;
>
> : positive-integer? ( n -- error or n ) dup 1 < if not-positive-integer drop then ;
>
> : stars ( n -- ) positive-integer? begin dup 0 > while 1 - star repeat drop ;
>
> : solid-box-stars ( column row -- )
> positive-integer? cr begin dup 0 > while >r
> dup stars r> 1 - cr repeat drop drop ;
OCaml:
let stars n = for _ = 1 to n do print_char '*' done ;;
let box_stars columns rows =
for _ = 1 to rows do
stars columns ; print_newline ()
done ;;
box_stars 9 3;;
===>
*********
*********
*********
--
Goyim were born only to serve us.... They will work, they will plow, they will
reap. We will sit like an effendi and eat. --- Rabbi Ovadia Yosef
archive.org/download/DavidDuke_videos/TopRabbiExposesJewishRacism-cybsdwjezqi.ogv
web.archive.org/web/20101020044210/http://www.jpost.com/JewishWorld/JewishNews/Article.aspx?id=191782
[toc] | [prev] | [next] | [standalone]
| From | Darin Murphy <murphy.darin@gmail.com> |
|---|---|
| Date | 2016-05-21 22:30 -0400 |
| Message-ID | <nhr5jt$1u2u$1@gioia.aioe.org> |
| In reply to | #47406 |
"WJ" <w_a_x_man@yahoo.com> Wrote in message: > Darin Murphy wrote: > >> Hi everybody. I created the following program >> and would like to know how I could have factored >> and documented it better. >> >> : star ( n -- ) 42 emit ; >> >> : not-positive-integer ." ERROR - Value not a positive integer!" ; >> >> : positive-integer? ( n -- error or n ) dup 1 < if not-positive-integer drop then ; >> >> : stars ( n -- ) positive-integer? begin dup 0 > while 1 - star repeat drop ; >> >> : solid-box-stars ( column row -- ) >> positive-integer? cr begin dup 0 > while >r >> dup stars r> 1 - cr repeat drop drop ; > > OCaml: > > let stars n = for _ = 1 to n do print_char '*' done ;; > > let box_stars columns rows = > for _ = 1 to rows do > stars columns ; print_newline () > done ;; > > box_stars 9 3;; > ===> > ********* > ********* > ********* > > -- > Goyim were born only to serve us.... They will work, they will plow, they will > reap. We will sit like an effendi and eat. --- Rabbi Ovadia Yosef > archive.org/download/DavidDuke_videos/TopRabbiExposesJewishRacism-cybsdwjezqi.ogv > web.archive.org/web/20101020044210/http://www.jpost.com/JewishWorld/JewishNews/Article.aspx?id=191782 > Hey WJ. Thanks for giving me your OCaml interpretation of my program, but I was wondering why you did it in OCaml instead of forth? I am not trying to cause any negative reaction, but I've noticed in several posts OCaml examples are given and I'm just wondering why? Since I am new here and this is comp.lang.forth it makes me curious. Again I am not trying to start anything negative and I am sorry if my question appears to be anything other than my curiosity. I was always told if you don't know something just ask, so that's all I am doing. Take care now, -- Darin Murphy ----Android NewsGroup Reader---- http://usenet.sinaapp.com/
[toc] | [prev] | [next] | [standalone]
| From | humptydumpty <ouatubi@gmail.com> |
|---|---|
| Date | 2016-05-21 19:40 -0700 |
| Message-ID | <6dd14611-ae5f-4766-9c77-3bbe3ad966e5@googlegroups.com> |
| In reply to | #47414 |
On Sunday, May 22, 2016 at 5:30:28 AM UTC+3, Darin Murphy wrote: > "WJ" <w_a_x_man@yahoo.com> Wrote in message: > > Darin Murphy wrote: > > > >> Hi everybody. I created the following program > >> and would like to know how I could have factored > >> and documented it better. > >> > >> : star ( n -- ) 42 emit ; > >> > >> : not-positive-integer ." ERROR - Value not a positive integer!" ; > >> > >> : positive-integer? ( n -- error or n ) dup 1 < if not-positive-integer drop then ; > >> > >> : stars ( n -- ) positive-integer? begin dup 0 > while 1 - star repeat drop ; > >> > >> : solid-box-stars ( column row -- ) > >> positive-integer? cr begin dup 0 > while >r > >> dup stars r> 1 - cr repeat drop drop ; > > > > OCaml: > > > > let stars n = for _ = 1 to n do print_char '*' done ;; > > > > let box_stars columns rows = > > for _ = 1 to rows do > > stars columns ; print_newline () > > done ;; > > > > box_stars 9 3;; > > ===> > > ********* > > ********* > > ********* > > > > -- > > Goyim were born only to serve us.... They will work, they will plow, they will > > reap. We will sit like an effendi and eat. --- Rabbi Ovadia Yosef > > archive.org/download/DavidDuke_videos/TopRabbiExposesJewishRacism-cybsdwjezqi.ogv > > web.archive.org/web/20101020044210/http://www.jpost.com/JewishWorld/JewishNews/Article.aspx?id=191782 > > > > Hey WJ. Thanks for giving me your OCaml interpretation of my > program, but I was wondering why you did it in OCaml instead of > forth? I am not trying to cause any negative reaction, but I've > noticed in several posts OCaml examples are given and I'm just > wondering why? Since I am new here and this is comp.lang.forth > it makes me curious. Again I am not trying to start anything > negative and I am sorry if my question appears to be anything > other than my curiosity. I was always told if you don't know > something just ask, so that's all I am doing. > > Take care now, > -- > Darin Murphy > > > ----Android NewsGroup Reader---- > http://usenet.sinaapp.com/ Just a troll.
[toc] | [prev] | [next] | [standalone]
| From | humptydumpty <ouatubi@gmail.com> |
|---|---|
| Date | 2016-05-21 19:38 -0700 |
| Message-ID | <d3c4045d-0df1-42d8-8cf8-5649078bfbea@googlegroups.com> |
| In reply to | #47362 |
On Friday, May 20, 2016 at 11:09:43 PM UTC+3, Darin Murphy wrote: > Hi everybody. I created the following program and would like to know how I could have factored and documented it better. > > : star ( n -- ) 42 emit ; > : not-positive-integer ." ERROR - Value not a positive integer!" ; > : positive-integer? ( n -- error or n ) dup 1 < if not-positive-integer drop then ; > : stars ( n -- ) positive-integer? begin dup 0 > while 1 - star repeat drop ; > : solid-box-stars ( column row -- ) positive-integer? cr begin dup 0 > while >r dup stars r> 1 - cr repeat drop drop ; > > Examples, suggestions and advice are welcomed as always. Take care now. Hi! Is time to work primarily on forth command-line. Practice on a forth that have some keyboard facilities (line history, etc.) After writing and testing a definition copy (add) it to the source file. : star ( -- ) 42 emit ; ok : stars ( ucols -- ) begin dup while 1- star repeat drop ; ok cr 5 stars .s *****<0> ok : box ( ucols urows -- ) begin dup while 1- over stars cr repeat 2drop ; ok cr 5 3 box .s ***** ***** ***** <0> ok Non-negative input are specified for user by prefix u of input parameters. There are and other forth niceties for it, but for now is enough, I think. Have a nice day, humptydumpty
[toc] | [prev] | [next] | [standalone]
| From | Darin Murphy <murphy.darin@gmail.com> |
|---|---|
| Date | 2016-05-21 23:06 -0400 |
| Message-ID | <nhr7nc$1vtk$1@gioia.aioe.org> |
| In reply to | #47416 |
humptydumpty <ouatubi@gmail.com> Wrote in message: > On Friday, May 20, 2016 at 11:09:43 PM UTC+3, Darin Murphy wrote: >> Hi everybody. I created the following program and would like to know how I could have factored and documented it better. >> >> : star ( n -- ) 42 emit ; >> : not-positive-integer ." ERROR - Value not a positive integer!" ; >> : positive-integer? ( n -- error or n ) dup 1 < if not-positive-integer drop then ; >> : stars ( n -- ) positive-integer? begin dup 0 > while 1 - star repeat drop ; >> : solid-box-stars ( column row -- ) positive-integer? cr begin dup 0 > while >r dup stars r> 1 - cr repeat drop drop ; >> >> Examples, suggestions and advice are welcomed as always. Take care now. > > Hi! > Is time to work primarily on forth command-line. Practice on a forth > that have some keyboard facilities (line history, etc.) > After writing and testing a definition copy (add) it to the source file. > > : star ( -- ) 42 emit ; ok > : stars ( ucols -- ) begin dup while 1- star repeat drop ; ok > cr 5 stars .s > *****<0> ok > : box ( ucols urows -- ) begin dup while 1- over stars cr repeat 2drop ; ok > cr 5 3 box .s > ***** > ***** > ***** > <0> ok > > Non-negative input are specified for user by prefix u of input parameters. > There are and other forth niceties for it, but for now is enough, I think. > > Have a nice day, > humptydumpty > Thanks Humptydumpty for your example and for explaining how to use "u" in documentation for letting other programmers or myself latter realize that it's asking for only positive integers. I've seen it used in "Starting forth", I guess I forgot to put it in, but will remember next time. The reason I put the tests in, is because I'd rather add a little check than to assume that I, another programmer, or another program calling stars or solid-box-stars will always have the correct values on the stack. This way if they are not correct abort will throw an error explaining what's wrong and where, so that the user/programmer will understand what went wrong and when. Take care now, -- Darin Murphy ----Android NewsGroup Reader---- http://usenet.sinaapp.com/
[toc] | [prev] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2016-05-21 20:59 -0700 |
| Message-ID | <871t4ud9pg.fsf@jester.gateway.pace.com> |
| In reply to | #47419 |
Darin Murphy <murphy.darin@gmail.com> writes:
> Thanks Humptydumpty for your example and for explaining how to use
> "u" in documentation for letting other programmers or myself
> latter realize that it's asking for only positive integers.
It implies a little extra too: namely that the number is treated as
unsigned in the code. That is, a bit pattern like $FFFFFFFF would be
interpreted as the largest positive number (around 4 billion) rather
than as the signed integer -1. In this case though, such large numbers
probably aren't relevant.
Note that unsigned's range includes 0, which is generally not considered
to be a positive number. If we want to indicate that a number comes
from the set {0,1,2,3...}, we generally say that the number is
non-negative.
[toc] | [prev] | [next] | [standalone]
| From | Darin Murphy <murphy.darin@gmail.com> |
|---|---|
| Date | 2016-05-22 03:30 -0400 |
| Message-ID | <nhrn6v$ftr$1@gioia.aioe.org> |
| In reply to | #47420 |
Paul Rubin wrote:
> It implies a little extra too: namely that the number is treated as
> unsigned in the code. That is, a bit pattern like $FFFFFFFF would be
> interpreted as the largest positive number (around 4 billion) rather
> than as the signed integer -1. In this case though, such large numbers
> probably aren't relevant.
>
> Note that unsigned's range includes 0, which is generally not considered
> to be a positive number. If we want to indicate that a number comes
> from the set {0,1,2,3...}, we generally say that the number is
> non-negative.
Thanks Paul for giving me a better understanding at what "u" as in
"unsigned integer" means. Now I understand that that I need to
use something like ( positive n -- ) or ( +u ) to show I mean a
positive integer ( greater than zero ). I'll remember
that.
Take care now,
--
Darin Murphy
----Android NewsGroup Reader----
http://usenet.sinaapp.com/
[toc] | [prev] | [next] | [standalone]
| From | "Elizabeth D. Rather" <erather@forth.com> |
|---|---|
| Date | 2016-05-21 23:14 -1000 |
| Message-ID | <-Zadncb2MZnl5dzKnZ2dnUU7-WWdnZ2d@supernews.com> |
| In reply to | #47422 |
On 5/21/16 9:30 PM, Darin Murphy wrote:
> Paul Rubin wrote:
>
>> It implies a little extra too: namely that the number is treated as
>> unsigned in the code. That is, a bit pattern like $FFFFFFFF would be
>> interpreted as the largest positive number (around 4 billion) rather
>> than as the signed integer -1. In this case though, such large numbers
>> probably aren't relevant.
>>
>> Note that unsigned's range includes 0, which is generally not considered
>> to be a positive number. If we want to indicate that a number comes
>> from the set {0,1,2,3...}, we generally say that the number is
>> non-negative.
>
> Thanks Paul for giving me a better understanding at what "u" as in
> "unsigned integer" means. Now I understand that that I need to
> use something like ( positive n -- ) or ( +u ) to show I mean a
> positive integer ( greater than zero ). I'll remember
> that.
"+n" is the usual indicator of a positive integer. It's easy to avoid
having to explicitly address the "non-zero" aspect by using ?DO.
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]
| From | humptydumpty <ouatubi@gmail.com> |
|---|---|
| Date | 2016-05-27 03:54 -0700 |
| Message-ID | <ef119822-9f01-4f45-816c-27e39f5fe606@googlegroups.com> |
| In reply to | #47362 |
On Friday, May 20, 2016 at 11:09:43 PM UTC+3, Darin Murphy wrote:
> Hi everybody. I created the following program and would like to know how I could have factored and documented it better.
>
> : star ( n -- ) 42 emit ;
> : not-positive-integer ." ERROR - Value not a positive integer!" ;
> : positive-integer? ( n -- error or n ) dup 1 < if not-positive-integer drop then ;
> : stars ( n -- ) positive-integer? begin dup 0 > while 1 - star repeat drop ;
> : solid-box-stars ( column row -- ) positive-integer? cr begin dup 0 > while >r dup stars r> 1 - cr repeat drop drop ;
>
> Examples, suggestions and advice are welcomed as always. Take care now.
Hi!
Here is some mental-food awaiting for you :)
\ Sentence 'A word should consumes their input parameters.'
\ holds true if that word is not a loop-body.
\ A loop-body should leave intact 'number and order of stack parameters'
\ = 'Stack Effect Invariance'.
: times ( xt u -- ; xt of SEI )
BEGIN dup WHILE 1- over swap 2>R execute 2R> REPEAT 2drop
;
: times: ( u -- ) ( R: CA --u times CA; CA=Continuation Address )
\ Sequence-Of-Code between 'times:' and ';'(or 'EXIT') *is* the Loop-Body
\ Beware of return-stack overflow.
BEGIN 1- dup WHILE R@ >R REPEAT drop
;
\ ---
: cross ( -- ) 43 emit ;
\ ---
\ Use of 'times:' enforce using only loop-body (that assures SEI),
\ input-parameters of 'times:' are also output parameters of word
\ that use 'times:'.
: rcrosses ( u -- ) times: cross ;
: rbox ( uc ur -- uc) times: dup rcrosses cr ;
\ ---
: xcrosses ( u -- ) ['] cross swap times ;
: (xbox) ( u -- u ) dup xcrosses cr ;
: xbox ( uc ur -- uc) ['] (xbox) swap times ;
\ ---
cr 9 3 xbox drop .s
cr 9 3 rbox drop .s
Have a nice day,
humptydumpty
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.forth
csiph-web