The operators shown below are in DXL out of the box. - -- ! != % %= & && &= (&) (*) * *= . .. / /= ? [] ^ _-- _++ | || |= ~ + ++ += < <- <? << = -= == > -> >? >= >>
by default do for if sizeof while
SystemAdmin - Wed Feb 23 11:38:43 EST 2011 |
Re: DXL Operators, What Symbols are Fair Game?
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!)
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"
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"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
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!)
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"
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"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
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? SystemAdmin - Mon Feb 28 12:41:33 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
*/
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
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: DXL Operators, What Symbols are Fair Game? 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
*/
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
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) {
string ::demoTitle(Demo demo) { Demo demo = initDemo("Some Value"); print demoTitle(demo); This works like: struct Demo {};
Demo initDemo(string sDemoTitle) {
string demoTitle(Demo demo) { Demo demo = initDemo("Some Value"); print demoTitle(demo); Best regards Wolfgang |
Re: DXL Operators, What Symbols are Fair Game? 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) {
string ::demoTitle(Demo demo) { Demo demo = initDemo("Some Value"); print demoTitle(demo); This works like: struct Demo {};
Demo initDemo(string sDemoTitle) {
string demoTitle(Demo demo) { 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? 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 |