Casting a skip into a DxlObject

Hi, 

What is the deal with DxlObjects, there is absolutely no documentation on this data structure in the 9.5 reference manual.

I am trying to recuperate the contents of a DxlObject that I have stored in a skipList.using the following syntax:

DxlObject currDiscussion = skip_post_snapshot_disc[keyStr] DxlObject

However this give me an error message: "incorrect context for binary op ([)"

 

Previously (in a different script) I was able to recuperate the contents of a DxlObject from a skip using a for loop 

DxlObject hist = new

for hist in skipHistory do
{

...

}

 

So what's the deal with trying to grab it by directly casting?

Thanks to anyone who can provide info on a subject that never existed... 

Patrick

 


PatrickGuay - Mon Nov 11 10:45:34 EST 2013

Re: Casting a skip into a DxlObject
Mathias Mamsch - Mon Nov 11 14:26:52 EST 2013

Well first of all, you need to know, that DxlObjects are exactly the same as Skip lists with a string key. DxlObjects are a syntax play, trying to mimic objects in other scripting languages. So the code:

Skip sk = createString();
put (sk, "Hello", "World!");

is exactly equal to:

DxlObject sk = new();
sk->"Hello" = "World!";

My guess is, that since DXL has always had problems with functions returning different types (like the Array get) function, which can lead to crashes if used badly, Telelogic figured to never officially support DxlObjects. Maybe they simply got forgotten as a new development in some version and not documented since (like a lot of other DXL).

So: DxlObjects are really nothing more than a String-Skip and a try to make DXL look a little nicer.

Anyway regarding type casting (which you can do for example with the addr_ function) you should know that is only useful in a couple of situations. One of it is Pseudo-Object-Oriented DXL where you can use DxlObjects as a basetype for your objects. Normally you then declare your own data-type and take a DxlObject and cast it to that type.

The other advantages of DxlObjects is, that you can inline the find() result in an expression. So for example you can write:

Skip sk = createString();
put (sk, "Hello", "World!");
print "Finding Hello: " ((((addr_ sk) DxlObject)->"Hello") string) "\n"

which for a Skip list you would have to write:

Skip sk = createString();
put(sk, "Hello", "World!");
string s = null;
find (sk, "Hello", s);
print "Finding Hello: " s "\n";

So obviously the second form is much nicer to read, although you have to write more code. You can of course get the key/value pairs from a DxlObject by iterating over it as a skip list. I used that for cloning class objects in some function, without having to hardcode their properties:

DxlObject dx = new();
dx->"Hello" = "World!";
dx->"World" = "Dude!";

string sValue, sKey;
Skip sk = addr_ dx;
for sValue in sk do {
   string sKey = (key sk) string; 
   print "Key: " sKey " Value: " sValue "!\n";
}

Regards, Mathias

Re: Casting a skip into a DxlObject
PatrickGuay - Mon Nov 11 15:03:59 EST 2013

Mathias Mamsch - Mon Nov 11 14:26:52 EST 2013

Well first of all, you need to know, that DxlObjects are exactly the same as Skip lists with a string key. DxlObjects are a syntax play, trying to mimic objects in other scripting languages. So the code:

Skip sk = createString();
put (sk, "Hello", "World!");

is exactly equal to:

DxlObject sk = new();
sk->"Hello" = "World!";

My guess is, that since DXL has always had problems with functions returning different types (like the Array get) function, which can lead to crashes if used badly, Telelogic figured to never officially support DxlObjects. Maybe they simply got forgotten as a new development in some version and not documented since (like a lot of other DXL).

So: DxlObjects are really nothing more than a String-Skip and a try to make DXL look a little nicer.

Anyway regarding type casting (which you can do for example with the addr_ function) you should know that is only useful in a couple of situations. One of it is Pseudo-Object-Oriented DXL where you can use DxlObjects as a basetype for your objects. Normally you then declare your own data-type and take a DxlObject and cast it to that type.

The other advantages of DxlObjects is, that you can inline the find() result in an expression. So for example you can write:

Skip sk = createString();
put (sk, "Hello", "World!");
print "Finding Hello: " ((((addr_ sk) DxlObject)->"Hello") string) "\n"

which for a Skip list you would have to write:

Skip sk = createString();
put(sk, "Hello", "World!");
string s = null;
find (sk, "Hello", s);
print "Finding Hello: " s "\n";

So obviously the second form is much nicer to read, although you have to write more code. You can of course get the key/value pairs from a DxlObject by iterating over it as a skip list. I used that for cloning class objects in some function, without having to hardcode their properties:

DxlObject dx = new();
dx->"Hello" = "World!";
dx->"World" = "Dude!";

string sValue, sKey;
Skip sk = addr_ dx;
for sValue in sk do {
   string sKey = (key sk) string; 
   print "Key: " sKey " Value: " sValue "!\n";
}

Regards, Mathias

Mathias, I agree with what you are saying, however, it seems a little strange that a skip can be placed within multiple levels of skips and that we can access any sublevel skips with the appropriate cast (as long as we know the key of the n-level skip) however we cannot do the same for DxlObjects considering they are the same thing.

