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


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

Starting Forth 5.

Started by"WJ" <w_a_x_man@yahoo.com>
First post2013-09-23 21:41 +0000
Last post2013-09-24 19:43 +0100
Articles 11 — 7 participants

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


Contents

  Starting Forth 5. "WJ" <w_a_x_man@yahoo.com> - 2013-09-23 21:41 +0000
    Re: Starting Forth 5. Doug Hoffman <glidedog@gmail.com> - 2013-09-24 07:31 -0400
      Re: Starting Forth 5. mhx@iae.nl - 2013-09-24 10:29 -0700
      Re: Starting Forth 5. rickman <gnuarm@gmail.com> - 2013-09-24 21:07 -0400
        Re: Starting Forth 5. mhx@iae.nl - 2013-09-24 21:33 -0700
          Re: Starting Forth 5. albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-09-25 09:20 +0000
        Re: Starting Forth 5. "Rod Pemberton" <dont_use_email@nohavenotit.com> - 2013-09-25 02:41 -0400
        Re: Starting Forth 5. albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-09-25 09:15 +0000
          Re: Starting Forth 5. rickman <gnuarm@gmail.com> - 2013-09-25 16:35 -0400
    Re: Starting Forth 5. albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-09-24 18:21 +0000
      Re: Starting Forth 5. "Alex McDonald" <blog@rivadpm.com> - 2013-09-24 19:43 +0100

#25981 — Starting Forth 5.

From"WJ" <w_a_x_man@yahoo.com>
Date2013-09-23 21:41 +0000
SubjectStarting Forth 5.
Message-ID<l1qcit$998$1@dont-email.me>
: DOUBLED
  6 1000 21 1 DO CR ." YEAR " I 2 U.R
  2DUP R% + DUP ." BALANCE " .
  DUP 2000 > IF CR CR ." more than doubled in "
  I . ." years " LEAVE
  THEN
  LOOP 2DROP ;

The result will look like this:

DOUBLED
YEAR 1 BALANCE 1060
YEAR 2 BALANCE 1124
YEAR 3 BALANCE 1191
YEAR 4 BALANCE 1262
YEAR 5 BALANCE 1338
YEAR 6 BALANCE 1418
YEAR 7 BALANCE 1503
YEAR 8 BALANCE 1593
YEAR 9 BALANCE 1609
YEAR 10 BALANCE 1790
YEAR 11 BALANCE 1897
YEAR 12 BALANCE 2011
more than doubled in 12 years ok


As usual, the code is undecipherable; all you can see
is stack juggling.  Would you pay anyone to create
unmaintainable code like that?

And the results are inaccurate, since integers are
used instead of floating point.

And there is a typo for year 9; the amount shoud be
1689.

If you want it done correctly, a modern high-level
language like Ruby must be used.

def doubled()
  rate = 0.06
  principle = original = 1000
  year = 0
  begin
    year += 1
    principle *= 1 + rate
    printf "Year %2d  Balance %7.2f\n", year, principle
  end until principle > 2 * original
  puts "More than doubled in #{ year } years."
end

doubled
Year  1  Balance 1060.00
Year  2  Balance 1123.60
Year  3  Balance 1191.02
Year  4  Balance 1262.48
Year  5  Balance 1338.23
Year  6  Balance 1418.52
Year  7  Balance 1503.63
Year  8  Balance 1593.85
Year  9  Balance 1689.48
Year 10  Balance 1790.85
Year 11  Balance 1898.30
Year 12  Balance 2012.20
More than doubled in 12 years.

This is a very dull, boring, pedestrian, and elementary
problem for any normal programmer.  To a Forth worshipper,
it's intensely exciting and challenging, since he is using
a stone-age language that is suited only for programming
an embedded controller that flushes a toilet.

That this crude book is considered a classic by Forth
programmers tells us all that we need to know about them.

[toc] | [next] | [standalone]


#25990

FromDoug Hoffman <glidedog@gmail.com>
Date2013-09-24 07:31 -0400
Message-ID<524177ff$0$304$14726298@news.sunsite.dk>
In reply to#25981
On 9/23/13 5:41 PM, WJ wrote:
>
> : DOUBLED
>    6 1000 21 1 DO CR ." YEAR " I 2 U.R
>    2DUP R% + DUP ." BALANCE " .
>    DUP 2000 > IF CR CR ." more than doubled in "
>    I . ." years " LEAVE
>    THEN
>    LOOP 2DROP ;

