Relation valued parameters

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

Relation valued parameters

Post by Chris Walton » Fri Sep 27, 2013 3:15 pm

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 ;

steved
Posts: 49
Joined: Sun Sep 01, 2013 10:53 pm

Re: Relation valued parameters

Post by steved » Sun Sep 29, 2013 11:34 pm

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

Chris Walton
Posts: 76
Joined: Sat Aug 18, 2012 2:13 pm

Re: Relation valued parameters

Post by Chris Walton » Mon Sep 30, 2013 4:03 pm

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.

Dave
Site Admin
Posts: 364
Joined: Sun Nov 27, 2005 7:19 pm

Re: Relation valued parameters

Post by Dave » Mon Sep 30, 2013 5:04 pm

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.

Chris Walton
Posts: 76
Joined: Sat Aug 18, 2012 2:13 pm

Re: Relation valued parameters

Post by Chris Walton » Tue Oct 01, 2013 12:10 pm

Thanks for the pointer to an example - I'll pursue that.

HughDarwen
Posts: 118
Joined: Sat May 24, 2008 4:49 pm

Re: Relation valued parameters

Post by HughDarwen » Mon Oct 07, 2013 10:44 am

See TTM Very Strong Suggestion 6.

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

Hugh

Post Reply