Re: [BLACKBOX] IN Parameters - Side effects

From: [at]} <CFB>
Date: Thu, 31 Jan 2008 23:33:27 +1030

----boundary-LibPST-iamunique-1481736554_-_-
Content-type: text/plain

> -----Original Message-----
> From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xy
> Campbell, Robert (SELEX GALILEO, UK)
> Sent: Thursday, 31 January 2008 7:04 PM
> To: BLACKBOX{([at]})nowhere.xy
> Subject: Re: [BLACKBOX] IN Parameters - Making the design more regular
>
> MODULE Horrible;
...
...

Gee, thanks Robert - trust you to put a spanner in the works! Back to the
drawing board ... (or maybe time to throw in the towel?).

You have raised some valid points. I tried your example using records as
parameters instead of INTEGERs with the current BlackBox 1.6 rc5 compiler.
Contrary to what I have been claiming, it demonstrates that the value of an
IN parameter *can* be changed inside the procedure. Does that mean it is not
'read-only' inside the procedure? If so the compiler is not conforming to
the language reference is it?

...
...
PROCEDURE P (IN x : SomeRecord);
  BEGIN
    Q (x)
(* x can now differ from what it was when initially passed to this
procedure *)
  END P;
...
...

Studying how these design issues were tackled in Ada might be instructive. A
quick taster is here:

http://www.cs.arizona.edu/~collberg/Teaching/520/2005/Html/Html-31/index.htm
l

-----------------------------------------------------
* Ada has three modes:

in-parameters pass information from the caller to the callee. The callee
cannot write to them.
out-parameters pass information to the callee from the caller. The callee
can read and write them. They start out being uninitialized.
in out-parameters pass information from the caller to the callee and back.


* For scalars and pointers, all modes should be implemented by copying
values. Thus

in-parameters are passed-by-value.
out-parameters are passed-by-result (the formal is copied into the actual
when the procedure returns).
in out-parameters are passed-by-value/result (On entry, the actual is copied
into the formal. On return, the formal is copied back into the actual).


* For constructed types (records, arrays) an implementation is allowed to
pass either values or addresses.

If an in out parameter is passed by address an assignment to the formal
changes the actual immediately.
If an in out parameter is passed by value an assignment to the formal will
not affect the actual until the procedure returns (and the formal is copied
back into the actual).
Ada disallows programs that can tell which implementation a compiler uses.

(That last one is particularly intriguing!)

Regards,
Chris

Chris Burrows
CFB Software
http://www.cfbsoftware.com/cp


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1481736554_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwID4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS1c
cGFyDQo+IEZyb206IEJsYWNrQm94IFttYWlsdG86QkxBQ0tCT1hATElTVFMuT0JFUk9OLkNIXSBP
biBCZWhhbGYgT2YgXHBhcg0KPiBDYW1wYmVsbCwgUm9iZXJ0IChTRUxFWCBHQUxJTEVPLCBVSylc
cGFyDQo+IFNlbnQ6IFRodXJzZGF5LCAzMSBKYW51YXJ5IDIwMDggNzowNCBQTVxwYXINCj4gVG86
IEJMQUNLQk9YQExJU1RTLk9CRVJPTi5DSFxwYXINCj4gU3ViamVjdDogUmU6IFtCTEFDS0JPWF0g
SU4gUGFyYW1ldGVycyAtIE1ha2luZyB0aGUgZGVzaWduIG1vcmUgcmVndWxhclxwYXINCj4gXHBh
cg0KPiBNT0RVTEUgIEhvcnJpYmxlO1xwYXINCi4uLlxwYXINCi4uLlxwYXINClxwYXINCkdlZSwg
dGhhbmtzIFJvYmVydCAtIHRydXN0IHlvdSB0byBwdXQgYSBzcGFubmVyIGluIHRoZSB3b3JrcyEg
QmFjayB0byB0aGV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0KXHBhcg0KUmVn
YXJkcyxccGFyDQpDaHJpc1xwYXINClxwYXINCkNocmlzIEJ1cnJvd3NccGFyDQpDRkIgU29mdHdh
cmVccGFyDQpodHRwOi8vd3d3LmNmYnNvZnR3YXJlLmNvbS9jcFxwYXINClxwYXINClxwYXINCi0t
LS1ccGFyDQpUbyB1bnN1YnNjcmliZSwgc2VuZCBhIG1lc3NhZ2Ugd2l0aCBib2R5ICJTSUdOT0ZG
IEJMQUNLQk9YIiB0byBMSVNUU0VSVkBMSVNUUy5PQkVST04uQ0hcfX0AVzUw
----boundary-LibPST-iamunique-1481736554_-_---
Received on Thu Jan 31 2008 - 14:03:27 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:31:05 UTC