Quiz! -Reply

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

After running the code, I think that the following recursive reverse is
more intuitively correct than the version you posted.  Plus you needed an
empty case to bottom out the recursion blink

function r_reverse(sequence in)
    sequence out

-- added this line to bottom the recursion
    out = {}
--

    for i = 1 to length(in) do
        if atom(in[i]) then
            out = in[i] & out
        else

           -- added braces to this line to 'sequencize' the recursed
           -- sequences
           -- out = r_reverse(in[i]) & out
           out = {r_reverse(in[i])} & out

        end if
    end for
    return out
end function

now r_reverse({"hello","world"}) will return
{"dlrow","olleh"}
rather than
{d,l,r,o,w,o,l,l,e,h}

-Jay Turley
 "bored at work"

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

Search



Quick Links

User menu

Not signed in.

Misc Menu