Re: Possible feature for new Euphoria-version

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

----- Original Message ----- 
From: "Andy Serpa" <ac at onehorseshy.com>
To: <EUforum at topica.com>
Subject: 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}}

Okay, so because the reference was {1,3} you have plucked out the 1st and 3rd
elements.
 
> 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?
> 

I'm not sure if this solves the issue, Andy. I was thinking that the syntax ...

   SEQ[ seq ]

would only ever refer to a single element. The depth of that element is the
length of 'seq'. This is because at run time it is a trivial matter to have the
length of a sequence represent the depth you wish to fetch from. It may be harder
to do use the depth dynamically.

If, for example, we didn't know until runtime, that we wanted something 3 levels
deep, it is trival to build a reference sequence thus ...

  refseq = {index1, index2, index3}

but to do a depth reference sequence we would need to do ...

  refseq = {index1, index2, index3}
  for i = 1 to length(refseq) do
      refseq = {refseq}
  end for

Why bother?

And ...

   SEQ[ a,b, ... ,z ]

would refer to one or more elements, depending on the number of items in the
square-bracket-enclosed list.

We could even do 
    SEQ[ a, b..c, {d,e,f}, $ ]

which would create a new sequence whose 1st element would be SEQ[a], 2nd would
be SEQ[b..c], 3rd would be SEQ[{d,e,f}], and 4th would be SEQ[length(SEQ)].

-- 
Derek

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

Search



Quick Links

User menu

Not signed in.

Misc Menu