Computing Fundamentals -- Errors in module

All except GUI problems
Post Reply
jackD
Posts: 10
Joined: Fri Oct 15, 2021 9:10 am

Computing Fundamentals -- Errors in module

Post 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.
User avatar
Ivan Denisov
Posts: 362
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: Computing Fundamentals -- Errors in module

Post 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.
jackD
Posts: 10
Joined: Fri Oct 15, 2021 9:10 am

Re: Computing Fundamentals -- Errors in module

Post 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.
cfbsoftware
Posts: 55
Joined: Wed Sep 18, 2013 10:06 pm
Contact:

Re: Computing Fundamentals -- Errors in module

Post 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.
User avatar
Ivan Denisov
Posts: 362
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: Computing Fundamentals -- Errors in module

Post 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);
User avatar
Ivan Denisov
Posts: 362
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: Computing Fundamentals -- Errors in module

Post 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.
jackD
Posts: 10
Joined: Fri Oct 15, 2021 9:10 am

Re: Computing Fundamentals -- Errors in module

Post 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.
cfbsoftware
Posts: 55
Joined: Wed Sep 18, 2013 10:06 pm
Contact:

Re: Computing Fundamentals -- Errors in module

Post 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?
User avatar
Ivan Denisov
Posts: 362
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: Computing Fundamentals -- Errors in module

Post 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
Post Reply