DXL Operators, What Symbols are Fair Game?

The operators shown below are in DXL out of the box.

Operators may be unary, binary, or ternary.

I think the ternary operators are built-in only (or not so obvious how to make one in any event).

Here are some questions:
[A] What is fair game for usage as a symbol for a user-defined DXL operator? Are we limited to the symbol set shown in the first table below?

[B] As pointed out in another post, defining an "=" operator seems to break the functionality of DxlObject assignment (a rather nasty side effect). See http://www.ibm.com/developerworks/forums/thread.jspa?messageID=14583124 Are there any other "stay away from these operators" jeers from the crowd?
 

-        --        !         !=        %         %=
&        &&        &=        (&)       (*)       *      
*=       .         ..        /         /=        ?   
[]       ^         _--       _++       |         ||
|=       ~         +         ++        +=        <  
<-       <?        <<        =         -=        == 
>        ->        >?        >=        >>

 

by      default    do        for       
if      sizeof     while

 


SystemAdmin - Wed Feb 23 11:38:43 EST 2011

Re: DXL Operators, What Symbols are Fair Game?
Mathias Mamsch - Sun Feb 27 13:46:12 EST 2011

You forgot some of the undocumented nifty operators. Here is a (hopefully) complete list:
 

ternary (a, b, c used for operands):
if a (then) b else c        
for a in b do c        
a ? b : c
a : b by c
 
Binary (a and b used for operands): 
a->b   a<->b   a.b   a@b    a/b   a^^b   a*b   a\b   a%b   a+b   a-b
a<<b   a>>b   ab   a<?b   a>?b  a<b a>b   a<=b  a>=b  a==b  a!=b
a&b    a^b    a|b    a&&b   a||b  a<-b   a:=b  a=>b   
a=b    a+=b   a-=b   a*=b   a/=b  a%=b   a<<=b a>>=b   a&=b   a|=b   a^=b
a b (concatenation -> ::.. )  a[b] 
 
Unary: (a used as operand): 
++a   a++   a--   --a   ~a   -a   +a   $a   !a   *a   &a   
sizeof (yes this is an operator!)

 


You can test the overwritablity of the operators by the following code (just replace the - operator with one of the operators above.

 

 

struct testUnary {};  int ::- (testUnary a) { return 5 }
testUnary x = null; print ( - x ) "\n"
 
struct testBinary {}; testBinary a = null, b = null; 
int       ::-(testBinary a, testBinary b) { return 5 }
print     (a-b) "\n"



Regarding your question, I think that breaking of DxlObject in the post you mentioned is a one time thing (caused by ambiguous declaration of DxlObject operators) and should not happen with the other operators. Did not try out all of them of course ;-)

And by the way: You can do at least the ternary operators that don't take code blocks as a parameter:



 

 

 

struct testTernary {}; testBinary d = null, e = null, f = null
int       ::by(testBinary a, testBinary b, testBinary c) { return 5 }
 
print (d:e by f) "\n"


Regards, Mathias

 

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: DXL Operators, What Symbols are Fair Game?
SystemAdmin - Mon Feb 28 12:41:33 EST 2011

Mathias Mamsch - Sun Feb 27 13:46:12 EST 2011

You forgot some of the undocumented nifty operators. Here is a (hopefully) complete list:
 

ternary (a, b, c used for operands):
if a (then) b else c        
for a in b do c        
a ? b : c
a : b by c
 
Binary (a and b used for operands): 
a->b   a<->b   a.b   a@b    a/b   a^^b   a*b   a\b   a%b   a+b   a-b
a<<b   a>>b   ab   a<?b   a>?b  a<b a>b   a<=b  a>=b  a==b  a!=b
a&b    a^b    a|b    a&&b   a||b  a<-b   a:=b  a=>b   
a=b    a+=b   a-=b   a*=b   a/=b  a%=b   a<<=b a>>=b   a&=b   a|=b   a^=b
a b (concatenation -> ::.. )  a[b] 
 
Unary: (a used as operand): 
++a   a++   a--   --a   ~a   -a   +a   $a   !a   *a   &a   
sizeof (yes this is an operator!)

 


