Re: [BLACKBOX] Sorting Extended Records

From: [at]} <Alexander>
Date: Tue, 29 Mar 2011 00:12:43 +0600

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

Hello!

SRT>> In Component Pascal I wrote the common part of the records as an
SRT>> Extensible (base) record type, and then each of the three record
SRT>> types as extensions of that base type.

AI> Why use extenstions and not the base type?

  Sorry, I misquoted, that question was aimed at the following sentence:

SRT> I refer to each of the three binary trees by a root variable
SRT> which is a pointer to the corresponding extended record type.

  Why use extenstions and not the base type?

SRT> HOWEVER, in general sorting and balancing a binary tree causes
SRT> the root to change, and Component Pascal will not allow assigning
SRT> the value of a pointer to a base record, back to a pointer to an
SRT> extended record. Apparently this means I have to include three
SRT> separate but nearly-identical versions of the sorting routine,
SRT> one for each extended record type, which seems incredibly ugly,
SRT> inefficient, and error-prone. I am having trouble seeing how
SRT> this "feature" of BlackBox Component Pascal is an improvement.
SRT> Has anybody found a way to handle this issue? Any suggestions
SRT> would be much appreciated.

  Use type guard:
  VAR base: BaseType; extended: ExtendedType;
  BEGIN
      base := extended; (* Always works. *)
      extended := base(ExtendedType); (* Works only if 'base' is
      actually a pointer to an 'ExtendedType' instance, traps
      otherwise. *)

---===---
 Alexander


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1207817128_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmV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W5kZWRUeXBlJyBpbnN0YW5jZSwgdHJhcHNccGFyDQogICAgICBvdGhlcndp
c2UuICAqKVxwYXINClxwYXINCi0tLT09PT09LS0tXHBhcg0KIEFsZXhhbmRlclxwYXINClxwYXIN
ClxwYXINCi0tLS1ccGFyDQpUbyB1bnN1YnNjcmliZSwgc2VuZCBhIG1lc3NhZ2Ugd2l0aCBib2R5
ICJTSUdOT0ZGIEJMQUNLQk9YIiB0byBMSVNUU0VSVkBMSVNUUy5PQkVST04uQ0h9fQACAAAA
----boundary-LibPST-iamunique-1207817128_-_---
Received on Mon Mar 28 2011 - 20:12:43 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:16 UTC