> DOUBLED
> YEAR 1 BALANCE 1060
> YEAR 2 BALANCE 1124
> YEAR 3 BALANCE 1191
> YEAR 4 BALANCE 1262
> YEAR 5 BALANCE 1338
> YEAR 6 BALANCE 1418
> YEAR 7 BALANCE 1503
> YEAR 8 BALANCE 1593
> YEAR 9 BALANCE 1609
> YEAR 10 BALANCE 1790
> YEAR 11 BALANCE 1897
> YEAR 12 BALANCE 2011
> more than doubled in 12 years ok

> ... the results are inaccurate, since integers are
> used instead of floating point.

They are precisely accurate in terms of integers with "precision as 
displayed", which a programmer should understand.  You miss the purpose 
of the example, which is to illustrate the use of LEAVE.

> And there is a typo for year 9; the amount shoud be
> 1689.

Which has nothing to do with programming.  It is just a 
transcription-to-website error (the paper book has the correct number). 
  By the way, you committed a typo just now (shoud).

> If you want it done correctly, a modern high-level
> language like Ruby must be used.

The last comparison I made showed your Ruby code to be about 1000 times 
slower than the Forth code (also your Ruby code was bugged).  You keep 
missing these important and obvious points.  Why?

You may want to understand your apparently uncontrollable fascination 
with and time spent on a topic that you say you dislike so much.  There 
are professionals that can help you.

-Doug

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


#26001

Frommhx@iae.nl
Date2013-09-24 10:29 -0700
Message-ID<4c92630a-8b81-4dc4-80f5-ee31ded9d68e@googlegroups.com>
In reply to#25990
On Tuesday, September 24, 2013 1:31:10 PM UTC+2, Doug Hoffman wrote:
> On 9/23/13 5:41 PM, WJ wrote:
[..]
>> And there is a typo for year 9; the amount shoud be
>> 1689.
> 
> Which has nothing to do with programming.  It is just a 
> transcription-to-website error (the paper book has the correct number). 

As does the website with the original transcription.

-marcel

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


#26008

Fromrickman <gnuarm@gmail.com>
Date2013-09-24 21:07 -0400
Message-ID<l1td0d$4i6$1@dont-email.me>
In reply to#25990
On 9/24/2013 7:31 AM, Doug Hoffman wrote:
> On 9/23/13 5:41 PM, WJ wrote:
>>
>> : DOUBLED
>> 6 1000 21 1 DO CR ." YEAR " I 2 U.R
>> 2DUP R% + DUP ." BALANCE " .
>> DUP 2000 > IF CR CR ." more than doubled in "
>> I . ." years " LEAVE
>> THEN
>> LOOP 2DROP ;
>
>> DOUBLED
>> YEAR 1 BALANCE 1060
>> YEAR 2 BALANCE 1124
>> YEAR 3 BALANCE 1191
>> YEAR 4 BALANCE 1262
>> YEAR 5 BALANCE 1338
>> YEAR 6 BALANCE 1418
>> YEAR 7 BALANCE 1503
>> YEAR 8 BALANCE 1593
>> YEAR 9 BALANCE 1609
>> YEAR 10 BALANCE 1790
>> YEAR 11 BALANCE 1897
>> YEAR 12 BALANCE 2011
>> more than doubled in 12 years ok
>
>> ... the results are inaccurate, since integers are
>> used instead of floating point.
>
> They are precisely accurate in terms of integers with "precision as
> displayed", which a programmer should understand. You miss the purpose
> of the example, which is to illustrate the use of LEAVE.
>
>> And there is a typo for year 9; the amount shoud be
>> 1689.
>
> Which has nothing to do with programming. It is just a
> transcription-to-website error (the paper book has the correct number).
> By the way, you committed a typo just now (shoud).
>
>> If you want it done correctly, a modern high-level
>> language like Ruby must be used.
>
> The last comparison I made showed your Ruby code to be about 1000 times
> slower than the Forth code (also your Ruby code was bugged). You keep
> missing these important and obvious points. Why?
>
> You may want to understand your apparently uncontrollable fascination
> with and time spent on a topic that you say you dislike so much. There
> are professionals that can help you.
>
> -Doug

