Jump to content
Server Maintenance This Week. ×

need help to make cf recursive


This topic is 6075 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hello all,

This is my first attempt at a recursive cf.

I have managed to get the desired output for one line of input text. However I need it to work on

multiple , return delimited lines of text.

Can't get my head around how to make it recursive for n number of lines.

pl see atatched file with cf.

thanks.

RecCF.zip

Link to comment
Share on other sites

The idea of recursion is to take a large problem and tackle one small bit at a time, sending the rest to be evaluated by another call of the function. So in your case, the key is to grab that first line and work on that in your function, then send the remaining lines to another call of the function. Eventually you run out of lines and the problem is solved.

I'd encourage you to examine some other recursive functions that deal with text values to get a better feel for how to do that.

One suggestion specific to your function, is to not use global or script variables within the CF. Use local variables only. If you need to pass values to subsequent calls of the CF, send them as parameters.

Link to comment
Share on other sites

Thanks Ender!

Only reason I'm using global variables is to view the results in the data viewer as I build the calc. Once its working I intend to change them to locals. thanks for the advice though.

Suppose I have 50 lines in my input.

first thing is to get rid of each line as it is porcessed - so that eventually there are no more lines to process.

This is exactly my problem.

thinking out loud:

Let([...

$$counter = 1];

Case($$counter<$$values;

Quote(Left($$x;$$y))& Right( $$x;Length($$x)-$$y)& "P" &Convertvars(Gtext))

But where do I put in the counter parameter so that it increments with each iteration so that at some point it is greater than $$values and the function exits.

("P" is the pilcrow)

Link to comment
Share on other sites

I'd use a recursive algorithm for this, not an iterative algorithm. The different being that an iterative algorithm uses a counter to decide which line to look at and for loop control, whereas the recursive algorithm simply reduces the problem at each call of the function.

Hint: use LeftValues() to get the current line, RightValues() to get the remaining lines (for subsequent calls), and ValueCount() to figure out when to stop; ie: case(valuecount(text)>1; recursive call with remaining text).

Link to comment
Share on other sites

  • 4 weeks later...

It's not clear what you're trying to accomplish for a custom function. Generally functions have parameters. Will your parameter be a field or expression which contains a list of text and a delimiter? What is the input going to look like and what do you want the output to look like (ignore the $$)? What are you trying to accomplish? It may be you don't need recursion in your custom function (a recursive CF is a type of CF).

Link to comment
Share on other sites

This topic is 6075 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.