Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

need help to make cf recursive

Featured Replies

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

Maybe you can say what it's actually supposed to do? Give some sample input and the desired output.

  • Author

Oops! Sorry missed that.

Sample input:

$$animate=Animate;

$$showname=ShowName;

$$rotatename=Rotatename;

Sample Output:

"animate="&$$animate&delim;

"showname="&$$showname&delim;

etc.

thanks.

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.

  • Author

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)

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).

  • 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).

To make it recursive you need an exit condition as well as a self call.

Ie:

If(x = n; result; do more work and call self)

A simple switch will do.

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.