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