Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

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

Recommended Posts

Posted

I am trying to design a recursive field that will give me an IRR of an investment.

To calculate IRR, I have to understand recursion.

As a guide, I downloaded this very good example.... but do not understand it,

Let(
$i = $i + 1 ;
Middle( "abcdefghkjilmnopqrstuvwxyz" ; $i ; 1 ) & If ( $i < EndLoop ; ¶ & Test ; Let( $i = "" ; "" ) )
)

Can someone explain to me was "Test" does?  I feel silly... but can find no documentation on it.

And what does the "Let( $i = "" ; "" )" do?

Thanks,

#1 Solved... Test is the field name... hence the recursion

Posted

FileMaker field calculations cannot be recursive, but they can use a custom function (CF), which can be.

In your example it's not exactly clear, but I believe Test would be the name of the CF, and EndLoop would be a parameter of the CF. As such, there's an error, because where it says "Test" after the paragraph mark it's missing its parameter. It should be:

Let(
$i = $i + 1 ;
Middle( "abcdefghkjilmnopqrstuvwxyz" ; $i ; 1 ) & 
If ( $i < EndLoop ;  & Test(EndLoop)  ; Let( $i = "" ; "" ) )
)

If you call the CF like this:

Test(3)

... the output will be:

a
b
c

As it runs, it increments the counter $i; grabs the $i letter from the string, and then if $i is less than EndLoop -- 3 in this case -- it does it again, by calling itself, which is called recursion. Once $i reaches 4, it goes to the end of the If() function -- Let( $i = "" ; "" ) -- what this does is reset the counter $i and return a null result -- because a Let function has to return something, even if it's only null -- and since it does NOT call itself, the calculation is done. It's always important that a recursive function has some kind of logic like that to tell it when to stop.

Hope that helps.

PS: you don't have to use a recursive custom function, you could try scripting it.

This topic is 2445 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.