Page 1 of 1

Type inheritance constraint syntax query

Posted: Wed Aug 07, 2013 10:15 am
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.

Re: Type inheritance constraint syntax query

Posted: Wed Aug 07, 2013 10:57 am
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.

Re: Type inheritance constraint syntax query

Posted: Wed Aug 07, 2013 4:42 pm
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 ) } } ;

Re: Type inheritance constraint syntax query

Posted: Wed Aug 07, 2013 9:46 pm
by Dave
I'll leave it. This discussion and resulting query might be helpful to someone else.

Re: Type inheritance constraint syntax query

Posted: Tue Aug 13, 2013 10:38 pm
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.

Re: Type inheritance constraint syntax query

Posted: Fri Aug 16, 2013 2:34 pm
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.

Re: Type inheritance constraint syntax query

Posted: Fri Aug 16, 2013 5:50 pm
by Dave
Please let me know if you find any code for which the workaround doesn't work.