Computing Fundamentals -- Errors in module
Posted: Sat Feb 19, 2022 2:58 pm
I'm working through the book Computing Fundamentals and the module on page 257 is giving me errors at the f.Write statements in the PrintLine procedure. The error messages are that the variables (fields) are read only. I haven't got far enough yet in the book to understand why this is happening, or perhaps it's a typo or bug in the code?
Thanks for any help.
Thanks for any help.
Code: Select all
MODULE Pbox12B;
IMPORT TextModels, TextViews, Views, TextControllers, PboxMappers;
PROCEDURE PrintLine (x: REAL; IN f: PboxMappers.Formatter);
VAR
i, n: INTEGER;
BEGIN
ASSERT(x >= 0.0, 20);
f.WriteReal(x, 8, 1);
f.WriteString(" | ");
n := SHORT(ENTIER(x + 0.5));
FOR i := 1 TO n DO
f.WriteChar("*")
END;
f.WriteLn
END PrintLine;
PROCEDURE PrintHistogram*;
VAR
cn: TextControllers.Controller;
sc: PboxMappers.Scanner;
dataValue: REAL;
md: TextModels.Model;
vw: TextViews.View;
fm: PboxMappers.Formatter;
BEGIN
cn := TextControllers.Focus();
IF cn # NIL THEN
md := TextModels.dir.New();
fm.ConnectTo(md);
sc.ConnectTo(cn.text);
sc.ScanReal(dataValue);
WHILE ~sc.eot DO
PrintLine(dataValue, fm);
(* ra1 *)
sc.ScanReal(dataValue)
END;
vw := TextViews.dir.New(md);
Views.OpenView(vw)
END
END PrintHistogram;
END Pbox12B.