// This is legal

for Skip_value in reqConds_copy do {
        keyValue = (int key reqConds_copy)
        reqInfo_skip = reqConds_copy[keyValue] Skip;

// we could go on and on and on here unpilling skips by simply extracting skips in this fashion

}

 

// This is NOT legal

for Skip_value in reqConds_copy do {
        keyValue = (int key reqConds_copy)
        DxlObject obj = reqConds_copy[keyValue] DxlObject;

 

}

 

For the time being I have gone back to storing a complex data structure by embedding skips inside of skips. I saw someone write that DXL is "c--"s dumb cousin, i guess DxlObjects are an afterthought.

PG

 

 

 

Re: Casting a skip into a DxlObject
llandale - Mon Nov 11 16:37:02 EST 2013

PatrickGuay - Mon Nov 11 15:03:59 EST 2013

Mathias, I agree with what you are saying, however, it seems a little strange that a skip can be placed within multiple levels of skips and that we can access any sublevel skips with the appropriate cast (as long as we know the key of the n-level skip) however we cannot do the same for DxlObjects considering they are the same thing.

// This is legal

for Skip_value in reqConds_copy do {
        keyValue = (int key reqConds_copy)
        reqInfo_skip = reqConds_copy[keyValue] Skip;

// we could go on and on and on here unpilling skips by simply extracting skips in this fashion

}

 

// This is NOT legal

for Skip_value in reqConds_copy do {
        keyValue = (int key reqConds_copy)
        DxlObject obj = reqConds_copy[keyValue] DxlObject;

 

}

 

For the time being I have gone back to storing a complex data structure by embedding skips inside of skips. I saw someone write that DXL is "c--"s dumb cousin, i guess DxlObjects are an afterthought.

PG

 

 

 

I could not make your "legal" code work.  Adding declarations:

// This is legal
Skip reqConds_copy = create()
Skip  reqInfo_skip
string Skip_value
int keyValue

for Skip_value in reqConds_copy do {
        keyValue = (int key reqConds_copy)
        reqInfo_skip = reqConds_copy[keyValue] Skip;
// we could go on and on and on here unpilling skips by simply extracting skips in this fashion

}

I do have a couple monster scripts that have Skips inside of other Skips; but they all do this:

  • for skpMiddle in skpOuter do
  • {  for skpInner in skpMiddle do

-Louie

Re: Casting a skip into a DxlObject
llandale - Mon Nov 11 16:43:11 EST 2013

Mathias Mamsch - Mon Nov 11 14:26:52 EST 2013

Well first of all, you need to know, that DxlObjects are exactly the same as Skip lists with a string key. DxlObjects are a syntax play, trying to mimic objects in other scripting languages. So the code:

Skip sk = createString();
put (sk, "Hello", "World!");

is exactly equal to:

DxlObject sk = new();
sk->"Hello" = "World!";

My guess is, that since DXL has always had problems with functions returning different types (like the Array get) function, which can lead to crashes if used badly, Telelogic figured to never officially support DxlObjects. Maybe they simply got forgotten as a new development in some version and not documented since (like a lot of other DXL).

So: DxlObjects are really nothing more than a String-Skip and a try to make DXL look a little nicer.

Anyway regarding type casting (which you can do for example with the addr_ function) you should know that is only useful in a couple of situations. One of it is Pseudo-Object-Oriented DXL where you can use DxlObjects as a basetype for your objects. Normally you then declare your own data-type and take a DxlObject and cast it to that type.

The other advantages of DxlObjects is, that you can inline the find() result in an expression. So for example you can write:

Skip sk = createString();
put (sk, "Hello", "World!");
print "Finding Hello: " ((((addr_ sk) DxlObject)->"Hello") string) "\n"

which for a Skip list you would have to write:

Skip sk = createString();
put(sk, "Hello", "World!");
string s = null;
find (sk, "Hello", s);
print "Finding Hello: " s "\n";

So obviously the second form is much nicer to read, although you have to write more code. You can of course get the key/value pairs from a DxlObject by iterating over it as a skip list. I used that for cloning class objects in some function, without having to hardcode their properties:

DxlObject dx = new();
dx->"Hello" = "World!";
dx->"World" = "Dude!";

string sValue, sKey;
Skip sk = addr_ dx;
for sValue in sk do {
   string sKey = (key sk) string; 
   print "Key: " sKey " Value: " sValue "!\n";
}

Regards, Mathias

Did not occur to me the physical similarity of Skips and DxlObjects thanks, but I will say that conceptually the DXLO "Fields" should tend to be fixed by the coder and not dynamic data inserted at run time; and are more like stone-age "Structures".  And the DXLOs themselves tend to be dynamic (created, one per some real world item) where as "Skips" tend to be hard coded in the script.

Re: Casting a skip into a DxlObject
PatrickGuay - Tue Nov 12 07:58:28 EST 2013

Thanks for your feedback. For the time being I have embedded a skip within a skip in order to achieve the same result.