Was Function Newbie Question

Dar Scott dsc at swcp.com
Mon Dec 9 16:47:02 EST 2002


On Monday, December 9, 2002, at 12:14 AM, Malte Brill wrote:

> @Dar: I believe I will have to read a lot more until I completely 
> understand
> the recursion principle. So I guess I´ll stick to the repeat method at
> first. I have re-read your post for quite a few times and feel like I 
> have
> never written a programm before.

Here is a little description.  You might want to put this aside until 
you feel up to looking at recursion again.


When you see "line 1 of xxx" in the example code, think "the first line 
of xxx".  When you see "line 2 to -1 of xxx", think "the rest of the 
lines".

So the recursive functions I showed say this:

     A report on the distances among a list of objects is
     a report on the distances between the first object & the rest
     followed by a report on the distances among the rest.
     If there is no first object, then the report is empty.

     A report on the distance between an object and a list of objects is
     the report on the distance between the object and the first object 
in the list
     followed by a report on the distance between that object and the 
rest of the list.
     If the list is empty, though, the report is empty.

     A report on the distance between two objects is ....

The code is a translation of the above sentences.

(You should watch out; I rattled the code off the top of my head and it 
probably has errors.)  If you try this, you should first try it on 
creating a line of two words instead of distances and then testing on a 
list of words.  This will create all pairs ignoring order of the pair.


Sometimes you see, in studying recursion, the factorial as an example.  
That is a good example in Revolution, so try that if you run across it 
in your reading.

Dar Scott




More information about the Use-livecode mailing list