1. Referencing Nested Sequences

I am new to Euphoria but find it an exciting language.
One point that bothers me however is as follows -

* to access a sequence nested in a sequence you must make the full
"path" reference each time if you are to change any values
You can not simply copy a reference to the inner sequence - otherwise a
copy of the entire sequence would be made.

e.g   for i = 1 to 10 do
            nested[9][3][i] = 0
        end for

if it done as
      SubList = nested[9][3]
    for i = 1 to 10 do
            SubList[i] = 0
     end for

The latter causes a new list to be made - which is not what I want

When the subscripts are CONSTANTS it would be so much more readable to
access the inner element without the full "PATH"
This is also the same when passing the Sub Sequence as a parameter to a
function.
This would be convenient for writing generic sub-functions without them
knowing how the sub-sequence was accesses

In summary it seems that I am forces to accept a significant reduction
to efficiency and less
readability to write the code I intend.

Not also that although I know 'C' pointers would solve this, I would not
want pointers.
Rather I would like a "shorthand" way to access the inner elements - I
would like that  interpreter
to handle "shorthand" refereneces without the performance loss of
copying entire sequences

new topic     » topic index » view message » categorize

2. Re: Referencing Nested Sequences

Hello pblonner:

> I am new to Euphoria but find it an exciting language.

Welcome!

> One point that bothers me however 
> is as follows - to access a sequence 
> nested in a sequence you must make the full
> "path" reference each time if you are to change
> any values. You can not simply copy a reference
> to the inner sequence - otherwise a
> copy of the entire sequence would be made.
> 
> e.g   for i = 1 to 10 do
>             nested[9][3][i] = 0
>         end for
> 
> if it done as
>       SubList = nested[9][3]
>     for i = 1 to 10 do
>             SubList[i] = 0
>     end for

[snip]

Try please:

sequence SubList
SubList = nested[9][3]

for i = 1 to 
  length(SubList) -- my be 10, if length(SubList)>=10
do SubList[i] = 0
end for

nested[9][3] = SubList

Regards,
Igor Kachan
kinz at peterlink.ru

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

3. Re: Referencing Nested Sequences

On Sat, 07 Jun 2003 18:55:21 +1000, pblonner at optushome.com.au wrote:

>e.g   for i =3D 1 to 10 do
>            nested[9][3][i] =3D 0
>        end for
>
>if it done as
>      SubList =3D nested[9][3]
>    for i =3D 1 to 10 do
>            SubList[i] =3D 0
>     end for
>
>The latter causes a new list to be made - which is not what I want
You are missing the last line:
	nested[9][3] =3D SubList

Processing inner elements via temporary variables (and remembering to
put them back) is actually the fastest way to do this (excepting of
course nested[9][3][1..10]=3Drepeat(0,10);), as well as being quite
readable.

Pete

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

4. Re: Referencing Nested Sequences

----- Original Message -----
From: <pblonner at optushome.com.au>
To: "EUforum" <EUforum at topica.com>
Subject: Referencing Nested Sequences


>
>
> I am new to Euphoria but find it an exciting language.

Hi there, a lot of people find it pretty good too.

> One point that bothers me however is as follows -
>
> * to access a sequence nested in a sequence you must make the full
> "path" reference each time if you are to change any values
> You can not simply copy a reference to the inner sequence - otherwise a
> copy of the entire sequence would be made.
>
> e.g   for i = 1 to 10 do
>             nested[9][3][i] = 0
>         end for
>
> if it done as
>       SubList = nested[9][3]
>     for i = 1 to 10 do
>             SubList[i] = 0
>      end for
>
> The latter causes a new list to be made - which is not what I want

Like most languages, there is more that one way to do things. In your
example here, if what you are trying to do is set all values of the
innermost sequence zero, three simpler ways to do it are ...

a) nested[9][3] = repeat(0, length(nested[9][3]))
b) nested[9][3] = and_bits(nested[9][3], 0 )
c) nested[9][3][1..length(nested[9][3])] = 0

