dbTalk Databases Forums  

recursive function

comp.databases.filemaker comp.databases.filemaker


Discuss recursive function in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ursus.kirk
 
Posts: n/a

Default recursive function - 12-06-2005 , 09:58 AM






I'm trying to figure out what I have missed in the following:

I want to compare two names on an 'editCompare' function. Meaning that if I
compared

Ursus against Ursus the func would yield 0
Uksus against Urkus would yield 1 (only one letter different)
Usus would yield 4 (only the first u matches)
Ursus against MyFirstName would result in 10 since no letters matched the 10
letters of MyFirstname

I have written a complex function that does the job, but wanted to replace
it by a much neater recurring function

test ( name1 ; name2 ; 0 )

Let ( [

result = Case ( Length ( name1 & name2 ) > 0 ; //As long as both names
contain any characters keep looping
If ( Left ( name1; 1 ) = Left ( name2 ; 1) ; result ; result + 1 ) ;
//Compare the first letter of each name, when no match result keeps the
same, otherwise result+1
test ( Right ( name1 ; Length ( name1 ) -1 ) ; Right ( name2 ; Length (
name2 ) -1 ) ; result ) ; //Recall the test with new parameters (name minus
first letter and new result)
result ) ] ;

result )

I must have mist something since it only returnes the same value all the
time. And ofcourse does my old solution still works, but I'm pretty sure
someting like the new solution should work, and neater.

--
Keep Well,
Ursus




Reply With Quote
  #2  
Old   
Dan Fretwell
 
Posts: n/a

Default Re: recursive function - 12-06-2005 , 10:34 AM






Ursus

Sorry I could not work out the logic of your CF. You seem to be doing
too much in the Let. On the basis of your description try the following

Test(name1;name2) =

Case(
Length(name1 & name2 ) = 0;0;
Test(Right(name1;Length(name1) - 1); Right(name2;Length(name2) - 1)) +
(Left(name1;1) â‰* Left(name2;1))
)

It seems to match you expected results except 10! and a quick count
revealed that MyFirstname has 11 characters - so I have spotted your
deliberate mistake.


Reply With Quote
  #3  
Old   
ursus.kirk
 
Posts: n/a

Default Re: recursive function - 12-07-2005 , 02:38 PM



Thank you Dan for your solution.

The 10 was actualy a miscount on my part.

Ursus

"Dan Fretwell" <dan (AT) owlsnet (DOT) co.uk> schreef in bericht
news:1133886844.651741.287490 (AT) g14g2000cwa (DOT) googlegroups.com...
Ursus

Sorry I could not work out the logic of your CF. You seem to be doing
too much in the Let. On the basis of your description try the following

Test(name1;name2) =

Case(
Length(name1 & name2 ) = 0;0;
Test(Right(name1;Length(name1) - 1); Right(name2;Length(name2) - 1)) +
(Left(name1;1) ? Left(name2;1))
)

It seems to match you expected results except 10! and a quick count
revealed that MyFirstname has 11 characters - so I have spotted your
deliberate mistake.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.