You can test the overwritablity of the operators by the following code (just replace the - operator with one of the operators above.

 

 

struct testUnary {};  int ::- (testUnary a) { return 5 }
testUnary x = null; print ( - x ) "\n"
 
struct testBinary {}; testBinary a = null, b = null; 
int       ::-(testBinary a, testBinary b) { return 5 }
print     (a-b) "\n"



Regarding your question, I think that breaking of DxlObject in the post you mentioned is a one time thing (caused by ambiguous declaration of DxlObject operators) and should not happen with the other operators. Did not try out all of them of course ;-)

And by the way: You can do at least the ternary operators that don't take code blocks as a parameter:



 

 

 

struct testTernary {}; testBinary d = null, e = null, f = null
int       ::by(testBinary a, testBinary b, testBinary c) { return 5 }
 
print (d:e by f) "\n"


Regards, Mathias

 

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Mathias,
Could you provide a simple example of how to use the iterators (do, for and while are mentioned in the first post) for custom structures? Or are they not valid operators?

Re: DXL Operators, What Symbols are Fair Game?
Mathias Mamsch - Mon Feb 28 15:14:39 EST 2011

SystemAdmin - Mon Feb 28 12:41:33 EST 2011
Mathias,
Could you provide a simple example of how to use the iterators (do, for and while are mentioned in the first post) for custom structures? Or are they not valid operators?

Unfortunately you can't. I mean you can override them:
 

struct test {}
void ::do (test a, test b, test c) {
    int var = 1337
    print "A at " ((addr_ (&a)) int) " = " ((addr_ a) int) "\n"
    print "B at "  ((addr_ (&b)) int) " = " ((addr_ b) int)  "\n"
    print "C at "  ((addr_ (&c)) int) " = " ((addr_ c) int)  "\n"
    print "var at "  ((addr_ (&var)) int) " = " ((addr_ var) int)  "\n"
}
 
test a = addr_ 0, b = addr_ 1, c = addr_ 2
for a in b do c 
/* prints something like
A at 107100248 = 0
B at 107100252 = 1
C at 107100256 = 1337
var at 107100256 = 1337
*/

 


As you can see, I can override the iterator and even call it. You see from the result, that the third parameter is NOT put to the stack, so while DXL thinks that there is a third argument, there isnt. Therefore if you put a real statement in there (and change the 3rd Parameter to void, so the for will take code blocks) ...

 

 

 

struct test {}
void ::do (test a, test b, void) { print "Inside operator.\n" }
test a = null, b = null
for a in b do print "YES!"
// prints YES!Inside operator



then you can see,that the statement is executed like any other DXL operator/function. The expression argument print "YES" is evaluated first, then the operands are passed to the ::do operator. So you have no chance of redefining the for loop. The whole statement does not behave like a loop anymore, more like the ? : operator for example. The same is true for the "::if" operator and the ::? operator. Only the ::by operator works, since it does not take those code expressions as parameter.

Hope that clears matters up, regards, Mathias



 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: DXL Operators, What Symbols are Fair Game?
Wolfgang Uhr - Mon Aug 17 11:27:06 EDT 2015

Mathias Mamsch - Mon Feb 28 15:14:39 EST 2011

Unfortunately you can't. I mean you can override them:
 

struct test {}
void ::do (test a, test b, test c) {
    int var = 1337
    print "A at " ((addr_ (&a)) int) " = " ((addr_ a) int) "\n"
    print "B at "  ((addr_ (&b)) int) " = " ((addr_ b) int)  "\n"
    print "C at "  ((addr_ (&c)) int) " = " ((addr_ c) int)  "\n"
    print "var at "  ((addr_ (&var)) int) " = " ((addr_ var) int)  "\n"
}
 
test a = addr_ 0, b = addr_ 1, c = addr_ 2
for a in b do c 
/* prints something like
A at 107100248 = 0
B at 107100252 = 1
C at 107100256 = 1337
var at 107100256 = 1337
*/

 


As you can see, I can override the iterator and even call it. You see from the result, that the third parameter is NOT put to the stack, so while DXL thinks that there is a third argument, there isnt. Therefore if you put a real statement in there (and change the 3rd Parameter to void, so the for will take code blocks) ...

 

 

 

struct test {}
void ::do (test a, test b, void) { print "Inside operator.\n" }
test a = null, b = null
for a in b do print "YES!"
// prints YES!Inside operator