in the first two cases, the entire element at [9][3] is replaced with a new
sequence of all zero elements. This is usually faster than replacing each
innermost element one at the time. The third case uses 'slice' technique
which is a useful skill.

> When the subscripts are CONSTANTS it would be so much more readable to
> access the inner element without the full "PATH"

Agreed. This has been asked for year after year but the creators of Euphoria
don't like the idea.

> This is also the same when passing the Sub Sequence as a parameter to a
> function.
> This would be convenient for writing generic sub-functions without them
> knowing how the sub-sequence was accesses

Agreed. This has been asked for year after year but the creators of Euphoria
don't like the idea of passing parameters by reference rather than value. (I
tend to agree with RDS on this one). However there could still be some
shorthand way of specifying a sequence as both a parameter AND a result...
Maybe along the lines of ...

    nested[9][3] = and_bits( @, 0)

> In summary it seems that I am forces to accept a significant reduction
> to efficiency and less readability to write the code I intend.

Efficiency is not much of an issue as Euphoria is extremely efficient and
clever about how sequences are actually implemented. However I must fully
support your call for readability.

> Not also that although I know 'C' pointers would solve this, I would not
> want pointers.
> Rather I would like a "shorthand" way to access the inner elements - I
> would like that  interpreter
> to handle "shorthand" refereneces without the performance loss of
> copying entire sequences

Couldn't agree more. Even we borrowed from Pascal...

   with nested[9][3]
     for i = 1 to 10 do
       .[i] = 0
     end for
   end with

Or if there was an short way of indicating the length of a sequence...

  nested[9][3][1..$] = 0

These are just syntactic sugar, but makes coding a whole lot easier for both
coder and reader.

--
Derek

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

5. Re: Referencing Nested Sequences

----- Original Message -----
From: <pblonner at optushome.com.au>
To: "EUforum" <EUforum at topica.com>
Subject: Referencing Nested Sequences

G'Day. I just clued in you're another vegemite. I'm from Melbourne. Hope you
find what you need from the Euphoria language. This list is a bonzer source
of info and there's only a couple of larrikins. Catch you later.

--
Derek

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

6. Re: Referencing Nested Sequences

Hi Derek

Another vegemite here - also from Melbourne!

Also new - and finding Eu very good for my needs.

David Jarvis



On 7 Jun 2003 at 21:22, Derek Parnell wrote:

> 
> 
> ----- Original Message -----
> From: <pblonner at optushome.com.au>
> To: "EUforum" <EUforum at topica.com>
> Sent: Saturday, June 07, 2003 6:55 PM
> Subject: Referencing Nested Sequences
> 
> G'Day. I just clued in you're another vegemite. I'm from Melbourne. Hope you
> find what you need from the Euphoria language. This list is a bonzer source
> of info and there's only a couple of larrikins. Catch you later.
> 
> --
> Derek
> 
> 
> 
> TOPICA - Start your own email discussion group. FREE!
> 
> 


-- 
David Jarvis
ULTRAsmart Marketing
www.ultrasmart.org
ph: 61 3 9884 4661

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

7. Re: Referencing Nested Sequences

Thanks ,

I did not expect such a quick response.
Derek, I guess the ".au" postfix gave me away, I'm from Sydney.  Some of the
lingo you used might give us all away as a "wierd mob" :)

I realise that I may have simplified my example to where it lost some of the
general issue.   I was hoping/believing that Euphoria would be great for
symbolic manipulations,i.e where you could coalesce sub-sequences into an item
that is part of a larger item,  generally rearrange items in a sequence - where
each of these items might be a nested sequence.

Would this result in is that large 'copying tasks' for  each rearrangement ? -
even though it might just be pushing a item up or down the structure.
That is, you may have just moved an subsequence - but as soon as you set a value
in the "moved" subseqence would Euphoria assume a copy of the entire subsequence
is necessary?   This is perhaps why a sort library function is vital, since
shifting the items manually around and then setting values later would cause
large 'copying' - i.e if the sort was coded outside the library function.

--
Peter

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

