Page 1 of 1

Computing Fundamentals -- Errors in module

Posted: Sat Feb 19, 2022 2:58 pm
by jackD
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.

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.

Re: Computing Fundamentals -- Errors in module

Posted: Sat Feb 19, 2022 5:36 pm
by Ivan Denisov
This is new security feature of BlackBox, which does not allow to call methods of read-only variables.
Just replace

Code: Select all

PROCEDURE PrintLine (x: REAL; IN f: PboxMappers.Formatter);
to

Code: Select all

PROCEDURE PrintLine (x: REAL; f: PboxMappers.Formatter);
This is done, because now compiler can check that data does not modified by methods calling.

Re: Computing Fundamentals -- Errors in module

Posted: Sat Feb 19, 2022 8:03 pm
by jackD
Ivan, thanks. I guess the book is showing its age.

But when I make the change I get a new error at the line which calls the procedure:

Code: Select all

PrintLine(dataValue, fm);
The error is "incompatible assignment", after fm.

Re: Computing Fundamentals -- Errors in module

Posted: Sat Feb 19, 2022 9:46 pm
by cfbsoftware
I tried compiling your unmodified Pbox12B module using v1.6 of BlackBox and the version of PBoxFormatters included with the PBox modules uploaded by Stan Warford to Helmut Zinn's Component Pascal Resources site:

http://www.zinnamturm.eu/downloadsOS.htm#Pbox

and it compiled without a problem.

Re: Computing Fundamentals -- Errors in module

Posted: Sun Feb 20, 2022 5:57 am
by Ivan Denisov
jackD wrote:Ivan, thanks. I guess the book is showing its age.

But when I make the change I get a new error at the line which calls the procedure:

Code: Select all

PrintLine(dataValue, fm);
The error is "incompatible assignment", after fm.
I think that gave wrong advice, because does not know original type of PboxMappers.Formatter.
So VAR should be used instead of IN.

Replace

Code: Select all

PROCEDURE PrintLine (x: REAL; IN f: PboxMappers.Formatter);
To

Code: Select all

PROCEDURE PrintLine (x: REAL; VAR f: PboxMappers.Formatter);

Re: Computing Fundamentals -- Errors in module

Posted: Sun Feb 20, 2022 5:58 am
by Ivan Denisov
cfbsoftware wrote:I tried compiling your unmodified Pbox12B module using v1.6 of BlackBox and the version of PBoxFormatters included with the PBox modules uploaded by Stan Warford to Helmut Zinn's Component Pascal Resources site:

http://www.zinnamturm.eu/downloadsOS.htm#Pbox

and it compiled without a problem.
This change was made in 1.7.2 so of cause in 1.6 there will be no such problem.

Re: Computing Fundamentals -- Errors in module

Posted: Sun Feb 20, 2022 7:52 am
by jackD
Replace

Code: Select all

PROCEDURE PrintLine (x: REAL; IN f: PboxMappers.Formatter);
To

Code: Select all

PROCEDURE PrintLine (x: REAL; VAR f: PboxMappers.Formatter);
Now it's compiling without error. Thanks Ivan.

Re: Computing Fundamentals -- Errors in module

Posted: Sun Feb 20, 2022 10:48 am
by cfbsoftware
Ivan Denisov wrote: This change was made in 1.7.2 so of cause in 1.6 there will be no such problem.
What is the change that was made in 1.7.2 that caused the problem?

Re: Computing Fundamentals -- Errors in module

Posted: Sun Feb 20, 2022 2:26 pm
by Ivan Denisov
cfbsoftware wrote:
Ivan Denisov wrote: This change was made in 1.7.2 so of cause in 1.6 there will be no such problem.
What is the change that was made in 1.7.2 that caused the problem?
There was the discussion here
https://forum.blackboxframework.org/vie ... f=49&t=205