Re: subscripts

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

Lewis Townsend writes
>>       a["Lewis"] = 99
>>       a["Townsend"] = {1,2,3}
>>       ? a["Lewis"] + a["Townsend"]
> I don't think I understand this syntax. Does it mean
> that it looks for the string "Lewis" in a and replaces
> it wit 99? This hardly seems logical but maybe you are
> doing something else?

> In my proposed syntax:
> a["Lewis"] = 99 -- would convert to:
> a[['L']['e']['w']['i']['s']] = 99

Sorry, I didn't really explain this well.
I meant that you could generalize the current notion
of what a sequence is, and turn it into a kind of
associative array, where any Euphoria object could
be associated with any Euphoria object.
The interpreter would maintain a list like:

sequence a:

subscript         value

1                       0
2                       {0,0,{9},1}
3                       {}
"Lewis"            99
"Townsend"     {1, 2, 3}

When you read a subscript, the interpreter would
find that subscript in the first column and return the
associated value in the second column.
Similarly, you could overwrite a subscripted value with
a[1] = 10
or,
a["Townsend"] = {1,2,4}
I guess the values could also be generalized sequences
so you might see code like:
a["Rob"]["Craig"] = 9.9
i.e. a subscript could be any Euphoria object, but it
only does one level of subscripting. Perl "hashes"
are a primitive version of what I've described here.

As I said, I'm not really convinced that it would be
worth it to add all this stuff, either your proposal
or the one above.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu