Jump to content
Sign in to follow this  
Aussie John

Cant get the recursive function to work

Recommended Posts

I Have custom Function

BulletList(Text,BulletChar,Start) which is supposed to add the bullet character at the start of each value. I have been scratching my head all day trying to get it to be recursive.

Let([
VC=ValueCount(text);
Line=BulletChar & " "  & GetValue(text;start)
];
Case(start≤VC;line &¶&   BulletList(Line;BulletChar;Start+1);)
)

Any pointers would be great. I actually don't want to have the "Start" variable but thought I needed a counter to exit the function and a way to increment the getvalue.

Edited by Aussie John

Share this post


Link to post
Share on other sites
5 hours ago, Aussie John said:

Untested, but this might work? It's also late so I might not be thinking right. 😄


Let([
     line = GetValue( text; 1 );
     newText = Substitute( "!!!" & text & "¶"; "!!!" & line & "¶"; "")
    ];
    If( IsEmpty( newText ); BulletChar & " " & line; BulletList( newText; BulletChar) )
   )

 

The "!!!" in the substitute make the first line unique in case there are duplicate values.

Share this post


Link to post
Share on other sites

Hi John,

8 hours ago, Aussie John said:

BulletList(Text,BulletChar,Start)

Is this a CF you created, or is it posted someplace?

Lee

Share this post


Link to post
Share on other sites
5 hours ago, Lee Smith said:

Hi John,

Is this a CF you created, or is it posted someplace?

Lee

Hi Lee. This is a CF I am trying to create. 

Share this post


Link to post
Share on other sites
9 hours ago, OlgerDiekstra said:

Let([
     line = GetValue( text; 1 );
     newText = Substitute( "!!!" & text & "¶"; "!!!" & line & "¶"; "")
    ];
    If( IsEmpty( newText ); BulletChar & " " & line; BulletList( newText; BulletChar) )
   )

Thanks Olger - unfortunately this goes into an indefinite loop

Edited by Aussie John

Share this post


Link to post
Share on other sites
6 hours ago, Aussie John said:

Thanks Olger - unfortunately this goes into an indefinite loop

Nearly got it right.

bulletList( text; bulletChar )

Let([
     line = GetValue( text; 1 );
     textstr = Substitute( text; "¶"; ",");
     text = Substitute( ¶ & text & ¶; ¶ & line & ¶; ¶ );
     text = Middle( text; 2; Length( text ) - 2 );
     result = If( IsEmpty( text ); line; bulletList( text; bulletChar ) )
    ];
   bulletChar & " " & line & ¶ & result
   )

The last item is duplicated, which I haven't worked out yet, but everything else works. Recursion ain't easy.

Share this post


Link to post
Share on other sites

I think I have cracked it.

Let([
     Line = GetValue( text; 1 );
     VC = ValueCount(text)
    ];
Case ( VC > 0 ;BulletChar&line & ¶ &  BulletList ( RightValues ( text ; VC - 1 ) ;BulletChar) ;)
   )

Thanks for your help Olger

Share this post


Link to post
Share on other sites

Well done. Here's a simpler version, no need for those variables:

   If( ValueCount( text ) > 0; 
       bulletChar & GetValue( text; 1 ) & ¶ & bulletList( RightValues( text; ValueCount( text ) - 1 ); bulletChar ) 
      )

The only downside is that you do valuecount() twice. (I prefer if statements as opposed to case in instances like these, but it makes no difference really).

Share this post


Link to post
Share on other sites

thanks - the key is the rightvalues which I saw in a different CF by Comment. I have a numbering CF from the Brian dunning site which I can now simplify too.

Edited by Aussie John

Share this post


Link to post
Share on other sites

Yeah, I was looking for something like rightvalues but couldn't find it. Simplifies it greatly.

Here's the numbered list:

numberedList( text; counter )

If( ValueCount( text ) > 0; 
    counter & " " & GetValue( text; 1 ) & ¶ & numberedList( RightValues( text; ValueCount( text ) - 1 ); counter + 1 ) )

It's funny how it now all looks so easy. 😄

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

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