Re: [BLACKBOX] Variant Records vs. Component Pascal

From: [at]} <Bob>
Date: Sun, 3 Jan 2010 19:07:31 -0000

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

I amended my little example to add a type bound comparison procedure to the
Figure and Circle types. The Circle procedure demonstrates the use of IS and
WITH. The Rectangle is left as an exercise ;0)

Voila:

CONST
        less = -1; equal = 0; greater = 1;

...

PROCEDURE ( this: Figure ) Compare( that: Figure ): INTEGER, NEW,
EXTENSIBLE;
VAR
        result: INTEGER;
BEGIN
        IF this.key < that.key THEN
                result := less;
        ELSIF this.key > that.key THEN
                result := greater
        ELSIF this.x < that.x THEN
                result := less
        ELSIF this.x > that.x THEN
                result := greater
        ELSIF this.y < that.y THEN
                result := less
        ELSIF this.y > that.y THEN
                result := greater
        ELSE
                result := equal;
        END;
        RETURN result;
END Compare;

PROCEDURE ( this: Circle ) Compare( that: Figure ): INTEGER;
VAR
        result: INTEGER;
BEGIN
        result := this.Compare^( that );
        IF (result = equal) & (that IS Circle) THEN
                WITH that: Circle DO
                        IF this.r < that.r THEN
                                result := less
                        ELSIF this.r > that.r THEN
                                result := greater
                        ELSE
                                result := equal
                        END
                END;
        END;
        RETURN result;
END Compare;
 

> -----Original Message-----
> From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xy
> Bernhard Treutwein
> Sent: 02 January 2010 17:36
> To: BLACKBOX{([at]})nowhere.xy
> Subject: Re: [BLACKBOX] Variant Records vs. Component Pascal
>
> Hi Stephen,
>
> maybe you'll need a type bound procedure (defined as ABSTRACT
> for the base
> type) which
> defines your ordering relations, which is called as
>
> IF myrec.Order() = less THEN ...
>
> Here your comparision is handed to the type-bound procedure,
> which is unknown beforehand.
>
> The other solution is a less generic sort routine, which has
> the base type as parameter, and a type test for the actual
> type. In this case you have to know (and import) all possible
> extension beforehand.
>
> and again: Mössenböck's book is an excellent starting point.
>
> Bernhard
>
> ----- Original Message -----
> From: Stephen R. Troy
> To: BLACKBOX{([at]})nowhere.xy
> Sent: Friday, January 01, 2010 8:10 PM
> Subject: Re: [BLACKBOX] Variant Records vs. Component Pascal
>
>
> Thanks to Douglas and Bob for their quick replies, regarding
> my problem
> migrating a database using Modula-2 variant records to
> Component Pascal. In
> Modula-2, I had variant records, and was able to use the same sorting
> routine with each of the variants.
> In Component Pascal I tried using a base EXTENSIBLE record,
> and each of the
> variant record types as an extension of the base. The
> problem was that I
> couldn't pass each of the variants to the sorting routine,
> and it looked as
> though I would need a separate sorting routine for each variant.
>
>
> Douglas's method looks like it would work if indeed I did all
> my sorting on
> variables that were common to the base record type, but alas
> that is pretty
> limiting. Bob's method looks like it might solve my problem,
> but I'll have
> to bang my head with a brick some more to be sure I
> understand it. Thanks
> again and Happy New Year to both of you!
>
>
> Steve Troy
>
>
> ---- To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to
> LISTSERV{([at]})nowhere.xy
>
>
> ----
> To unsubscribe, send a message with body "SIGNOFF BLACKBOX"
> to LISTSERV{([at]})nowhere.xy


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1663901816_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzc1xmY2hhcnNldDAgQXJpYWw7fQ0Ke1xmMVxmbW9kZXJuIENvdXJpZXIgTmV3O30NCntcZjJc
Zm5pbFxmY2hhcnNldDIgU3ltYm9sO30NCntcZjNcZm1vZGVyblxmY2hhcnNldDAgQ291cmllciBO
ZXc7fX0NCntcY29sb3J0YmxccmVkMFxncmVlbjBcYmx1ZTA7XHJlZDBcZ3JlZW4wXGJsdWUyNTU7
fQ0KXHVjMVxwYXJkXHBsYWluXGRlZnRhYjM2MCBcZjBcZnMyMCBJIGFtZW5kZWQgbXkgbGl0dGxl
IGV4YW1wbGUgdG8gYWRkIG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RiBCTEFDS0JPWCIgdG8gXHBhcg0KPiBM
SVNUU0VSVkBMSVNUUy5PQkVST04uQ0ggXHBhcg0KPiBccGFyDQo+IFxwYXINCj4gLS0tLVxwYXIN
Cj4gVG8gdW5zdWJzY3JpYmUsIHNlbmQgYSBtZXNzYWdlIHdpdGggYm9keSAiU0lHTk9GRiBCTEFD
S0JPWCIgXHBhcg0KPiB0byBMSVNUU0VSVkBMSVNUUy5PQkVST04uQ0hccGFyDQpccGFyDQpccGFy
DQotLS0tXHBhcg0KVG8gdW5zdWJzY3JpYmUsIHNlbmQgYSBtZXNzYWdlIHdpdGggYm9keSAiU0lH
Tk9GRiBCTEFDS0JPWCIgdG8gTElTVFNFUlZATElTVFMuT0J9fQBsPg0KUHJlY2VkZQ=
----boundary-LibPST-iamunique-1663901816_-_---
Received on Sun Jan 03 2010 - 20:07:31 UTC

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