There are a great many people in this group who seem to compulsively 
respond to this guy in spite of the fact that he continues to post the 
same sort of denigration of Forth over an over again.  No matter how 
many people respond to him, he continues to not respond to any of the 
points they raise and post more of the same in reply.

Why do people keep responding to him?  Why do I bother to point out any 
of this?

-- 

Rick

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


#26009

Frommhx@iae.nl
Date2013-09-24 21:33 -0700
Message-ID<96709b07-ea05-47aa-a927-fe6249f57be9@googlegroups.com>
In reply to#26008
On Wednesday, September 25, 2013 3:07:12 AM UTC+2, rickman wrote:
> Why do people keep responding to him?  Why do I bother to point out any 
> of this?

The answer is in line with e.g. the decision of Popular 
Science to disable comments on their website. 
Adjust their text to taste.

"'It wasn't a decision we made lightly. 
As the news arm of a 141-year-old science and technology 
magazine, we are as committed to fostering lively, 
intellectual debate as we are to spreading the word of 
science far and wide. The problem is when trolls and 
spambots overwhelm the former, diminishing our ability 
to do the latter. ... even a fractious minority wields 
enough power to skew a reader's perception of a story, 
recent research suggests. ... A politically motivated, 
decades-long war on expertise has eroded the popular 
consensus on a wide variety of scientifically validated 
topics. Everything, from evolution to the origins of 
climate change, is mistakenly up for grabs again. 
Scientific certainty is just another thing for two 
people to "debate" on television. And because comments 
sections tend to be a grotesque reflection of the 
media culture surrounding them, the cynical work of 
undermining bedrock scientific doctrine is now being
done beneath our own stories, within a website devoted 
to championing science.'"

-marcel

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


#26022

Fromalbert@spenarnc.xs4all.nl (Albert van der Horst)
Date2013-09-25 09:20 +0000
Message-ID<5242aaee$0$26866$e4fe514c@dreader37.news.xs4all.nl>
In reply to#26009
In article <96709b07-ea05-47aa-a927-fe6249f57be9@googlegroups.com>,
 <mhx@iae.nl> wrote:
>On Wednesday, September 25, 2013 3:07:12 AM UTC+2, rickman wrote:
>> Why do people keep responding to him?  Why do I bother to point out any
>> of this?
>
>The answer is in line with e.g. the decision of Popular
>Science to disable comments on their website.
>Adjust their text to taste.
>
>"'It wasn't a decision we made lightly.
>As the news arm of a 141-year-old science and technology
>magazine, we are as committed to fostering lively,
>intellectual debate as we are to spreading the word of
>science far and wide. The problem is when trolls and
>spambots overwhelm the former, diminishing our ability
>to do the latter. ... even a fractious minority wields
>enough power to skew a reader's perception of a story,
>recent research suggests. ... A politically motivated,
>decades-long war on expertise has eroded the popular
>consensus on a wide variety of scientifically validated
>topics. Everything, from evolution to the origins of
>climate change, is mistakenly up for grabs again.
>Scientific certainty is just another thing for two
>people to "debate" on television. And because comments
>sections tend to be a grotesque reflection of the
>media culture surrounding them, the cynical work of
>undermining bedrock scientific doctrine is now being
>done beneath our own stories, within a website devoted
>to championing science.'"

There are several solutions. One is to just have a moderator.
The other is the slash dot way. Everybody can rate everybody's
answers. The best answer rises to the top and the experts gain
an inordinate amount of points, which in the end give them the
power to erase a subject totally from the forum.

>
>-marcel

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


#26011

From"Rod Pemberton" <dont_use_email@nohavenotit.com>
Date2013-09-25 02:41 -0400
Message-ID<op.w3yfjksd0e5s1z@localhost>
In reply to#26008
On Tue, 24 Sep 2013 21:07:12 -0400, rickman <gnuarm@gmail.com> wrote:

> [snip on-topic FORTH code for once...]
...