8. Re: Referencing Nested Sequences

----- Original Message -----
From: <pblonner at optushome.com.au>
To: "EUforum" <EUforum at topica.com>
Subject: Re: Referencing Nested Sequences


>
>
> Thanks ,
>
> I did not expect such a quick response.
> Derek, I guess the ".au" postfix gave me away, I'm from Sydney.  Some of
the
> lingo you used might give us all away as a "wierd mob" :)

Well aren't we? blink

> I realise that I may have simplified my example to where it lost some of
the
> general issue.   I was hoping/believing that Euphoria would be great for
> symbolic manipulations,i.e where you could coalesce sub-sequences into an
item
> that is part of a larger item,  generally rearrange items in a sequence -
where
> each of these items might be a nested sequence.
>
> Would this result in is that large 'copying tasks' for  each rearrangement
? -

Not really. If I understand this ( Robert Craig - can you confirm this?)
correctly, altering an element inside a sequence does not mean that the
entire sequence is copied to a new RAM location. Internally, a sequence uses
pointers to data, like a handle. This, combined with reference counting and
garbage collection, means that manipulating a sequence's contents is not all
that inefficient.


> even though it might just be pushing a item up or down the structure.
> That is, you may have just moved an subsequence - but as soon as you set a
value
> in the "moved" subseqence would Euphoria assume a copy of the entire
subsequence
> is necessary?


> This is perhaps why a sort library function is vital, since
> shifting the items manually around and then setting values later would
cause
> large 'copying' - i.e if the sort was coded outside the library function.

You can see the source code for the supplied sort() function in sort.e file.
It is really very quick.

Here is a short program to demonstrate that the length of a sequence does
not greatly influence the speed of changing its elements.

----
include machine.e
atom e
integer c,l
sequence x,y
tick_rate(1000)
x = repeat({0,1,2,3,4,5,6,7,8,9}, 4)
l=20
x = repeat(x,l)
y = {{"testdata"}}
c = 0
e = time()+10
while e > time() do
    x[2] = y
    c += 1
end while
? c
---

This just counts the number of assignments done in a 10 second span. Try
varying the value of 'l' and you should see that it doesn't change things
much.

BTW, on my machine I'm getting a count around 21 million.
--
Derek

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

9. Re: Referencing Nested Sequences

On 8 Jun 2003 at 11:06, pblonner at optushome.com.au wrote:

> 
> 
> Thanks ,
> 
> I did not expect such a quick response.
> Derek, I guess the ".au" postfix gave me away, I'm from Sydney.  Some of the
> lingo you used might give us all away as a "wierd mob" :)
> 
> I realise that I may have simplified my example to where it lost some of the
> general issue.   I was hoping/believing that Euphoria would be great for
> symbolic manipulations,i.e where you could coalesce sub-sequences into an item
> that is part of a larger item,  generally rearrange items in a sequence -
> where
> each of these items might be a nested sequence.
> 
> Would this result in is that large 'copying tasks' for  each rearrangement ? -
> even though it might just be pushing a item up or down the structure.
> That is, you may have just moved an subsequence - but as soon as you set a
> value
> in the "moved" subseqence would Euphoria assume a copy of the entire
> subsequence
> is necessary?   This is perhaps why a sort library function is vital, since
> shifting the items manually around and then setting values later would cause
> large 'copying' - i.e if the sort was coded outside the library function.
> 
> --
> Peter

As an example, Bach has a built-in sort.
For a sequence of 6000 chars, Eu managed 27 / sec.
while Bach was 125/sec.

Karl Bochert

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

10. Re: Referencing Nested Sequences

kbochert at copper.net wrote:
> As an example, Bach has a built-in sort.
> For a sequence of 6000 chars, Eu managed 27 / sec.
> while Bach was 125/sec.

If someone wanted to sort 6000 chars (0-255),
they could use the bucket sort in euphoria\demo\allsorts.ex,
and it would "blow away" your sort.  smile

