Reputation: 113
I am stuck with the assignment of a procedure to a pointer in Modula-2.
PROCEDURE print(node : Node_ptr);
BEGIN
(* some code *)
END print;
TYPE Node_ptr = POINTER TO Node;
TYPE Visit_ptr = POINTER TO PROCEDURE (Node_ptr);
TYPE
Node = RECORD
parent : Node_ptr;
left : Node_ptr;
right : Node_ptr;
id : INTEGER;
visit : Visit_ptr;
END;
This somehow compiles.
But I do not know how to assign the print procedure to the visit member of my Node record. I need something like this:
node^.visit^ := print;
(Even the POINTER TO PROCEDURE definition took me a while to figure out...)
Upvotes: 0
Views: 323
Reputation: 66
Your assignment syntax is correct (after you declare node as Node_ptr and allocate space to it).
For more information, I would recommend reading Wirth, "Programming in Modula-2". You can find good used copies USD. It is terse but contains probably all you need. (Other tutorials may be found on http://freepages.modula2.org/tutor.html .)
Upvotes: 2