Asda Posted August 17, 2007 Posted August 17, 2007 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
Ender Posted August 17, 2007 Posted August 17, 2007 Maybe you can say what it's actually supposed to do? Give some sample input and the desired output.
Asda Posted August 17, 2007 Author Posted August 17, 2007 Oops! Sorry missed that. Sample input: $$animate=Animate; $$showname=ShowName; $$rotatename=Rotatename; Sample Output: "animate="&$$animate&delim; "showname="&$$showname&delim; etc. thanks.
Ender Posted August 17, 2007 Posted August 17, 2007 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.
Asda Posted August 17, 2007 Author Posted August 17, 2007 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)
Ender Posted August 17, 2007 Posted August 17, 2007 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).
David Jondreau Posted September 8, 2007 Posted September 8, 2007 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).
Natalie Posted September 16, 2007 Posted September 16, 2007 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.
Recommended Posts
This topic is 6278 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 accountSign in
Already have an account? Sign in here.
Sign In Now