Re: subscripts (Long Post)

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

On Wed, 17 May 2000 14:59:55 +1200, Jiri Babor <J.Babor at GNS.CRI.NZ> wrote:

>function fetch(object a, sequence b)
>    integer i,len
>    i = 1
>    len = length(b)
>    while i <= len do
>        a = a[b[i]]
>        i += 1
>    end while
>    return a
>end function

Carl returns as today's cheeky pedant:

function fetch(sequence a, object b)
    if atom(b) then return a[b] end if
    for i = 1 to length(b) do
        a = a[b[i]] -- can't pick holes in this line smile
    end for
    return a
end function

Note that an 'if not length(b)' line isn't required, since the for loop
will skip, and a will be returned as a whole.

>Or, if you prefer a recursive variant:
[snipped]

Shudder! smile There's a time and a place for recursion, Jiri. This wasn't
it... smile))

</pedant>,
Carl -- ducking and waiting for Jiri's flames... smile

--
Error: .sig not found. Abort, Retry, Ignore?> i

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

Search



Quick Links

User menu

Not signed in.

Misc Menu