>>> If you want it done correctly, a modern high-level
>>> language like Ruby must be used.
>>
>> The last comparison I made showed your Ruby code to be about 1000 times
>> slower than the Forth code (also your Ruby code was bugged). You keep
>> missing these important and obvious points. Why?
>>
>> You may want to understand your apparently uncontrollable fascination
>> with and time spent on a topic that you say you dislike so much. There
>> are professionals that can help you.
>>
> There are a great many people in this group who seem to compulsively  
> respond to this guy in spite of the fact that he continues to post the  
> same sort of denigration of Forth over an over again.  No matter how  
> many people respond to him, he continues to not respond to any of the  
> points they raise and post more of the same in reply.
>
> Why do people keep responding to him?  Why do I bother to point out any  
> of this?
>

Wow, that's truly ironic...

Didn't I ask the same two things about you posting about non-Forth
microprocessors? (rhetorical)

They respond to him because he *actually* posts Forth code, unlike
you...  Did you post any prior to your c.l.f. hiatus?  I think the
answer to that is a "No" too.  Your earlier posts seem to be purely
microprocessor related also.

The only other people to post Forth code lately are Lauri and gavino.
Lauri is new so they haven't come to hate her yet.  Familiarity breeds
contempt, more so when some people are naturally contemptuous of others...
Yes, the other who posted Forth was gavino.  Are you shocked?  Were you?

This is supposed to be a Forth newsgroup.  There are a few here who
still believe that's true...  They seem to be Marcel and Albert.
They're the *only* ones who've been on-topic over the past year or so.

Unfortunately, those who believe this is a Forth newsgroup instead
of alt.etc, have yet to recognize that this is just a place where
the other long-term "regulars" use Forth topicality as an excuse
to shoo away or silence those they don't want to converse with, so
they can continue discuss other off-topic stuff amongst themselves,
like non-Forth microprocessors (rickman, Bernd), like COBOL or scaring
people in elevators (Alex), like China or history (Bernd, Hugh), like
Testra or MFX or spanish food (Hugh), like Ocaml (Paul R., Mark, Andrew),
like safety standards and touch screens (Paul B.), like artificial
intelligence (Arthur), like advertising a commercial Forth compiler
(Stephen), like totally random shit (Roelf) etc.  There is no point
in mentioning Hohensee or Passaniti since they haven't posted in a while.
AFAICT, it's only acceptable to discuss C if it involves gForth with
Bernd or Anton, even if it's on the exact same topics others have
attempted to discuss prior, e.g., C's malloc(), but not mentioning
gForth in particular...  See, Ms. Rather never complains about Anton
and Bernd discussing C in-depth as long as they casually mention gForth
in passing, so the rest of the Forth clique doesn't complain either
when they do (Andrew, Alex, Mark, et. al.).

Do you understand now?  No?  Well, wait a while and at some point
Ms. Rather will politely hint that you should STFU.  Watch for it.


Rod Pemberton

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


#26021

