Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #47419
| From | Darin Murphy <murphy.darin@gmail.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: How could have I factored this better? |
| Date | 2016-05-21 23:06 -0400 |
| Organization | news.aioe.org |
| Message-ID | <nhr7nc$1vtk$1@gioia.aioe.org> (permalink) |
| References | <5e60dbda-f34b-4be0-bfac-d32ddc67062f@googlegroups.com> <d3c4045d-0df1-42d8-8cf8-5649078bfbea@googlegroups.com> |
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/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web