Page 1 of 1

Relation valued parameters

Posted: Fri Sep 27, 2013 3:15 pm
by Chris Walton
Is it possible to define operators which have, as their parameters, relations of any type? Below is my naive attempt to define such an operator.

OPERATOR test ( P RELATION, Q RELATION ) RETURNS RELATION;
return P JOIN Q;
END OPERATOR ;

Re: Relation valued parameters

Posted: Sun Sep 29, 2013 11:34 pm
by steved
Hello Chris,
I'd be very surprised if you could do something like that:) But you could create operators (and their overloads) dynamically (using EXECUTE).

Best,
steve dassin

Re: Relation valued parameters

Posted: Mon Sep 30, 2013 4:03 pm
by Chris Walton
Could you possibly expand on your suggestion a little - would the syntax simply be execute.......(the listing of my statement)? I am finding that I am writing quite a lot of boilerplate code such as:
VAR Dir VIEW WITH (
A := ( sys.Catalog WHERE Owner <> "Rel" ) { Name, Definition },
B := ( EXTEND Relvar_predicate :
{ Name := TREAT_AS_CHARACTER ( name ),
Predicate := TREAT_AS_CHARACTER ( predicate ) }
{ ALL BUT name, predicate } ),
***Begin Boilerplate***
C := A { Name } NOT MATCHING B { Name },
D := EXTEND A : { Predicate := "" },
E := A JOIN B, F := C JOIN D ):
E { Name, Predicate, Definition } UNION F;
***End Boilerplate***
While part of my investigating this possibility is sheer laziness (I don't like all the repetitive typing), in the past repetition of definitions or part definitions (as here) has been a warning sign of poor design and/or a potential source of error and version problems.

Re: Relation valued parameters

Posted: Mon Sep 30, 2013 5:04 pm
by Dave
There's been some discussion about being able to define generics -- they would be very handy for defining your own relational operators, for example -- but nothing has, to my recollection, yet made it into the Tutorial D specification. For now, using EXECUTE is certainly a way forward. Take a look at the Rel backup script, DatabaseToScript.d (found in the Scripts folder) for an example.

Re: Relation valued parameters

Posted: Tue Oct 01, 2013 12:10 pm
by Chris Walton
Thanks for the pointer to an example - I'll pursue that.

Re: Relation valued parameters

Posted: Mon Oct 07, 2013 10:44 am
by HughDarwen
See TTM Very Strong Suggestion 6.

Business System 12, an interpreter, supported such operators back in 1980.

Hugh