Fromalbert@spenarnc.xs4all.nl (Albert van der Horst)
Date2013-09-25 09:15 +0000
Message-ID<5242a9bb$0$26866$e4fe514c@dreader37.news.xs4all.nl>
In reply to#26008
In article <l1td0d$4i6$1@dont-email.me>, rickman  <gnuarm@gmail.com> wrote:
>On 9/24/2013 7:31 AM, Doug Hoffman wrote:
>> On 9/23/13 5:41 PM, WJ wrote:
>>>
>>> : DOUBLED
>>> 6 1000 21 1 DO CR ." YEAR " I 2 U.R
>>> 2DUP R% + DUP ." BALANCE " .
>>> DUP 2000 > IF CR CR ." more than doubled in "
>>> I . ." years " LEAVE
>>> THEN
>>> LOOP 2DROP ;
>>
>>> DOUBLED
>>> YEAR 1 BALANCE 1060
>>> YEAR 2 BALANCE 1124
>>> YEAR 3 BALANCE 1191
>>> YEAR 4 BALANCE 1262
>>> YEAR 5 BALANCE 1338
>>> YEAR 6 BALANCE 1418
>>> YEAR 7 BALANCE 1503
>>> YEAR 8 BALANCE 1593
>>> YEAR 9 BALANCE 1609
>>> YEAR 10 BALANCE 1790
>>> YEAR 11 BALANCE 1897
>>> YEAR 12 BALANCE 2011
>>> more than doubled in 12 years ok
>>
>>> ... the results are inaccurate, since integers are
>>> used instead of floating point.
>>
>> They are precisely accurate in terms of integers with "precision as
>> displayed", which a programmer should understand. You miss the purpose
>> of the example, which is to illustrate the use of LEAVE.
>>
>>> And there is a typo for year 9; the amount shoud be
>>> 1689.
>>
>> Which has nothing to do with programming. It is just a
>> transcription-to-website error (the paper book has the correct number).
>> By the way, you committed a typo just now (shoud).
>>
>>> If you want it done correctly, a modern high-level
>>> language like Ruby must be used.
>>
>> The last comparison I made showed your Ruby code to be about 1000 times
>> slower than the Forth code (also your Ruby code was bugged). You keep
>> missing these important and obvious points. Why?
>>
>> You may want to understand your apparently uncontrollable fascination
>> with and time spent on a topic that you say you dislike so much. There
>> are professionals that can help you.
>>
>> -Doug
>
>There are a great many people in this group who seem to compulsively
>respond to this guy in spite of the fact that he continues to post the
>same sort of denigration of Forth over an over again.  No matter how
>many people respond to him, he continues to not respond to any of the
>points they raise and post more of the same in reply.
>
>Why do people keep responding to him?  Why do I bother to point out any
>of this?

Some of us see it as a challenge to show that Forth is up to the
programming exercises that WJ poses. We run that show for our own public,
not for miss/mister/misses WJ.

>
>--
>
>Rick

Groetjes Albert
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


#26031

Fromrickman <gnuarm@gmail.com>
Date2013-09-25 16:35 -0400
Message-ID<l1vhf7$c2p$1@dont-email.me>
In reply to#26021
On 9/25/2013 5:15 AM, Albert van der Horst wrote:
> In article<l1td0d$4i6$1@dont-email.me>, rickman<gnuarm@gmail.com>  wrote:
>> On 9/24/2013 7:31 AM, Doug Hoffman wrote:
>>> On 9/23/13 5:41 PM, WJ wrote:
>>>>
>>>> : DOUBLED
>>>> 6 1000 21 1 DO CR ." YEAR " I 2 U.R
>>>> 2DUP R% + DUP ." BALANCE " .
>>>> DUP 2000>  IF CR CR ." more than doubled in "
>>>> I . ." years " LEAVE
>>>> THEN
>>>> LOOP 2DROP ;
>>>
>>>> DOUBLED
>>>> YEAR 1 BALANCE 1060
>>>> YEAR 2 BALANCE 1124
>>>> YEAR 3 BALANCE 1191
>>>> YEAR 4 BALANCE 1262
>>>> YEAR 5 BALANCE 1338
>>>> YEAR 6 BALANCE 1418
>>>> YEAR 7 BALANCE 1503
>>>> YEAR 8 BALANCE 1593
>>>> YEAR 9 BALANCE 1609
>>>> YEAR 10 BALANCE 1790
>>>> YEAR 11 BALANCE 1897
>>>> YEAR 12 BALANCE 2011
>>>> more than doubled in 12 years ok
>>>
>>>> ... the results are inaccurate, since integers are
>>>> used instead of floating point.
>>>
>>> They are precisely accurate in terms of integers with "precision as
>>> displayed", which a programmer should understand. You miss the purpose
>>> of the example, which is to illustrate the use of LEAVE.
>>>
>>>> And there is a typo for year 9; the amount shoud be
>>>> 1689.
>>>
>>> Which has nothing to do with programming. It is just a
>>> transcription-to-website error (the paper book has the correct number).
>>> By the way, you committed a typo just now (shoud).
>>>
>>>> If you want it done correctly, a modern high-level
>>>> language like Ruby must be used.
>>>
>>> The last comparison I made showed your Ruby code to be about 1000 times
>>> slower than the Forth code (also your Ruby code was bugged). You keep
>>> missing these important and obvious points. Why?
>>>
>>> You may want to understand your apparently uncontrollable fascination
>>> with and time spent on a topic that you say you dislike so much. There
>>> are professionals that can help you.
>>>
>>> -Doug
>>
>> There are a great many people in this group who seem to compulsively
>> respond to this guy in spite of the fact that he continues to post the
>> same sort of denigration of Forth over an over again.  No matter how
>> many people respond to him, he continues to not respond to any of the
>> points they raise and post more of the same in reply.
>>
>> Why do people keep responding to him?  Why do I bother to point out any
>> of this?
>
> Some of us see it as a challenge to show that Forth is up to the
> programming exercises that WJ poses. We run that show for our own public,
> not for miss/mister/misses WJ.

