tenticon
tenticon

Reputation: 2913

q - string representation of list

I have a list

filter:((in;`name;`betsy`robert`tom);(>;`age;43));

and I would like to get the following list representation out of it

"((in;`name;`betsy`robert`tom);(>;`age;43))"

What I found so far is this:

flatten:{[alist]
    $[(count alist)~count raze alist;:alist;:flatten raze alist];
    };
";" sv string raze flatten[filter]
/ gives: "in;name;betsy;robert;tom;>;age;43"

which loses the nested lists in the filter list.

credits to: https://lifeisalist.wordpress.com/2009/07/10/p07-flatten-a-nested-list-structure/

Thanks!

Upvotes: 2

Views: 381

Answers (1)

Thomas Smyth
Thomas Smyth

Reputation: 5644

I think the command you are looking for is .Q.s or .Q.s1 which return kdb code in plain text:

q).Q.s1 filter
"((in;`name;`betsy`robert`tom);(>;`age;43))"

It should be noted that the output of these functions is limited by \c.

Upvotes: 2

Related Questions