🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.oberon
Article #849

Help! POINTERS

#849
From: Bronxx
Date: Fri, 26 Jan 1996 12:10
106 lines
4369 bytes
Someone please confirm the heaps of errors in the book 
"Programming in Oberon" <Martin Reiser, Niklaus Wirth>.
(I'm referring to the 1992 edition and don't know if there
is a newer one.)

It's a very important section in the book (pointers), and I 
think it's terrible that one can't rely on the creator's manual 
on such a crucial topic.

So first we look at page 135, where the authors introduce a 
Pointer declaration:

p.135:	TYPE
	  ListNode = POINTER TO ListNodeDesc;
	  ListNodeDesc = RECORD
	    key: Key; next: Node		(*)
	  END;
	  VAR first: ListNode;

(*) The field named next should obviously be of pointer type 
"ListNode", not "Node"!

On the next page, some other examples are given, like TreeNode etc.
(TreeNode = POINTER TO TreeNodeDesc: TreeNodeDesc = RECORD ...)

On page 137:

I must admit, that I have some problems understanding the NEW(p) 
command, not least because of this book, but I think there are
errors here too:

p.137:	For example, assume first: ListNode and root: TreeNode. Then

	  NEW(first)  A variable of type ListNode (*) is created, 
                      which is designated by pointer first.

          NEW(root)   A variable of type TreeNode (**) is created, 
                      which is designated by pointer root.

Okay now, I suppose TreeNode and ListNode are of pointer type.
So  first  and  root  are declared as pointers.
Shouldn't it be "ListNodeDesc" instead of "ListNode" at position 
marked with (*) and similarly "TreeNodeDesc" at (**) ?


At the next page, I still have the declaration of type 
ListNode = POINTER and ListNodeDesc = RECORD in my head (as above), 
because nowhere is mentioned that the declaration changes at this 
point. But I think for the chapter "Implied dereferencing", the 
authors have chosen a different type declaration, without telling 
us so! Because:

p.138:	first.next   stands for   first^.next
        [...]

	Thus if a field or index selector is present we may use the 
        pointer as if it were a name of the variable pointed at. We
        stress, however, that this abreviation holds only for fields
        and array elements. The designator  first , for example, de-
        notes a pointer value, not an object of type ListNode. (*)
        Such an object is referenced by  first^ . To refine this
        point, let  node: ListNode (**) and consider the assignments:

          node := first		illegal assignment, pointer to record

          node := first^        legal assignment, record to record.

I understand the dereferencing principle, but still I think the types
are wrong here again! Because in (*), "ListNode" obviously isn't a 
pointer anymore. (My proposition would be "ListNodeDesc"), and I think
Martin Reiser and Niklaus Wirth want to define in (**) that node is
of record type. (But according to earlier definitions, this should be
"node: ListNodeDesc").

(**) Until now "ListNode" was a pointer (p. 135), but now "ListNode"
     is a record.

Therefore I assume the type declaration has changed from the one on
page 135 to this one:

TYPE Node = POINTER TO ListNode;
     ListNode = RECORD
		  key: Key;
		  next: Node
		END;

I complain of course because noone tells this anywhere, and it is 
confusing! [On page 140, a new pointer will be declared, like "Node"
and "NodeDesc", but this isn't exactly what we need here, and anyway,
I tend to read my books from low page numbers to higher ones, and in 
that order :)]

On the very next page, we see a picture of a sample list, composed
of three nodes, and here "first: ListNode" is clearly a pointer again!


Please tell me if I'm wrong. I want to understand these things, but how
can I if errors and unmentioned assumptions stop me?

Thank you,
Robert

In my next posting I'll have a question concerning NEW(p) again.

%% rmichl@cinenet.ch %% http://www.amiga.icu.net.ch/~rmichl %%
%% Robert Michl %% Fabrikstrasse  21 %% 8005  Zuerich %% CH %%
Technical Details
Message-ID: <4eagcg$l6d@neptune.ethz.ch>
Path: arc1-ca.pugleaf.net!inf.ethz.ch!rmichl

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!inf.ethz.ch!rmichl
From: rmichl@iiic.ethz.ch (Bronxx)
Newsgroups: comp.lang.oberon
Subject: Help! POINTERS
Date: 26 Jan 1996 12:10:56 GMT
Organization: Dept. Informatik, Swiss Federal Institute of Technology (ETH), Zurich, CH
Message-ID: <4eagcg$l6d@neptune.ethz.ch>
NNTP-Posting-Host: raf1.inf.ethz.ch
Keywords: Errors in the book