----boundary-LibPST-iamunique-241418521_-_-
Content-type: text/plain
There is an easy way not to fall into the pit - if this is a pit for you.
Imagine CP were MODULA-2 stylish. Then your code would have to look as
follows:
VAR
a, b: POINTER TO ARRAY OF INTEGER;
x, y: ARRAY 2 OF INTEGER;
NEW(a, 2); NEW(b, 2);
a^[1]:= 1; b^[1]:= 2; (* obligatory pointer symbol ^ *)
x[1]:= 1; y[1]:= 2; (* no pointer symbol allowed *)
b^ := a^; (* deep copy, addresses in heap different *)
b := a; (* shallow copy, pointer assignment, addresses in heap
identical *)
y := x; (* static copy, addresses in stack different *)
b^[1]:= 5; (* resulting unambiguously in a^[1] = 5 *)
This notation is allowed in CP (although I am glad not enforced).
So you may adopt it for your code and get more clarity - together of
course with some added clumsiness.
What can of course not be helped is the fact that only the programmer can
know how many (aliasing) pointers to a certain structure exist in his
programme.
A computer has no brains otherwise programming might be handed over to the
machines.
Harro von Lavergne
On Mon, 19 Jun 2006 21:20:56 +0200, Rex Couture <rex{([at]})nowhere.xy
wrote:
> This has to be a pretty standard problem in computer science,
> and it's not limited to BlackBox. Is there a good way to handle the
> following ambiguity? The problem is that you don't know by looking at
> an assignment statement what the results will be.
>
> My own method is pretty ugly: I use Hungarian notation. Please
> tell me there's a better way. Thanks.
>
> Rex Couture
>
> =====
> VAR
> a, b: POINTER TO ARRAY OF INTEGER;
> x, y: ARRAY 2 OF INTEGER;
>
> NEW( a, 2); NEW( b, 2);
> a[1]:= 1; b[1]:= 2;
> x[1]:= 1; y[1]:= 2;
>
> b:= a;
> y:= x; (* not an equivalent statement *)
>
> b[1]:= 5; (* a[1] = 5 *)
> y[1]:= 5; (* x[1] = 1 *)
>
> --- BlackBox
> --- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy>
>
--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy
----boundary-LibPST-iamunique-241418521_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf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XHBhcg0K
PiAtLS0gQmxhY2tCb3hccGFyDQo+IC0tLSBzZW5kIHN1YmplY3QgSEVMUCBvciBVTlNVQlNDUklC
RSB0byBibGFja2JveEBvYmVyb24uY2hccGFyDQo+XHBhcg0KPlxwYXINClxwYXINCi0tLSBCbGFj
a0JveFxwYXINCi0tLSBzZW5kIHN1YmplY3QgSEVMUCBvciBVTlNVQlNDUklCRSB0byBibGFja2Jv
eEBvYmVyb24uY2hccGFyDQpccGFyDQp9
----boundary-LibPST-iamunique-241418521_-_---
Received on Tue Jun 20 2006 - 13:06:39 UTC