Type inheritance constraint syntax query

This forum is for any questions about the language Tutorial D or the Rel implementation of it.
Post Reply
Chris Walton
Posts: 76
Joined: Sat Aug 18, 2012 2:13 pm

Type inheritance constraint syntax query

Post by Chris Walton »

Given:
TYPE P POSSREP { VALUE CHAR } ;
VAR S BASE RELATION { X1 P, X2 INT } KEY { X2 } ;
S := RELATION { TUPLE { X1 P ( "T1" ), X2 INTEGER ( 1 ) }, TUPLE { X1 P ( "T2" ), X2 INTEGER ( 2 ) } };

What syntax defines TYPE Q IS { P CONSTRAINT **see below** POSSREP { VALUE = THE_VALUE ( P ) } } ; ?

The constraint is that the range for Q is only those values that appear in S.X1 (ie the range of Q is T1, T2 only).

I have tried multiple ways of defining this, but cannot get the syntax correct. The best I have achieved is:
TYPE Q IS { P CONSTRAINT TUPLE { X1 P ( THE_VALUE ( P ) ) } IN S { X1 } POSSREP { VALUE = THE_VALUE ( P ) } } ;
which gives an infinite loop in Rel.
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Type inheritance constraint syntax query

Post by Dave »

I'm not sure I understand what you're trying to create, but I suspect the infinite loop is the same bug reported at http://shark.armchair.mb.ca/~dave/relfo ... ?f=2&t=957

It should be corrected in the next update.
Chris Walton
Posts: 76
Joined: Sat Aug 18, 2012 2:13 pm

Re: Type inheritance constraint syntax query

Post by Chris Walton »

In trying to simplify my query, I made a mistake in the statements listed. Sorting it out also sorted out my original query.
What I was trying to do was to define a (inherited) type whose values depended on the values in a (lookup) relvar.

As this was a bit of a red herring, might I suggest you either delete this thread, or leave it with the corrected (and now solved) query:

Given:
TYPE P POSSREP { VALUE CHAR } ;
VAR S BASE RELATION { X1 P, X2 INT } KEY { X2 } ;
S := RELATION { TUPLE { X1 "T1", X2 INTEGER ( 1 ) }, TUPLE { X1 "T2", X2 INTEGER ( 2 ) } };

The syntax that defines a constraint that the range of Q is those values that appear in S.X1 (ie the range of Q is T1, T2 only) is:
TYPE Q IS { P CONSTRAINT TUPLE { X1 P } IN S { X1 } POSSREP { VALUE = THE_VALUE ( P ) } } ;
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Type inheritance constraint syntax query

Post by Dave »

I'll leave it. This discussion and resulting query might be helpful to someone else.
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Type inheritance constraint syntax query

Post by Dave »

This is definitely the same bug reported at http://shark.armchair.mb.ca/~dave/relfo ... ?f=2&t=957

A workaround is to define this...

Code: Select all

TYPE Q IS { P CONSTRAINT TUPLE { X1 P } IN S { X1 } POSSREP { VALUE = THE_VALUE ( P ) } } ;
...as this:

Code: Select all

TYPE Q IS { P CONSTRAINT TUPLE { X1 P } IN S { X1 } POSSREP { X = THE_VALUE ( P ) } } ;
The problem is that VALUE is already defined in TYPE P. The attempted redefinition of VALUE in TYPE Q causes an infinite loop.

This should be fixed one way (prevent infinite loop) or another (prevent redefinition of supertype POSSREP components) in the next Rel update.
Chris Walton
Posts: 76
Joined: Sat Aug 18, 2012 2:13 pm

Re: Type inheritance constraint syntax query

Post by Chris Walton »

Thanks for the workaround - I do keep bumping into this issue from a variety of directions, and had not come up with a solution for myself.
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Type inheritance constraint syntax query

Post by Dave »

Please let me know if you find any code for which the workaround doesn't work.
Post Reply