On recursion

new topic     » topic index » view thread      » older message » newer message

Hi,

To be sure, recursion is sometimes the way to go.  I recently found myself
using the pattern below several times in writing string functions (probably
discovered a hundred times by Euphorians):

--======================================================================
global function StringFunc(sequence s)
    --basic pattern of several functions
    --handles 1 or many strings in s
    if not length(s) then
        return s
    elsif atom(s[1]) then
        --process single string
    else
        for i=1 to length(s) do
            s[i]=StringFunc(s[i])
        end for
    end if
    return s
end function
--======================================================================


Some recursive functions are obscure, but this pattern is clear and
obviously useful when processing one string or many.

--Quark

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu