Function Newbie Question:
Dar Scott
dsc at swcp.com
Sat Dec 7 18:20:01 EST 2002
On Saturday, December 7, 2002, at 03:15 AM, Malte Brill wrote:
>> To calculate the pairs of distances, the repeat is probably the best
>> way
>> to go. If you are comfortable with recursion, then you might want to
>> try that.
>
> Hi Dar, I defenitly want to learn more about recursion. Are there any
> tutorials on the web, that could help me getting startet?
I don't know of any.
Here is an example using your distance problem (off the top of my head):
****************************
-- An object is specified by the long id
-- An object list has an object spec on each line
-- and represents multiple objects
-- Returns a one line (with lf) report on the distance
function distanceTweenObjects( firstObj, secondObj)
...
end distanceBetweenObjects
-- Returns a muliline report
-- on distances between an object and a list of objects
function distanceObjToObjList( theObj, objList)
if objList is empty then
return empty
else
return distanceBetweenObjects( theOBJ, line 1 of objList) & \
distanceObjToObjList( theObj, line 2 to -1 of objList)
end if
end distanceObjToObjList
-- Returns a multiline report
-- on distance among objects in a list
-- The report should have n(n-1)/2 lines for n objects
function distanceAmongObjects (objList)
if objList is empty then
return empty
else
return distanceObjToObjects( line 1 of objList, line 2 to -1 of
objList) & \
distanceAmongObjects( line 2 to -1 of objList)
end if
end distanceAmongObjects
******************************
This is completely untested, but should give you an idea of how
recursion might apply. You might find this fun or you might decide you
like repeat after all.
Dar Scott
More information about the use-livecode
mailing list