When you say "Eu", I assume you mean the Euphoria
interpreter. Don't forget that the Translator can
give a very significant boost to the speed of Euphoria code.

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

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

11. Re: Referencing Nested Sequences

On 7 Jun 2003 at 23:41, Robert Craig wrote:

> 
> 
> kbochert at copper.net wrote:
> > As an example, Bach has a built-in sort.
> > For a sequence of 6000 chars, Eu managed 27 / sec.
> > while Bach was 125/sec.
> 
> If someone wanted to sort 6000 chars (0-255),
> they could use the bucket sort in euphoria\demo\allsorts.ex,
> and it would "blow away" your sort.  smile

True enough. On my system the integer sort (allsorts.e) of
5120  elements gives:
EU :    1.25 ms.
Bach:   0.32 ms.
Bucket: 0.12 ms

The figures I quoted are for a sequence of 6000 2-character
sequences, {"a3", "dr", ....} which accounts for the 8ms. (125/sec) 
quoted vs. the .32 ms above (and disqualifies the bucket)

I should also point out that the qsort is slowed a little by a capable
compare routine. The sort may be case insensitive or numerical
(2 before 12) and may start beyond the first element of a
sequence (for 'sorting on fields').

I think these features are very desireable and I would suggest 
adding them to the Eu sort -- except that no Euphorian has ever 
asked for them! 


> When you say "Eu", I assume you mean the Euphoria
> interpreter. Don't forget that the Translator can
> give a very significant boost to the speed of Euphoria code.
> 

I certainly do mean the interpreter smile
Bach cannot and never will compete with the translator
for overall speed!  In theory it should match it on a  qsort
benchmark -- after all, a built in qsort is written in C.

Given that Bach cannot translate, bind, trace or profile, it does what 
it can in other areas.

Yours
Karl Bochert

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

12. Re: Referencing Nested Sequences

----- Original Message -----
From: <rforno at tutopia.com>
To: "EUforum" <EUforum at topica.com>
Subject: RE: Referencing Nested Sequences


>
>
> Derek:
> Are these words/expressions in a dictionary, or are they only aussie
forms?

Mostly Australian terms, many not in current usage. Here is a rough
translation...

  G'Day = (Good Day) Hello

  clued in = Realized. "To clue you in" is to pass on information to
somebody.

  vegemite = Australian. Comes from a line in an advertisment for a sandwich
spread which is unique to Australia. "We are happy little vegemites..."

  bonzer = Very good. This term is considered old-fashioned now.

  larrikin = A lovable rogue. Someone who can cause a bit of occasional
trouble but is generally tolerated, and may even be admired for it.

--
Derek

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

13. Re: Referencing Nested Sequences

Hi Karl, you wrote:

> On 7 Jun 2003 at 23:41, Robert Craig wrote:
>
>> kbochert at copper.net wrote:
>>> As an example, Bach has a built-in sort.
>>> For a sequence of 6000 chars, Eu managed 27 / sec.
>>> while Bach was 125/sec.
>>
>> If someone wanted to sort 6000 chars (0-255),
>> they could use the bucket sort in euphoria\demo\allsorts.ex,
>> and it would "blow away" your sort.  smile
>
> True enough. On my system the integer sort (allsorts.e) of
> 5120  elements gives:
> EU :    1.25 ms.
> Bach:   0.32 ms.
> Bucket: 0.12 ms
>
> The figures I quoted are for a sequence of 6000 2-character
> sequences, {"a3", "dr", ....} which accounts for the 8ms. (125/sec)
> quoted vs. the .32 ms above (and disqualifies the bucket)
>
> I should also point out that the qsort is slowed a little by a capable
> compare routine. The sort may be case insensitive or numerical
> (2 before 12) and may start beyond the first element of a
> sequence (for 'sorting on fields').
>
> I think these features are very desireable and I would suggest
> adding them to the Eu sort -- except that no Euphorian has ever
> asked for them!

I'd like to second this suggestion (and my cat does so, too smile).

<snip>

Best 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

Search



Quick Links

User menu

Not signed in.

Misc Menu