RE: Possible feature for new Euphoria-version
Robert Craig wrote:
>
>
> Tommy Carlier wrote:
> > sequence seq
> > seq = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
> > sequence b
> > b = {2, 2}
> > integer a
> > a = seq[b]
> >
> > This way you can also pass and return multiple indices to and from
> > procedures and functions.
>
> There are at least three logical ways that you might define
> subscripting of a sequence with a sequence.
>
> 1. Your way (above). The sequence used as a subscript would
> contain a series of subscripts to be applied. This
> fills a logical gap in subscripting, since currently
> the number of levels of subscripting is fixed at
> compile-time. You could use this for reading and writing.
>
> 2. sequence s
> s = {100, 200, 300, 400, 500}
> s[{1,5,3}] is {100, 500, 300}
> The subscript would let you randomly select a bunch of
> elements for reading or writing.
>
> 3. sequence s
> s[1] = 7
> s["Tommy"] = 99
> s["Carlier"] = 0
> s["Carlier"] += 1
> ? s["Tommy"] * s["Carlier"]
>
> The Euphoria implementer might set up a hash table internally.
> Whenever you assigned to a previously nonexistent
> element, the implementation would create a new
> element for you. This would be good for symbol tables,
> databases etc.
>
> Which approach is best? If you choose one, you'll
> eliminate the possibility of doing the others.
>
Can't #1 and #2 be combined?
sequence s
s = {{1,2,3},{4,5,6},{7,8,9}}
object x
-- Like #2
x = s[{1,3}]
-- Now x = {{1,2,3},{7,8,9}}
x = s[{1,2}]
-- Same as x = s[1..2], x = {{1,2,3},{4,5,6}}
-- Like #1
x = s[{{1,2}}]
-- Now x = 2, depth of subscripting sequence = depth of retrieved
element
-- Like #1 & #2 both
x = s[{{1,2},{3,1}}]
-- Now x = {2,7}
x = s[{{1,2},3}]
-- Now x = {2,{7,8,9}}
Logical, consistent, no?
|
Not Categorized, Please Help
|
|