Re: [BLACKBOX] Sorting Extended Records

From: [at]} <Alexander>
Date: Tue, 29 Mar 2011 00:03:20 +0700

----boundary-LibPST-iamunique-1033522980_-_-
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.

  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-1033522980_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIEhlbGxvIVxwYXINClxwYXINClNSV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XMgImZlYXR1cmUiIG9mIEJsYWNrQm94
IENvbXBvbmVudCBQYXNjYWwgaXMgYW4gaW1wcm92ZW1lbnQuIFxwYXINClNSVD4gSGFzIGFueWJv
ZHkgZm91bmQgYSB3YXkgdG8gaGFuZGxlIHRoaXMgaXNzdWU/ICBBbnkgc3VnZ2VzdGlvbnNccGFy
DQpTUlQ+IHdvdWxkIGJlIG11Y2ggYXBwcmVjaWF0ZWQuXHBhcg0KXHBhcg0KICBVc2UgdHlwZSBn
dWFyZDpccGFyDQogIFZBUiBiYXNlOiBCYXNlVHlwZTsgZXh0ZW5kZWQ6IEV4dGVuZGVkVHlwZTtc
cGFyDQogIEJFR0lOXHBhcg0KICAgICAgYmFzZSA6PSBleHRlbmRlZDsgKCogQWx3YXlzIHdvcmtz
LiAqKVxwYXINCiAgICAgIGV4dGVuZGVkIDo9IGJhc2UoRXh0ZW5kZWRUeXBlKTsgKCogV29ya3Mg
b25seSBpZiAnYmFzZScgaXNccGFyDQogICAgICBhY3R1YWxseSBhIHBvaW50ZXIgdG8gYW4gJ0V4
dGVuZGVkVHlwZScgaW5zdGFuY2UsIHRyYXBzXHBhcg0KICAgICAgb3RoZXJ3aXNlLiAgKilccGFy
DQpccGFyDQotLS09PT09PS0tLVxwYXINCiBBbGV4YW5kZXJccGFyDQpccGFyDQpccGFyDQotLS0t
XHBhcg0KVG8gdW5zdWJzY3JpYmUsIHNlbmQgYSBtZXNzYWdlIHdpdGggYm9keSAiU0lHTk9GRiBC
TEFDS0JPWCIgdG8gTElTVFNFUlZATElTVFMuT0JFUk9OLkNIfX0AcmliZQ=
----boundary-LibPST-iamunique-1033522980_-_---
Received on Mon Mar 28 2011 - 19:03:20 UTC

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