7 Replies Latest reply: Nov 17, 2016 7:09 AM by Marcus Sommer

# is it possible to nest udfs or use recursion

Hi,

1. Is it possible to nest one udf into another (I wasn't able to do it)? If yes, how?

2. Is it possible to use recursion (this is just a variant of the first question)? If yes, how? -> when I tried it QV expanded the function until it had space and then raised an error: too many iterations or something similar.

Regards

Andrzej

• ###### Re: is it possible to nest udfs or use recursion

Please elaborate more practically what you are trying to do and why.

- Marcus

• ###### Re: is it possible to nest udfs or use recursion

hi,

e.g. @recursion: split a string: 'xx xxxxxxxxx xxxx xxxxxxxxxxx xxxxx xxxxxx xxx x x xxxx xxxx' into pieces of 10 characters but so that the split is being done only on spaces

this is just a dummy code to show the concept:

set udf_split= if(len(left(\$1,index(\$1,'  ' ,1))<=\$2 or len(\$1)<=\$2 or substrincount(\$1, '  ')=0,

trim(\$1),

\$(udf_split(left(\$1,index(\$1,'  ' ,1),\$2))

);

FOO:

\$(udf_split(dimension)) as MyDim

resident MyTable;

@nesting:

BOO:

\$(udf_Outer(\$(udf_Inner(1,x)))) as Something

resident MyTable;

• ###### Re: is it possible to nest udfs or use recursion

This could be done with something like:

load recno() as ID, iterno() as SubID, subfield(String, ' ' , iterno()) as SubString

From Source

while iterno() <= substringcount(String, ' ') + 1;

- Marcus

• ###### Re: is it possible to nest udfs or use recursion

i know it's a bed practice to answer one's comment but i cannot seem to find the edit:

in the udf_split in the 'false' part there should be something storing the left(...) part but that is irrelevant, I'm just interested in the ability to use recursion, the answer can be presented on n!

the output should be something like:

 x x x x x x x x x x x 1 2 3 4 5 6 7 8 9 10 11 12 x x x x x x x x x x x x x x x 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 x x x x x x x x x x x 1 2 3 4 5 6 7 8 9 10 11 12 x x x x x x x x x 1 2 3 4 5 6 7 8 9 10 11 12 x x x x 1 2 3 4
• ###### Re: is it possible to nest udfs or use recursion

Sorry, I don't understand what do you want to do. Please give an example in a tabular form like:

source:

Load * inline [

String, OtherFields

.......

],

Output:

F1 ... Fn

values ......

- Marcus

• ###### Re: is it possible to nest udfs or use recursion

1. I really appreciate you're trying to find a workaround but the point is: whether is it possible to use recursion in udfs or nested functions in QV.

single dimension, single expression bar chart:

- dimension name: Animals

- expression: count(Animals)

Animals:

1. Cat

2. White Cat

3. Very Fluffy White Cat with a Dark spot on the Tail

4. Not So Fluffy Cat

5. Not So Fluffy Cat but also Nice

I have limited space so i would like to use \$(udf_split(Animals,9)) instead of Animals and have:

1. Cat

2. White Cat

3.  Very Fluffy

White Cat

with a Dark

spot on the

Tail

4.  Not So Fluffy

Cat

5.  Not So Fluffy

Cat but also

Nice

regards

Andrzej