My System 4 hate me. 
Author Message
 My System 4 hate me.

Hello.  Just for fun I thought I'd go back and do the excercises in
the Reiser & Wirth book.  Chapter 7 is annoying me, because my
procedures that should work don't.  I'm including MODULE Excercises
and the coinciding Out.Text .  Anyone recognize why my actual parameters
aren't passed properly, or why my assignments don't work?  I've been
grappling with this for a week now, and I can't see anything I'm doing
wrong.

I realize that my algorithms aren't the prettiest, but I presume that
Oberon doesn't have some sort of inborn sense of good algorithmic
design (colon right-parenthesis).  Also, while sqrt (arg) worked here
it doesn't with anything else.

Thanks, and I hope that such a low level question is refreshing.
Mick Powers

inclusions:
MODULE Excercises;

IMPORT
        In, Out;

CONST
        epsilon = 0.0005;

PROCEDURE fact* (x: REAL): REAL;
VAR value: REAL;
BEGIN
        Out.Ln; Out.String ("Opening fact"); Out.Ln;
        value := 1.0;
        WHILE x >= 0.0 DO
                Out.String ("x = "); Out.Real (x,4); Out.String ("     value = "
                Out.Real (x,4); Out.Ln;
                value := value * x; x := x - 1.0
        END;
        RETURN value
END fact;

PROCEDURE pwr* (x, e: REAL): REAL;
VAR value: REAL;
BEGIN
        Out.Ln; Out.String ("Opening pwr"); Out.Ln;
        value := 1.0;
        WHILE e >= 0.0 DO
                Out.String ("x = "); Out.Real (x,4); Out.String ("     e = ");
                Out.Real (x,4); Out.String ("     value = "); Out.Real (x,4); Ou
                value := value * x;
                e := e - 1.0
        END;
        RETURN value
END pwr;

PROCEDURE sin* (x: REAL): REAL;
VAR part, sign, count, value: REAL;
BEGIN
        value := 0.0; sign := 1.0; count := 1.0; part := 0.0;
        REPEAT
                part := sign * pwr (x,count) / fact (count); value := value + pa
                count := count + 2; sign := -1.0 * sign
        UNTIL part <= epsilon;
        RETURN value
END sin;

PROCEDURE harmonicup* (x: REAL): REAL;
VAR value, denominator: REAL;
BEGIN
        value := 0.0; denominator := 1.0;
        WHILE denominator <= x DO
                value := value + 1.0 / denominator;
                denominator := denominator + 1.0
        END;
        RETURN value
END harmonicup;

PROCEDURE harmonicdown* (x: REAL): REAL;
VAR value: REAL;
BEGIN
        value := 0.0; x := ENTIER (x);
        WHILE x > 0.0 DO
                value := value + 1.0 / x;
                x := x - 1.0
        END;
        RETURN value
END harmonicdown;

PROCEDURE sqrt* (x: REAL): REAL;
VAR new, old: REAL;
BEGIN
        new := 1.0;
        REPEAT
                old := new; new := 0.5 * (old + x / old)
        UNTIL ABS (new - old) <= epsilon;
        RETURN new
END sqrt;

END Excercises.

Here is the output:

Out.Text
sin (  4.E+00) =
Opening pwr
x =   4.E+00     e =   4.E+00     value =   4.E+00
x =   4.E+00     e =   4.E+00     value =   4.E+00

Opening fact
x =   1.E+00     value =   1.E+00
x =   0.E+00     value =   0.E+00

Opening pwr
x =   4.E+00     e =   4.E+00     value =   4.E+00
x =   4.E+00     e =   4.E+00     value =   4.E+00
x =   4.E+00     e =   4.E+00     value =   4.E+00
x =   4.E+00     e =   4.E+00     value =   4.E+00

Opening fact
x =   3.E+00     value =   3.E+00
x =   2.E+00     value =   2.E+00
x =   1.E+00     value =   1.E+00
x =   0.E+00     value =   0.E+00
     NaN
h+ (  4.E+00) =   2.E+00
h- (  4.E+00) =   2.E+00
sqrt (  4.E+00) =   2.E+00



Sat, 10 Jan 1998 03:00:00 GMT  
 My System 4 hate me.

Quote:

> PROCEDURE fact* (x: REAL): REAL;
> VAR value: REAL;
> BEGIN
>         Out.Ln; Out.String ("Opening fact"); Out.Ln;
>         value := 1.0;
>         WHILE x >= 0.0 DO
>                 Out.String ("x = "); Out.Real (x,4); Out.String ("     value = "
>                 Out.Real (x,4); Out.Ln;
>                 value := value * x; x := x - 1.0
>         END;
>         RETURN value
> END fact;

Why print out the same value of x TWICE?
Also, I suggest to make x an INTEGER.

In the second function, for x^^e, e MUST be an integer if you want
to implement using repeat multiplication.

If you program a little more carefully, other errors may go away too.

(sorry for bothering the list with this, but my mail system doesn't
really work for bitnet addresses.)

--Roland

-------------------------------------------------------------------


-------------------------------------------------------------------



Mon, 12 Jan 1998 03:00:00 GMT  
 My System 4 hate me.
There was a posting a while back about a
new OberonF which was supposed to be available
on: ftp.inf.ethz.ch /pub/Oberon/OberonF/WinOberonF11Beta/.
I've been trying to get it ever since - but with no success.
Can anyone help me? Thanks.

Ray Cheung



Thu, 15 Jan 1998 03:00:00 GMT  
 My System 4 hate me.

Quote:

> There was a posting a while back about a
> new OberonF which was supposed to be available
> on: ftp.inf.ethz.ch /pub/Oberon/OberonF/WinOberonF11Beta/.
> I've been trying to get it ever since - but with no success.
> Can anyone help me? Thanks.

> Ray Cheung

I downloaded WinOberon/F Beta Saturday night.  Took three tries to get
DISK2.EXE but otherwise no problems.  If I remember rightly, it was in
the directory you list.  It was certainly in a sub-directory of
/pub/Oberon/OberonF

Do you see anything in that directory?

Ian



Sat, 17 Jan 1998 03:00:00 GMT  
 My System 4 hate me.
: There was a posting a while back about a
: new OberonF which was supposed to be available
: on: ftp.inf.ethz.ch /pub/Oberon/OberonF/WinOberonF11Beta/.
: I've been trying to get it ever since - but with no success.
: Can anyone help me? Thanks.

: Ray Cheung

I ran into the same problem.  I found it on the ftp.inf.ethz.ch host in
a different directory path.  The path is:

    /pub/software/Oberon/OberonF/WinOberonF11Beta/

David Dowd



Thu, 22 Jan 1998 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. OZ++ system released with compiler, execution system and management systems

2. Art and all that Jazz: they are hating before lazy, without sad, alongside wet balls

3. Why do people hate VSAM?

4. Why do people hate VSAM?

5. I hate to ask the group this but...

6. I hate to ask the group this but...

7. Why do you hate C++ ?

8. why (non-smalltalk) programmers hate smalltalk

9. I hate reports<g>

10. I hate newsgroups

11. I hate reports!

12. I Hate Reports

 

 
Powered by phpBB® Forum Software