Re: Sequence index with sequences... Why not?!

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

>I do not really understand your problem so I'll respond only at the
>error message. If you reference a piece of a sequence you must point
>to it with a number or constant that represents a number. The number
>is mostly an atom/integer. You cannot reference a part of a sequence
>with a part of another sequence that is not of type atom/integer.

Ahh! But this is the cool part: Say you have a three-dimensional array
(sequence) s, containg something, blah, blah... Now, I want s[4][5][3] and this
is ok, because, (get this!) I know _how many dimensions it has_. With this
knowledge I can store the indexing in another sequence ix, like this: ix={4,5,3}
and just as easily get or set s[ix[1]][ix[2]][ix[3]]. Are you with me so far?
*Each element in ix indexes a dimension*. So far, so cool. Okay, now for the
twist: Say you have an x-dimensional sequence... ... ...But then I can't use the
square brackets anymore, because I don't know how many to use...

>sequence s
>atom l
>s = {4,3,2,1}
>integer ID
>ID = {'a','b','c','d'}
>
>l = ID[s[1]] -- so l would be 'd'

Yeah, sure, so what? (Ok, my post was crummy...)

>> a sequence, I could do all kinds of nifty things with trees and
>> stuff like that... I was thinking of doing this:

>Yes, you can but you must extract a number (atom) from the
>sequence that indexes the sequence.

Keyword: "Extract"; Gonna be a seriously tricky recursion...

>In the RDS examplecode there is a piece of code that uses a nested
>tree that counts characters look at that, maybe it helps you.

Hmm... Okay... I'll search for it

>> Each node: {ID,KEY,child1,child2,child3,...}
>> where ID is a sequence containing the index to itself.
>>  !Note: ID[1..len-1]=Parent! Smooth!
>> Key is whatever data you would like to store.
>> Child nodes would be appended (as sequences) to the node.
>>
>> I'm also a bit disturbed by not being able to alter variables from a procedur
e

>You must return the variables of a function in a sequence.

Yeah, I know, but you get really complicated recursions that way... Indexing
with a sequence would be much niftier! (Not to mention faster, function calls
do use some overhead...)
--8<--
<some code...>
-->8--
>MK

/Anders

BTW: For those who don't know: recursion is when a function does something, and
then calls itself, until some condition is met, like this:

function test(integer n)
  ? n
  if n>0 then test(n-1) end if
end function
--------------------------------------------------------------
Anders Eurenius <c96aes at cs.umu.se> UIN:1453793
Computer Science/Engineering student at the university of Umea
--------------------------------------------------------------

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

Search



Quick Links

User menu

Not signed in.

Misc Menu