We call that preaching to the choir.  The result is the same.  The troll 
is reinforced and continues to troll... in this case I would say it even 
increases the amount he trolls.

-- 

Rick

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


#26002

Fromalbert@spenarnc.xs4all.nl (Albert van der Horst)
Date2013-09-24 18:21 +0000
Message-ID<5241d839$0$1672$e4fe514c@dreader35.news.xs4all.nl>
In reply to#25981
In article <l1qcit$998$1@dont-email.me>, WJ <w_a_x_man@yahoo.com> wrote:
>
>: DOUBLED
>  6 1000 21 1 DO CR ." YEAR " I 2 U.R
>  2DUP R% + DUP ." BALANCE " .
>  DUP 2000 > IF CR CR ." more than doubled in "
>  I . ." years " LEAVE
>  THEN
>  LOOP 2DROP ;
>
>The result will look like this:
>
>DOUBLED
>YEAR 1 BALANCE 1060
>YEAR 2 BALANCE 1124
>YEAR 3 BALANCE 1191
>YEAR 4 BALANCE 1262
>YEAR 5 BALANCE 1338
>YEAR 6 BALANCE 1418
>YEAR 7 BALANCE 1503
>YEAR 8 BALANCE 1593
>YEAR 9 BALANCE 1609
>YEAR 10 BALANCE 1790
>YEAR 11 BALANCE 1897
>YEAR 12 BALANCE 2011
>more than doubled in 12 years ok
>
>
>As usual, the code is undecipherable; all you can see
>is stack juggling.  Would you pay anyone to create
>unmaintainable code like that?
>
>And the results are inaccurate, since integers are
>used instead of floating point.
>
>And there is a typo for year 9; the amount shoud be
>1689.
>
>If you want it done correctly, a modern high-level
>language like Ruby must be used.
>
>def doubled()
>  rate = 0.06
>  principle = original = 1000
>  year = 0
>  begin
>    year += 1
>    principle *= 1 + rate
>    printf "Year %2d  Balance %7.2f\n", year, principle
>  end until principle > 2 * original
>  puts "More than doubled in #{ year } years."
>end
>
>doubled
>Year  1  Balance 1060.00
>Year  2  Balance 1123.60
>Year  3  Balance 1191.02
>Year  4  Balance 1262.48
>Year  5  Balance 1338.23
>Year  6  Balance 1418.52
>Year  7  Balance 1503.63
>Year  8  Balance 1593.85
>Year  9  Balance 1689.48
>Year 10  Balance 1790.85
>Year 11  Balance 1898.30
>Year 12  Balance 2012.20

These results are incorrect. You don't take into account the
precise rules banking use to handle euro's and cents.
Banks don't think lightly about one cent off.

>More than doubled in 12 years.
>
>This is a very dull, boring, pedestrian, and elementary
>problem for any normal programmer.  To a Forth worshipper,
>it's intensely exciting and challenging, since he is using
>a stone-age language that is suited only for programming
>an embedded controller that flushes a toilet.
>
>That this crude book is considered a classic by Forth
>programmers tells us all that we need to know about them.
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

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


#26003