then you can see,that the statement is executed like any other DXL operator/function. The expression argument print "YES" is evaluated first, then the operands are passed to the ::do operator. So you have no chance of redefining the for loop. The whole statement does not behave like a loop anymore, more like the ? : operator for example. The same is true for the "::if" operator and the ::? operator. Only the ::by operator works, since it does not take those code expressions as parameter.

Hope that clears matters up, regards, Mathias



 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Hi Mathias

Every string can be used as an operator:

struct Demo {};

Demo ::initDemo(string sDemoTitle) {
Skip skpSC = createString();
put (skpSC, "sDemoTitle", sDemoTitle);
return(Demo addr_(skpSC));
}

string ::demoTitle(Demo demo) {
Skip skpSC = (Skip addr_(demo));
string sDemoTitle;
if (find(skpSC, "sDemoTitle", sDemoTitle)) {
return (sDemoTitle);
}
return ("");
}

Demo demo = initDemo("Some Value");

print demoTitle(demo);

This works like:

struct Demo {};

Demo initDemo(string sDemoTitle) {
Skip skpSC = createString();
put (skpSC, "sDemoTitle", sDemoTitle);
return(Demo addr_(skpSC));
}

string demoTitle(Demo demo) {
Skip skpSC = (Skip addr_(demo));
string sDemoTitle;
if (find(skpSC, "sDemoTitle", sDemoTitle)) {
return (sDemoTitle);
}
return ("");
}

Demo demo = initDemo("Some Value");

print demoTitle(demo);

Best regards

Wolfgang

Re: DXL Operators, What Symbols are Fair Game?
Mathias Mamsch - Mon Aug 17 12:14:09 EDT 2015

Wolfgang Uhr - Mon Aug 17 11:27:06 EDT 2015

Hi Mathias

Every string can be used as an operator:

struct Demo {};

Demo ::initDemo(string sDemoTitle) {
Skip skpSC = createString();
put (skpSC, "sDemoTitle", sDemoTitle);
return(Demo addr_(skpSC));
}

string ::demoTitle(Demo demo) {
Skip skpSC = (Skip addr_(demo));
string sDemoTitle;
if (find(skpSC, "sDemoTitle", sDemoTitle)) {
return (sDemoTitle);
}
return ("");
}

Demo demo = initDemo("Some Value");

print demoTitle(demo);

This works like:

struct Demo {};

Demo initDemo(string sDemoTitle) {
Skip skpSC = createString();
put (skpSC, "sDemoTitle", sDemoTitle);
return(Demo addr_(skpSC));
}

string demoTitle(Demo demo) {
Skip skpSC = (Skip addr_(demo));
string sDemoTitle;
if (find(skpSC, "sDemoTitle", sDemoTitle)) {
return (sDemoTitle);
}
return ("");
}

Demo demo = initDemo("Some Value");

print demoTitle(demo);

Best regards

Wolfgang

Well for me an operator is more than a function declaration with a "::" in the name. First of all, there are no operators with no parameters.

void ::test() { print "Hallo" }
test()

Additionally it should not be possible to call a normal function like an "operator"
 

void test() { print "Hallo" }
::test()

but this also works. To me it seems, that DXL will simply ignore the "::" in the function declaration and also when calling a function. Note that this also works with variables.

int ::a = 4
print a

One more reason to think, that this has nothing to do with operators. There is other stuff that DXL will ignore, like "static" or "const" modifiers in declarations.

Regards, Mathias

Re: DXL Operators, What Symbols are Fair Game?
Wolfgang Uhr - Tue Aug 18 02:12:42 EDT 2015

Mathias Mamsch - Mon Aug 17 12:14:09 EDT 2015

Well for me an operator is more than a function declaration with a "::" in the name. First of all, there are no operators with no parameters.

void ::test() { print "Hallo" }
test()

Additionally it should not be possible to call a normal function like an "operator"
 

void test() { print "Hallo" }
::test()

but this also works. To me it seems, that DXL will simply ignore the "::" in the function declaration and also when calling a function. Note that this also works with variables.

int ::a = 4
print a

One more reason to think, that this has nothing to do with operators. There is other stuff that DXL will ignore, like "static" or "const" modifiers in declarations.

Regards, Mathias

Hi Mathias

> Well for me an operator is more than a function declaration with a "::" in the name. First of all, there are no operators with no parameters.

For me too and now I see the differences. In your example you cannot omit "::".

Best regards

Wolfgang