1. Re: Fw: Re: subscripts (Long Post)

Kat wrote:

>Reposting, recieved no answer to the first one:
<snip>
>>>
>>>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
>>
>>Ok, but i don't understand how that line appends the selected
>>sequences together for the return. Can someone explain that to me?
>>Shouldn't it be something like:
>>returnseq = returnseq & a[b[i]]
>>?
>>>     end for
>>>     return a
>>> end function
<snip>

Sorry, Kat, somehow I missed it.

    o1 = fetch(o2,s)

is the same as

    o1 = o2[s[1]][s[2]]...[s[length(s)]]

only slower :). If you do not know dimensions of sequence o2 in
advance, or if you want to generalize for an arbitrary number of
dimensions, the second faster explicit form is useless.

The line in question simply replaces object 'a' with its own
subsequences as the iteration progresses. So, for example, if we have

    a = {1,2,{3,"jiri","kat"}}
    b = {3,2,1}

we will get, successively,

    a = {3,"jiri","kat"}
    a = "jiri"
    a = 'j'

and the last value will be returned.

Have you spotted Carl's mistake? Yeah, the first argument 'sequence a'
must be 'object a', otherwise we get a type_check failure when the
returned value is an atom, not a sequence. But do not tell him, his
self-confidence cannot probably take another knock.

jiri

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu