1. Possible feature for new Euphoria-version

Sequences are really easy to use, but there is no way you can create an 
index to a sub-, sub-, sub-sequence of a given sequence. Wouldn't it be 
nice if such a thing existed?

In the current version of Euphoria, you can do:
sequence seq
seq = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
integer a
a = seq[2][2]

My suggestion for a new feature: allow the index to be a sequence. That 
way you could do something like this:
sequence seq
seq = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
integer a
a = seq[ {2, 2} ]

And now for the exciting part:
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.

-- 

Tommy Carlier
tommy online: http://users.pandora.be/tommycarlier

new topic     » topic index » view message » categorize

2. Re: Possible feature for new Euphoria-version

Ouch, to much confusion...Im an old timer in euphoria

Euman

----- Original Message ----- 
From: "Tommy Carlier" <tommy.carlier at pandora.be>
To: "Euphoria Mailing List" <EUforum at topica.com>
Subject: Possible feature for new Euphoria-version


> 
> 
> Sequences are really easy to use, but there is no way you can create an 
> index to a sub-, sub-, sub-sequence of a given sequence. Wouldn't it be 
> nice if such a thing existed?
> 
> In the current version of Euphoria, you can do:
> sequence seq
> seq = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
> integer a
> a = seq[2][2]
> 
> My suggestion for a new feature: allow the index to be a sequence. That 
> way you could do something like this:
> sequence seq
> seq = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
> integer a
> a = seq[ {2, 2} ]
> 
> And now for the exciting part:
> 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.
> 
> -- 
> 
> Tommy Carlier
> tommy online: http://users.pandora.be/tommycarlier
> 
> 
> 
> TOPICA - Start your own email discussion group. FREE!
> 
>

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

3. Re: Possible feature for new Euphoria-version

On 8 Jan 2004, at 14:38, Euman wrote:

> 
> 
> Ouch, to much confusion...Im an old timer in euphoria
> 
> Euman
> 
> ----- Original Message ----- 
> From: "Tommy Carlier" <tommy.carlier at pandora.be>
> To: "Euphoria Mailing List" <EUforum at topica.com>
> Subject: Possible feature for new Euphoria-version
> 
> 
> > Sequences are really easy to use, but there is no way you can create an 
> > index to a sub-, sub-, sub-sequence of a given sequence. Wouldn't it be 
> > nice if such a thing existed?
> > 
> > In the current version of Euphoria, you can do:
> > sequence seq
> > seq = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
> > integer a
> > a = seq[2][2]
> > 
> > My suggestion for a new feature: allow the index to be a sequence. That 
> > way you could do something like this:
> > sequence seq
> > seq = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
> > integer a
> > a = seq[ {2, 2} ]
> > 
> > And now for the exciting part:
> > 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.

You can do this in strtok:

param = {2}
db = {"this is a test1","this is test2 a"}
result = gettok(db,param,"")

And this:

string = {"Red,Skelton,45,London,England",
          "Lucy,Ball,56,Barre,North Dakota",
          "Fred,Astaire,45,Alberta,Canada",
          "Pierre,du Pont,56,Paris,France"}
string = sorttok(string,{3,-2},',') 
string = {"Red,Skelton,45,London,England",
          "Fred,Astaire,45,Alberta,Canada",
          "Pierre,du Pont,56,Paris,France",
          "Lucy,Ball,56,Barre,North Dakota"}
You see, it did a ascending sort on (fictitious) age field, then sorted the two
last
name fields in decending order. 
And this gets you a seq in reply:

string = {"Red,Skelton,45,London,England",
          "Lucy,Ball,56,Barre,North Dakota",
          "Fred,Astaire,45,Alberta,Canada",
          "Pierre,du Pont,56,Paris,France"}
string = sortntok(string,{3,-2},',') 
string = {1,3,4,2} 

Eu should be as versatile as possible, no?

Kat

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

4. Re: Possible feature for new Euphoria-version

----- Original Message ----- 
From: "Tommy Carlier" <tommy.carlier at pandora.be>
To: "Euphoria Mailing List" <EUforum at topica.com>
Subject: Possible feature for new Euphoria-version


> 
> 
> Sequences are really easy to use, but there is no way you can create an 
> index to a sub-, sub-, sub-sequence of a given sequence. Wouldn't it be 
> nice if such a thing existed?
> 
> In the current version of Euphoria, you can do:
> sequence seq
> seq = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
> integer a
> a = seq[2][2]
> 
> My suggestion for a new feature: allow the index to be a sequence. That 
> way you could do something like this:
> sequence seq
> seq = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
> integer a
> a = seq[ {2, 2} ]
> 
> And now for the exciting part:
> 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.
> 

Tommy,
this idea has been suggested before (about 2 or 3 years ago). I was not accepted
then because (I think) it was too hard to incorporate into Euphoria's code, but
now that RDS is rewritting the parser they might consider it. I certainly like
the idea. And as an extention, I hope one could also do this ...

  seq[b] = 123

which would change the sequence to ...

  {{1, 2, 3}, {4, 123, 6}, {7, 8, 9}}

This would make a lot of my code much simplier to write and read, and make the
app run faster.

-- 
Derek

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

5. Re: Possible feature for new Euphoria-version

On Thu, 08 Jan 2004 19:54:28 +0100, Tommy Carlier
<tommy.carlier at pandora.be> wrote:

>Sequences are really easy to use, but there is no way you can create an 
>index to a sub-, sub-, sub-sequence of a given sequence. Wouldn't it be 
>nice if such a thing existed?

My apologies if you already knew how to code such, but this might just
(possibly) be all you are after:

function getqx(sequence q, sequence i)
	if length(i)=1 then
		return q[i[1]]
	end if
	return getqx(q[i[1]],i[2..length(i)])
end function

function setqx(sequence q, sequence i, object val)
	if length(i)=1 then
		q[i[1]]=val
		return q
	end if
	q[i[1]]=setqx(q[i[1]],i[2..length(i)],val)
	return q
end function

sequence s
s = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
integer a
? getqx(s,{2,2})			-- prints 5
s=setqx(s,{2,2},123)
?s					-- prints {{1, 2, 3}, {4, 123, 6}, {7, 8, 9}}
if getc(0) then end if
abort(0)

I'm not (too) worried about having to code get() like this, but set()
will probably impose serious COW (copy-on-write) overhead
unnecessarily when used with large sequences.

Of course I believe indexing using sequences should be part of a new
improved Euphoria, btw, but that's not going to be here for a while
yet, so maybe in the meantime the above will be of some use.

Regards,
Pete

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

6. Re: Possible feature for new Euphoria-version

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.

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

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

7. Re: Possible feature for new Euphoria-version

While it is true that there are alternative meanings that could be applied
to subscripting through sequences, in my opinion the first is by far the
most attractive.  The ability to access various levels of a sequence at
run-time could be quite a powerful tool, however as with Pete Lomax
suggestion implementing it with Euphoria (as it is currently works) would
impose a hefty overhead.

So for me, implementing this as part of the language would be a significant
improvement that would enable a lot of code to be written more generically
with reasonable efficiency.  Whereas the other alternative applications
could just as well be implemented though library functions.


Regards,
Peter Blonner


----- Original Message ----- 
From: "Robert Craig" <rds at RapidEuphoria.com>
To: <EUforum at topica.com>
Sent: Friday, January 09, 2004 3:29 PM
Subject: Re: Possible feature for new Euphoria-version


>
>
> 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.
>
> Regards,
>     Rob Craig
>     Rapid Deployment Software
>     http://www.RapidEuphoria.com
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

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

8. Re: Possible feature for new Euphoria-version

Derek wrote:

>> -----Original Message-----
>> From: Robert Craig
>> Sent: Friday, 9 January 2004 3:30 PM
>>
>>
>> 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.

I vote for this way.

>> 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.
>
> Or as alternative ...
>
>      s = {100, 200, 300, 400, 500}
>      s[1,5,3] is {100, 500, 300}
>
>> 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.
>
> Or as alternative ...
>
>      s."Tommy" = 99
>
>> Which approach is best? If you choose one, you'll
>> eliminate the possibility of doing the others.
>
> Well at least any of them will be an improvement, and the "eliminated" ones
> are still possible through slower methods.

I vote for using your alternatives for 2. and 3. smile
Well, 2. is not important for me, but implementing 1. and 3. directly
into Euphoria would be a *considerable* enhancement.

Regards,
   Juergen

-- 
 /"\  ASCII ribbon campain  |    |\      _,,,---,,_
 \ /  against HTML in       |    /,`.-'`'    -.  ;-;;,_
  X   e-mail and news,      |   |,4-  ) )-,_..;\ (  `'-'
 / \  and unneeded MIME     |  '---''(_/--'  `-'\_)

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

9. Re: Possible feature for new Euphoria-version

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

10. Re: Possible feature for new Euphoria-version

Tommy Carlier wrote:

> Options for seq[seq]:
> 
> 1. s[{a, b, c}] = s[a][b][c] -- recursive indices
> 2. s[{a, b, c}] = { s[a], s[b], s[c] } -- direct indices
> 3. s["abc"] = s[VALUES][ find("abc", s[KEYS]) ] -- associative list

1: Simpler than you might think:

   -- Get 's' from somewhere, then...
   params = {a, b, c}
   t = s
   for i = 1 to length(params) do
       t = t[params[i]]
   end for
   -- t is now s[a][b][c]

2: Not much difference in coding terms:

   -- Get 's' from somewhere, then...
   params = {a, b, c}
   t = repeat(0, length(params))
   for i = 1 to length(params) do
       t[i] = s[params[i]]
   end for
   -- t is now {s[a],s[b],s[c]}

3: Pretty much speaks for itself :)

Carl


-- 
[ Carl R White == aka () = The Domain of Cyrek = ]
[ Cyrek the Illogical /\ www.cyreksoft.yorks.com ]

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

11. Re: Possible feature for new Euphoria-version

----- Original Message ----- 
From: "Carl W." <euphoria at cyreksoft.yorks.com>
To: <EUforum at topica.com>
Subject: Re: Possible feature for new Euphoria-version


> 
> 
> Tommy Carlier wrote:
> 
> > Options for seq[seq]:
> > 
> > 1. s[{a, b, c}] = s[a][b][c] -- recursive indices
> > 2. s[{a, b, c}] = { s[a], s[b], s[c] } -- direct indices
> > 3. s["abc"] = s[VALUES][ find("abc", s[KEYS]) ] -- associative list
> 
> 1: Simpler than you might think:
> 
>    -- Get 's' from somewhere, then...
>    params = {a, b, c}
>    t = s
>    for i = 1 to length(params) do
>        t = t[params[i]]
>    end for
>    -- t is now s[a][b][c]

Yes, this is almost exactly how I coded it in my support library. The hard part
was putting it as a SET operation.

  S[{a,b,c}] = d

This needs recursion I think. Well that's how I've got it coded.

Here is code from my 'basic.e' library


-- Returns an element from source. Index is a list of subscripts
-- Example:  rc = seqfetch({"abc","def"}, {2,1})
--              --> rc is 'd'
-- Example:  rc = seqfetch({"abc","def"}, {1,2})
--              --> rc is 'b'
----------------------------------------
global function seqfetch(object piSource, object piIndex)
----------------------------------------
  -- fetch from piSource using index sequence piIndex
    for i=1 to length(piIndex) do
        if atom(piSource) then exit end if
        piSource = piSource[piIndex[i]]
    end for
    return piSource
end function


-- Returns an updated sequence. Index is a list of subscripts
-- Example:  rc = seqstore({"abc","def"}, {2,1}, 'q')
--              --> rc is {"abc","qef"}
-- Example:  rc = seqstore({"abc","def"}, {1,2}, 'q')
--              --> rc is {"aqc","def"}
----------------------------------------
global function seqstore(object piSource, object piIndex, object piValue)
----------------------------------------
  -- store piValue in piSource using index sequence piIndex
    integer lLen
    if atom(piSource) then
        return piValue
    end if
    if atom(piIndex) then
        piSource[piIndex] = piValue
    else
        lLen = length(piIndex)
        if lLen > 1 then
piSource[piIndex[1]] = seqstore(piSource[piIndex[1]],
            piIndex[2..lLen], piValue)
        else
            piSource[piIndex[1]] = piValue
        end if
    end if
    return piSource
end function

 
> 2: Not much difference in coding terms:
> 
>    -- Get 's' from somewhere, then...
>    params = {a, b, c}
>    t = repeat(0, length(params))
>    for i = 1 to length(params) do
>        t[i] = s[params[i]]
>    end for
>    -- t is now {s[a],s[b],s[c]}

Again my code is very similar, just more validation checking and an
'exclude/include' tweak...

----------------------------------------
global function subset(sequence piSource, sequence piIndex, integer pFlag)
----------------------------------------
  -- Pickout from a sequence, all the elements identified in the Index sequence
  -- If Flag = true then include all the elements, otherwise exclude them.
    sequence lResult
    integer  lSub
    integer  lUsed

    -- If excluding elements, rejig the index sequence.
    if pFlag = 0 then
        -- Init to a null set
        lResult = {}
        -- Examine each possible element subscript
        for i = 1 to length(piSource) do
            -- If subscript not in original list, then include it.
            if find(i, piIndex) = 0 then
                lResult &= i
            end if
        end for
        -- Replace original list with new list.
        piIndex = lResult
    end if

    lResult = repeat(0, length(piIndex))
    lUsed = 0
    -- for each subscript in the index sequence:
    for i = 1 to length(piIndex) do
        lSub = piIndex[i]
        -- if the subscript in valid for the source seq,
        if lSub >= 1 and lSub <= length(piSource) then
            -- collect the element
            lUsed += 1
            lResult[lUsed] = piSource[lSub]
        end if
    end for
    
    return lResult[1 .. lUsed]
end function



> 3: Pretty much speaks for itself :)

Hmmmm.... My associative array library is way to big to copy into this reply. 

-- 
Derek

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

12. Re: Possible feature for new Euphoria-version

What exactly do you mean?

In the second example;

sequence seq
seq = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
integer a
a = seq[ {2, 2} ]

to me it reads, "an embeded sequence", eg 'variable a' returns {{2,2}},
where example 1,  'a' would return
'integer 5'.

n.b. You can do what was done in your example by doing the following,

sequence seq, b, a
seq = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
b = [2][ 2]
a = b





----- Original Message ----- 
From: "Tommy Carlier" <tommy.carlier at pandora.be>
To: "Euphoria Mailing List" <EUforum at topica.com>
Sent: Friday, January 09, 2004 5:54 AM
Subject: Possible feature for new Euphoria-version


>
>
> Sequences are really easy to use, but there is no way you can create an
> index to a sub-, sub-, sub-sequence of a given sequence. Wouldn't it be
> nice if such a thing existed?
>
> In the current version of Euphoria, you can do:
> sequence seq
> seq = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
> integer a
> a = seq[2][2]
>
> My suggestion for a new feature: allow the index to be a sequence. That
> way you could do something like this:
> sequence seq
> seq = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
> integer a
> a = seq[ {2, 2} ]
>
> And now for the exciting part:
> 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.
>
> -- 
>
> Tommy Carlier
> tommy online: http://users.pandora.be/tommycarlier
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>
> -- 
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.558 / Virus Database: 350 - Release Date: 4/01/04
>


---



--

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

13. Re: Possible feature for new Euphoria-version

On Sat, 10 Jan 2004 02:33:53 +1100, Hayden McKay <hmck1 at dodo.com.au>
wrote:

>n.b. You can do what was done in your example by doing the following,
>
>sequence seq, b, a
>seq = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
Sorry to tell you this, but it gives a syntax error:
>b = [2][ 2]
	^ expected to see an expression, not '['

Pete

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

14. Re: Possible feature for new Euphoria-version

I vote for the first alternative, with this addition:

seq={{1,2,3},{4,5,6},{7,8,9}}
a={2,{2,3}}
b=seq[a]
-- b is {5,6}


thus a sequence subscript would provide both single elements and slices.
Thus in the general case

a={w,x,y,z}
seq[a] will have exactly the same effect as seq[w][x][y][z]

-- Mike Nelson

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

15. Re: Possible feature for new Euphoria-version

On Fri,  9 Jan 2004 12:23:43 +0000, Tommy Carlier
<tommy.carlier at pandora.be> wrote:

>Options for seq[seq]:
>
>1. s[{a, b, c}] = s[a][b][c] -- recursive indices
>2. s[{a, b, c}] = { s[a], s[b], s[c] } -- direct indices
>3. s["abc"] = s[VALUES][ find("abc", s[KEYS]) ] -- associative list
>
>I think that 2 and 3 are so easy and fast to do in Euphoria, 
There is (nearly) the same copy on write overhead for 2 as for 1.

I do agree that anyone using (large) associative arrays and wondering
why it is a tad slow ought not to give up their day job.

Pete
PS As I don't personally see that 1 necessarily wins over 2, and 3
would be darn handy (despite being unlikely to be specially fast if
hand-coded in optimised assembly), I have to abstain on this one.

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

16. Re: Possible feature for new Euphoria-version

On Fri,  9 Jan 2004 11:20:28 +0000, Matt Lewis
<matthewwalkerlewis at yahoo.com> wrote:

>
>
>> From: Robert Craig [mailto:rds at RapidEuphoria.com] 
>> 
>> 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.
>
>I think 1 and 2 could be combined in this way:
>
>s = {{1,2,3},{4,5,6},{7,8,9,{10,11,12}}}
>
>s[{2,2}] is 5
>s[{{2},{1}}] is {{4,5,6},{1,2,3}}
>s[{{2},{3,{2},{3,1}}] is {{4,5,6},8,10}
{3,1} would give you a subscript error on the 9, surely?
>
>In other words, each 1d sequence refers to an element.  To get really 
>fancy, we could do slices, too:
>
>s[{2,2}..{2,3}] is {5,6}
>s[{{2,1},{1,1}}..{{2,2},{1,3}}] is {{4,5},{1,2,3}}
s[{{2,1}..{2,2},{1,1}..{1.3}}] ??
>s[{{2},{3,{2},{3,1}}..{{3},{3,{4},{3,2}}}] is either:
>
>{{{4,5,6},{8,10}},{8,9,{10,11,12}},{10,11}}
>...or...
>{{4,5,6},{8,10},8,9,{10,11,12},10,11}
erm, pass blink

Definitely needs sugar, of the syntactic variety that is.

Perhaps {[1..2],[3..4]} which could be stored internally as
{{-inf,1,2},{-inf,3,4}} to represent (a pair of) slices?

Pete.

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

17. Re: Possible feature for new Euphoria-version

Ok, My 2 cents.

1. s[{a, b, c}] = s[a][b][c] -- recursive indices
2. s[a, b, c] = { s[a], s[b], s[c] } -- direct indices

Now, we extend this easily by allowing this to mean.
    s = {
      {1,2,3,},
      {4,5,6},
      {7 8,9}
    }
s[{1, 2}] = 2
s[1, 2] = {{1,2,3,}, {4, 5, 6}}
s[{1, 2}, {2, 3}] = {2, 6}

I don't want to allow slicing as of yet. because... I see some logic
problems with it.
PROBLEM:
    s = {
      {1,2,3,},
      {4,5,6},
      {7 8,9}
    }
    1. s[{1, 2}..{2, 3}] = {{2,3}, {5, 6}}? -- slice from the 2 to the 6.
       That's neither vertical nor horizontal.

I guess it could be implemented as:
    s = {
      {1,2,3,},
      {4,5,6},
      {7 8,9}
    }
    1. s[{1, 2}..3] = {2, 3}  -- but then that will forever limit us to the
current
        horizontal form of indexing.

I would still like to see some form of vertical indexing.
s[?] = {s[1][2], s[2][2], s[3][2]}

        Lucius L. Hilley III - Unkmar

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

Search



Quick Links

User menu

Not signed in.

Misc Menu