1. Sequence index with sequences... Why not?!

>>subscript must be an atom
>>(reading an element of a sequnce)

I don't get it. What horrors could possibly justify this? If I could index with
a sequence, I could do all kinds of nifty things with trees and stuff like
that... I was thinking of doing this:

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 procedure
or function. A (fully backwards compatible) of fixing this would be to introduce
some kind of 'var' directive. That can't be that tricky, could it?

/Anders

P.s. this is being sent to both the list, and RDS.
--------------------------------------------------------------
Anders Eurenius <c96aes at cs.umu.se> UIN:1453793
Computer Science/Engineering student at the university of Umea
--------------------------------------------------------------

new topic     » topic index » view message » categorize

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

>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 message » categorize

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

Anders Eurenius recently suggested that Euphoria should =

allow subscripting of a sequence with a sequence. This is a =

reasonable idea. I can understand his arguments in favor of this
feature. =


I'd like to point out that in addition to using recursion to =

subscript a tree of unknown depth, you can also write a =

loop that subscripts one level with each iteration.

This topic was discussed a few months ago on this mailing list, =

and the rest of this message is a copy of what I said back then...

---------

I've received many suggestions for defining what it would
mean to subscript a sequence with a sequence:

1. Jeff Zeitlin's idea (it's done like this in APL):

    s[{a,b,c}] is {s[a],s[b],s[c]}

2. Other people suggested:   *Anders idea too*
   (useful for tree structures of unknown depth):

    s[{a,b,c}] is s[a][b][c]

3. Someone else suggested (the database people would like it):

    s["Fred"] is the Euphoria object associated with "Fred" e.g.
               s["Fred"] =3D 99
               s["Dave"] =3D 27
               s["George"] =3D {1,2,3}

    Euphoria would try to look up "Fred" in s
    in some efficient way (linear search, hashing, whatever).
    If "Fred" couldn't be found it might fail, or perhaps =

    return some special value (what value?).

So far I haven't been convinced that any of the above are really worth it=
,
since you can achieve the same effect fairly easily using the
existing language. Plus the fact there are at least three choices  =

makes it difficult to confidently commit to one of them.
The main reason is I don't want to make the language more complicated
without good reason.

Regards,
  Rob Craig
  Rapid Deployment Software
 =

new topic     » goto parent     » topic index » view message » categorize

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

> Anders Eurenius recently suggested that Euphoria should
> allow subscripting of a sequence with a sequence. This is a
> reasonable idea. I can understand his arguments in favor of this
> feature.

Thank you. The way I'm figuring it, sequences are stored as linked lists. =
The
node-type is some kind of datatype tag (as prolly all objects have) in add=
ition
to the actual data (pointer to next node, integer, whatever). If so, makin=
g
trees (and such) tricky would really feel pretty stupid...

> I'd like to point out that in addition to using recursion to
> subscript a tree of unknown depth, you can also write a
> loop that subscripts one level with each iteration.

Oh, yeah... It's tail(?)-recursive... ok. doable.

> This topic was discussed a few months ago on this mailing list,
> and the rest of this message is a copy of what I said back then...

There's an FAQ and I didn't read it. Great. <bonk><bonk>

> I've received many suggestions for defining what it would
> mean to subscript a sequence with a sequence:

Yeah, ok... how about using {} or () var and func can't have the same name=
 can
they? Or maybe just s[#{}]=3D>Zeitlin, s[=A4{}]=3D>dimensional, s[%{}]=3D>=
associated...
Sure, I do get the part about complexity though, but the way I see it, it'=
s
easy to learn the basics, and that's what's important. If the black-magici=
ans
do weird stuff, it just means it's a powerful language...

> 1. Jeff Zeitlin's idea (it's done like this in APL):
>     s[{a,b,c}] is {s[a],s[b],s[c]}
Kinky! Hey Jeff! Does it do any cool tricks?

> 2. Other people suggested:   *Anders idea too*
>    (useful for tree structures of unknown depth):
>     s[{a,b,c}] is s[a][b][c]
I was slightly surprised it didn't already work this way, it felt very nat=
ural

> 3. Someone else suggested (the database people would like it):
>     s["Fred"] is the Euphoria object associated with "Fred" e.g.
>                s["Fred"] =3D3D 99
>                s["George"] =3D3D {1,2,3}
>
>     Euphoria would try to look up "Fred" in s
>     in some efficient way (linear search, hashing, whatever).
>     If "Fred" couldn't be found it might fail, or perhaps =3D
>
>     return some special value (what value?).

Easy: junk token like nan, or something. But, uhh, what is this associated=

object thing? How's this: it's a giant sequence, and links are kept as
index-sequences...?

> So far I haven't been convinced that any of the above are really worth i=
t
Perhaps it isn't. If I can escape the overheads of recursion, I'll try to =
make
a generic tree library...

> since you can achieve the same effect fairly easily using the
> existing language. Plus the fact there are at least three choices
Yeah, but the others are totally twisted! B-)

> makes it difficult to confidently commit to one of them.
You don't have to.

> The main reason is I don't want to make the language more complicated
> without good reason.
Makes more sense. If you'd buckle every time, it would become spit and bai=
ling
wire real quick...

> Regards, >   Rob Craig >   Rapid Deployment Software

/Anders
--------------------------------------------------------------
Anders Eurenius <c96aes at cs.umu.se> UIN:1453793
Computer Science/Engineering student at the university of Ume=E5
--------------------------------------------------------------

new topic     » goto parent     » topic index » view message » categorize

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

Whoa! Messy! How does the mailserver do it?
/Andy

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu