Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #34838
| From | Bernd Paysan <bernd.paysan@gmx.de> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: How popular is Forth really, compared to others, any guess? |
| Date | 2014-12-07 23:00 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <m62ilv$lfa$1@dont-email.me> (permalink) |
| References | (5 earlier) <m2dh0o$v3u$1@online.de> <839fb41b-4ccf-403b-a6e7-a0d572ae79dc@googlegroups.com> <ieKdnQzq5JNgGR_JnZ2dnUU7-VmdnZ2d@supernews.com> <cf5d22cb-6cf2-4740-a40d-6e63f185b35c@googlegroups.com> <m62i2m$j23$1@dont-email.me> |
WJ wrote:
> : sq ( n -- n ) dup * ; : g ( a b c -- n ) 2dup max sq >r min max sq r> +
> : ;
>
> Now, let's rewrite it using locals:
>
> : g { a b c -- d } b c max dup * b c min a max dup * + ;
You really should keep sq as factor, because "dup *" certainly is *not*
using locals, but the stack.
: sq { a -- n } a a * ;
> Easier to write, easier to read, easier to understand, easier to debug,
> and shorter.
Or if you write it without factoring, it becomes:
: g ( a b c -- n ) 2dup max dup * >r min max dup * r> + ;
Woops, it is one letter shorter than the locals version. The factoring is
there to make it easier to read, not to make it shorter.
BTW: I think taking the squares to the end makes it more readable:
: g ( a b c -- n ) 2dup max >r min max dup * r> dup * + ;
You see the separation of "get the biggest and the second biggest number"
and "add the two squares", which are really two tasks you have to solve
here.
BTW: Don't use "d" as stack comment if you are not returning a double cell.
--
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/
Back to comp.lang.forth | Previous | Next — Previous in thread | Find similar | Unroll thread
How popular is Forth really, compared to others, any guess? JUERGEN <epldfpga@aol.com> - 2014-10-21 04:50 -0700
Re: How popular is Forth really, compared to others, any guess? Mark Wills <markwills1970@gmail.com> - 2014-10-22 02:37 -0700
Re: How popular is Forth really, compared to others, any guess? "Elizabeth D. Rather" <erather@forth.com> - 2014-10-22 09:57 -1000
Re: How popular is Forth really, compared to others, any guess? Jason Damisch <jasondamisch@yahoo.com> - 2014-10-22 14:11 -0700
Re: How popular is Forth really, compared to others, any guess? Paul E Bennett <Paul_E.Bennett@topmail.co.uk> - 2014-10-22 23:08 +0100
Re: How popular is Forth really, compared to others, any guess? "Rod Pemberton" <buzzoff@nonamewhichexists.cmm> - 2014-10-22 23:02 -0400
Re: How popular is Forth really, compared to others, any guess? "Elizabeth D. Rather" <erather@forth.com> - 2014-10-22 18:26 -1000
Re: How popular is Forth really, compared to others, any guess? Paul E Bennett <Paul_E.Bennett@topmail.co.uk> - 2014-10-23 21:32 +0100
Re: How popular is Forth really, compared to others, any guess? Bernd Paysan <bernd.paysan@gmx.de> - 2014-10-22 23:14 +0200
Re: How popular is Forth really, compared to others, any guess? "Elizabeth D. Rather" <erather@forth.com> - 2014-10-22 13:23 -1000
Re: How popular is Forth really, compared to others, any guess? Bernd Paysan <bernd.paysan@gmx.de> - 2014-10-24 14:34 +0200
Re: How popular is Forth really, compared to others, any guess? beeflobill@gmail.com - 2014-12-05 12:28 -0800
Re: How popular is Forth really, compared to others, any guess? Paul Rubin <no.email@nospam.invalid> - 2014-12-05 12:44 -0800
Re: How popular is Forth really, compared to others, any guess? rickman <gnuarm@gmail.com> - 2014-12-05 16:20 -0500
Re: How popular is Forth really, compared to others, any guess? Jason Damisch <jasondamisch@yahoo.com> - 2014-12-05 13:43 -0800
Re: How popular is Forth really, compared to others, any guess? "Elizabeth D. Rather" <erather@forth.com> - 2014-12-05 18:24 -1000
Re: How popular is Forth really, compared to others, any guess? Jason Damisch <jasondamisch@yahoo.com> - 2014-12-06 10:23 -0800
Re: How popular is Forth really, compared to others, any guess? hughaguilar96@gmail.com - 2014-12-06 18:24 -0800
Re: How popular is Forth really, compared to others, any guess? rickman <gnuarm@gmail.com> - 2014-12-06 22:59 -0500
Re: How popular is Forth really, compared to others, any guess? hughaguilar96@gmail.com - 2014-12-06 21:03 -0800
Re: How popular is Forth really, compared to others, any guess? rickman <gnuarm@gmail.com> - 2014-12-07 04:14 -0500
Re: How popular is Forth really, compared to others, any guess? Julian Fondren <julian.fondren@gmail.com> - 2014-12-07 09:04 -0800
Re: How popular is Forth really, compared to others, any guess? hughaguilar96@gmail.com - 2014-12-07 19:23 -0800
Re: How popular is Forth really, compared to others, any guess? hughaguilar96@gmail.com - 2014-12-07 19:30 -0800
Re: How popular is Forth really, compared to others, any guess? "WJ" <w_a_x_man@yahoo.com> - 2014-12-08 09:35 +0000
Re: How popular is Forth really, compared to others, any guess? awegel@arcor.de (Alexander Wegel) - 2014-12-08 12:53 +0100
Re: How popular is Forth really, compared to others, any guess? JUERGEN <epldfpga@aol.com> - 2014-12-08 14:11 -0800
Re: How popular is Forth really, compared to others, any guess? awegel@arcor.de (Alexander Wegel) - 2014-12-09 00:02 +0100
Re: How popular is Forth really, compared to others, any guess? "WJ" <w_a_x_man@yahoo.com> - 2014-12-07 21:50 +0000
Re: How popular is Forth really, compared to others, any guess? Bernd Paysan <bernd.paysan@gmx.de> - 2014-12-07 23:00 +0100
csiph-web