Print Skip element

Hello all,

is there a possibility to print a single value from a skiplist without using the for loop?

e.g.

Skip sl = createString()
put(sl, "ID1", "TEST")
string sTMP = ""
Buffer buf = create

buf = "Just a "
buf+= (find(sl,"ID1",sTMP))""

print stringOf(buf)"\n"

The example only returns "true" as intended by the find function. But maybe there is another way to get the info.

Thank you & Regards


leporello - Fri Dec 05 04:02:40 EST 2014

Re: Print Skip element
SudarshanRao - Fri Dec 05 04:28:12 EST 2014

sTMP will contain the value you're looking for. Return value of find is only an indication whether find was successful or not.

Re: Print Skip element
leporello - Fri Dec 05 04:55:01 EST 2014

Yes, that's true. But my question is how do i get the value from sTMP in one line out of the skip into my buffer?

Re: Print Skip element
SudarshanRao - Fri Dec 05 05:20:23 EST 2014

leporello - Fri Dec 05 04:55:01 EST 2014

Yes, that's true. But my question is how do i get the value from sTMP in one line out of the skip into my buffer?

Ah, I missed the point then.

Maybe I'm missing it again, but is this not going to help?

if(find(s1,"ID1",sTMP))
  buf += sTMP

Re: Print Skip element
leporello - Fri Dec 05 05:46:42 EST 2014

Hm...i think i have to explain a bit more :)

I have a dxl script which have a lot of functions and in the end i create a *.csv file.

The output looks like ID#;ResultFromFunc;string "How_did_I_get_this_result"

The "how did i get the result" are my comments from the function description

Since my script is getting bigger, i excluded some functions to include files. And of course there are often some changes on the functions where i have to change the comment.

My idea is now to use a skip where i put the ID as key and the function comment as data. Filling the skip i would do directly in the functions, so i get rid of the copying the text between the files.

For creating the csv i am looking for a smart one line solution in order to keep it readable.

so something like that.

buf += "ID_1"; iResult_ID1; if((find(sl,"ID1",sTMP))) {print sTMP""}

Your solution is fine and i also had it in mind , but i have to add an extra line for every output. So I am wondering if there is a possibility to get it in one line. :)
 

 

Re: Print Skip element
Mathias Mamsch - Fri Dec 05 05:48:50 EST 2014

leporello - Fri Dec 05 04:55:01 EST 2014

Yes, that's true. But my question is how do i get the value from sTMP in one line out of the skip into my buffer?

Since the Skip list can store any type, there are no perms to get the value out of a skip list for each type. Also unlike the Array, the buffer has no  _x find (...) function ... So you need to go with at least two statements (that you can put in one line), however a lot of people do something like:

string getString(Skip sk, string sKey, string sDefault) {
    string sTemp = null; 
    // return the default, if the skip does not contain the key
    if (find(sk, sKey, sTemp)) return sTemp else return sDefault
}

Buffer buf = create(); 
Skip sk = createString(); 
put (sk, "Hello", "world!");

buf += getString(sk, "world", "Hello ") // not found will return Hello
buf += getString(sk, "Hello", "Dude!") // found, will return world

print buf "" // should print Hello world!

Maybe that helps, regards, Mathias

Re: Print Skip element
leporello - Fri Dec 05 06:29:41 EST 2014

Mathias Mamsch - Fri Dec 05 05:48:50 EST 2014

Since the Skip list can store any type, there are no perms to get the value out of a skip list for each type. Also unlike the Array, the buffer has no  _x find (...) function ... So you need to go with at least two statements (that you can put in one line), however a lot of people do something like:

string getString(Skip sk, string sKey, string sDefault) {
    string sTemp = null; 
    // return the default, if the skip does not contain the key
    if (find(sk, sKey, sTemp)) return sTemp else return sDefault
}

Buffer buf = create(); 
Skip sk = createString(); 
put (sk, "Hello", "world!");

buf += getString(sk, "world", "Hello ") // not found will return Hello
buf += getString(sk, "Hello", "Dude!") // found, will return world

print buf "" // should print Hello world!

Maybe that helps, regards, Mathias

Ok, that's i wanted to hear. i thought there might be such a "hidden" function for skips like it exists for arrays to get data out of it.  

But your helper function will do the trick just perfect.

 

Thank you all!

Regards