Specialisation by constraint

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

Specialisation by constraint

Post by Chris Walton »

After, I hope, learning a little about SbyC from the TTM mailing list, I used a variety of simple expressions to explore the behaviour of Rel in this respect. I have encountered a number of unexpected results and details are given below.

Code: Select all

  INTEGER(10)
  10

  OP_PLUS ( 10, 10 )
  20

  TYPE Ntest1 POSSREP { VALUE INTEGER CONSTRAINT VALUE >= 0 };
Ok

Code: Select all

  Ntest1(10)
  Ntest1(10)

  INTEGER(Ntest1(10))
  ERROR: Could not find operator INTEGER(Ntest1) Line 1, column 16 near '10'
OK so a new type needs its operators declared explicitly

Code: Select all

  OP_PLUS ( INTEGER ( 10 ), INTEGER ( 10 ) )
  20

  TYPE Ntest2 IS { INTEGER POSSREP { VALUE INTEGER CONSTRAINT VALUE < 10 } };
Ok.

Code: Select all

  Ntest2 ( 9 )
  Ntest2("[null-Ntest2-null]")
What is going on here?
There is no type with a structure like this, so it does not seem to be the MST
From the syntax of Rel, "[" is only used in the definition:
` basic_expression := order_expression ( "[" expression "]" )?
Surely "null" is specifically excluded from TTM.
In addition, when this is input, the following messages occur in DBrowser Monitor
(and continue to generate similar messages for all subsequent tests.:

Code: Select all

  ValueAlpha: invalid component at 7 size of internal is 9 type is Ntest2
  ValueAlpha:  internal[0] is null
  ValueAlpha:  internal[1] is 9
  ValueAlpha:  internal[2] is null
  ValueAlpha:  internal[3] is null
  ValueAlpha:  internal[4] is null
  ValueAlpha:  internal[5] is null
  ValueAlpha:  internal[6] is null
  ValueAlpha:  internal[7] is null
  ValueAlpha:  internal[8] is null
  ValueAlpha: invalid component at 7 size of internal is 9 type is Ntest2
  ValueAlpha:  internal[0] is null
  ValueAlpha:  internal[1] is 9
  ValueAlpha:  internal[2] is null
  ValueAlpha:  internal[3] is null
  ValueAlpha:  internal[4] is null
  ValueAlpha:  internal[5] is null
  ValueAlpha:  internal[6] is null
  ValueAlpha:  internal[7] is null
  ValueAlpha:  internal[8] is null
  PanelCommandline: Unable to locate error in   
    used by OPERATOR Ntest21(Ntest2)
    used by OPERATOR THE_VALUE(Ntest21)
    used by TYPE Ntest21
Line 1

Code: Select all

INTEGER ( Ntest2 ( 9 ) )  
  ERROR: Cannot convert a Ntest2 to a primitive value. Line 1, column 20 near '9'
// Surely it should be possible to use a subtype wherever a supertype is defined?

Code: Select all

  TYPE Ntest21 IS { Ntest2 POSSREP { VALUE Ntest2 CONSTRAINT VALUE < 8 } };
Ok.

Code: Select all

  Ntest21 ( 7 )
  Ntest21(Ntest21(7))
// Not what I expected, but I can see how it arises.

Code: Select all

  TYPE Ntest12 IS { Ntest1 POSSREP { VALUE Ntest1 CONSTRAINT VALUE < 7 } };
Ok.

Code: Select all

  Ntest12 ( 8 )
  ERROR: Could not find operator Ntest12(INTEGER) Line 1, column 11 near '8'
This is a subtype so why does it not give the MST? Compare to:

Code: Select all

  Ntest21 ( 5 )
  Ntest21(Ntest21(5))

INTEGER(10)
Ntest21(10)
Ok
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Specialisation by constraint

Post by Dave »

I'm not clear what this is:

Ntest2 ( 9 )
Ntest2("[null-Ntest2-null]")

Was this output that appeared as the result of entering an expression? If so, that's definitely a bug. Or were those a pair of expressions you entered?

Or was the first line the expression and the second the result? If so, the result is a bug.

I note that you're inheriting from INTEGER. Inheriting from built-in types is a relatively new addition that's received limited use and testing. Bugs are to be expected. :D
Chris Walton
Posts: 76
Joined: Sat Aug 18, 2012 2:13 pm

Re: Specialisation by constraint

Post by Chris Walton »

In each case, where there are a pair of lines the first line is my input and the second the response. So
Ntest2 ( 9 )
Ntest2("[null-Ntest2-null]")
I entered Ntest2(9) and got the response Ntest2("[null-Ntest2-null]").
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Specialisation by constraint

Post by Dave »

Strange. I'm unable to duplicate the problem.

Given NTest2(9), I get NTest2(NTest2(9)), which is what I would expect given that Ntest2 is defined as TYPE Ntest2 IS { INTEGER POSSREP { VALUE INTEGER CONSTRAINT VALUE < 10 } }. This defines Ntest2 as being inherited from INTEGER and possessing an additional POSSREP composed of VALUE INTEGER. I'm not clear what you're trying to define, but my result is consistent with that definition.

I wonder if this is what you intended:

Code: Select all

TYPE Ntest2 IS { INTEGER  CONSTRAINT INTEGER < 10 };
Chris Walton
Posts: 76
Joined: Sat Aug 18, 2012 2:13 pm

Re: Specialisation by constraint

Post by Chris Walton »

My aim in these examples was simply exploring the behaviour of types further, to assist me in writing operators. The examples were an attempt to do this exploration with the minimum of "clutter". What I was doing (I thought) was to define a type without inheritance Ntest1; and a type with SbyC from integer Ntest2; I then inherited from each of these types using SbyC giving Ntest12 and Ntest21. The code I put in the posting was where I had a question, with a few further examples to give the context of my questions. Your code does do what I was trying to do. Given my definition, like you I would have expected Ntest2(Ntest2(9)), but got the peculiar response in its place.

I will try to recreate my problems, and try to find another way to reproduce them but this may take me a few days.
Last edited by Chris Walton on Fri Oct 25, 2013 11:39 am, edited 1 time in total.
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Specialisation by constraint

Post by Dave »

Just had a thought regarding the Ntest2("[null-Ntest2-null]") result... Do you have more than one type inherited from INTEGER? If so, that might have exposed a bug.
Chris Walton
Posts: 76
Joined: Sat Aug 18, 2012 2:13 pm

Re: Specialisation by constraint

Post by Chris Walton »

Yes I do have more than one type inherited from integer - see my last post. I have one type inheriting directly from integer, with a subtype inheriting from that type; and one type defined without inheritance, but also with a subtype inheriting from it. In addition because I was exploring inheritance, I had had many more types inheriting from integer that had subsequently been dropped.
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

Re: Specialisation by constraint

Post by Dave »

Could you send me (or upload) a backup script of your database? I suspect the problem lies in the fact that there are a number of types inherited from INTEGER. In and of itself, that shouldn't cause a problem, so I'd like to see what's happening internally with the particular set of types you've created.
Chris Walton
Posts: 76
Joined: Sat Aug 18, 2012 2:13 pm

Re: Specialisation by constraint

Post by Chris Walton »

Backup attached.
Attachments
relbackup___2013_October_25_06_54_PM.d
(15.53 KiB) Downloaded 481 times
Post Reply