From"Alex McDonald" <blog@rivadpm.com>
Date2013-09-24 19:43 +0100
Message-ID<l1smgg$2qh$1@dont-email.me>
In reply to#26002
on 24/09/2013 19:21:47,  wrote:
> In article <l1qcit$998$1@dont-email.me>, WJ <w_a_x_man@yahoo.com>
> > wrote:
>>
> > wrote:
>>: DOUBLED
> > wrote:
>>  6 1000 21 1 DO CR ." YEAR " I 2 U.R
> > wrote:
>>  2DUP R% + DUP ." BALANCE " .
> > wrote:
>>  DUP 2000 > IF CR CR ." more than doubled in "
> > wrote:
>>  I . ." years " LEAVE
> > wrote:
>>  THEN
> > wrote:
>>  LOOP 2DROP ;
> > wrote:
>>
> > wrote:
>>The result will look like this:
> > wrote:
>>
> > wrote:
>>DOUBLED
> > wrote:
>>YEAR 1 BALANCE 1060
> > wrote:
>>YEAR 2 BALANCE 1124
> > wrote:
>>YEAR 3 BALANCE 1191
> > wrote:
>>YEAR 4 BALANCE 1262
> > wrote:
>>YEAR 5 BALANCE 1338
> > wrote:
>>YEAR 6 BALANCE 1418
> > wrote:
>>YEAR 7 BALANCE 1503
> > wrote:
>>YEAR 8 BALANCE 1593
> > wrote:
>>YEAR 9 BALANCE 1609
> > wrote:
>>YEAR 10 BALANCE 1790
> > wrote:
>>YEAR 11 BALANCE 1897
> > wrote:
>>YEAR 12 BALANCE 2011
> > wrote:
>>more than doubled in 12 years ok
> > wrote:
>>
> > wrote:
>>
> > wrote:
>>As usual, the code is undecipherable; all you can see
> > wrote:
>>is stack juggling.  Would you pay anyone to create
> > wrote:
>>unmaintainable code like that?
> > wrote:
>>
> > wrote:
>>And the results are inaccurate, since integers are
> > wrote:
>>used instead of floating point.
> > wrote:
>>
> > wrote:
>>And there is a typo for year 9; the amount shoud be
> > wrote:
>>1689.
> > wrote:
>>
> > wrote:
>>If you want it done correctly, a modern high-level
> > wrote:
>>language like Ruby must be used.
> > wrote:
>>
> > wrote:
>>def doubled()
> > wrote:
>>  rate = 0.06
> > wrote:
>>  principle = original = 1000
> > wrote:
>>  year = 0
> > wrote:
>>  begin
> > wrote:
>>    year += 1
> > wrote:
>>    principle *= 1 + rate
> > wrote:
>>    printf "Year %2d  Balance %7.2f\n", year, principle
> > wrote:
>>  end until principle > 2 * original
> > wrote:
>>  puts "More than doubled in #{ year } years."
> > wrote:
>>end
> > wrote:
>>
> > wrote:
>>doubled
> > wrote:
>>Year  1  Balance 1060.00
> > wrote:
>>Year  2  Balance 1123.60
> > wrote:
>>Year  3  Balance 1191.02
> > wrote:
>>Year  4  Balance 1262.48
> > wrote:
>>Year  5  Balance 1338.23
> > wrote:
>>Year  6  Balance 1418.52
> > wrote:
>>Year  7  Balance 1503.63
> > wrote:
>>Year  8  Balance 1593.85
> > wrote:
>>Year  9  Balance 1689.48
> > wrote:
>>Year 10  Balance 1790.85
> > wrote:
>>Year 11  Balance 1898.30
> > wrote:
>>Year 12  Balance 2012.20
> wrote:
> 
> These results are incorrect. You don't take into account the
> precise rules banking use to handle euro's and cents.
> Banks don't think lightly about one cent off.

When I was a COBOL programmer (yes, I'm afraid I was) working for an
insurance company, we used penny (or cent) integer fields with
accumulation of the remainder and very specfic rounding rules. The
remainder difference appeared in he accounts as a 0, +1 or -1 penny/cent
correction to the balance.

Floating point? Never. 
 
> 
>>More than doubled in 12 years.
>>
>>This is a very dull, boring, pedestrian, and elementary
>>problem for any normal programmer.  To a Forth worshipper,
>>it's intensely exciting and challenging, since he is using
>>a stone-age language that is suited only for programming
>>an embedded controller that flushes a toilet.
>>
>>That this crude book is considered a classic by Forth
>>programmers tells us all that we need to know about them.

[toc] | [prev] | [standalone]


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


csiph-web