1. sequence length allocation

I run the following simple program:

sequence s
s =3D "hell"
s[5] =3D 'o'

Most of you will immediately recognize that there is an error here, becau=
se
I allegedly assigned a fifth value to a length 4 sequence.  Well, I plead=

guilty, but I appeal because this should not be illegal.  Sure, I can use=

append, but the above syntax seems a lot more straightforward.  What woul=
d
we loose?  Also, I still have a initialize every sequence and specify at
least an initial length.  This is not complete dynamic storage allocation=
,
to me.

At least, I feel there should be a sequence initialized as an indefinite
length.

In Euphoria, I still have to initialize the sequence, and tell Euphoria
what length it should be initially.  There are tools to append and prepen=
d,
but that only masks the truth that we still have to tell Euphoria what th=
e
length of the sequence is.  It seems that if I have a database, with one
sequence with each sub-sequence being a record, I could just simply do
something like this:

s[length(s)+1] =3D new record

I feel this is a more direct approach, than append could ever be. =

Although, it is possible that C, which Euphoria is written in, forces
Euphoria to be like this.

Just a thought.

Alan
  =

new topic     » topic index » view message » categorize

2. Re: sequence length allocation

Alan wrote:

> sequence s
> s = "hell"
> s[5] = 'o'

 Hm. Even I hesistate at that one. blink

I'd issue want the program to warning, and add nothing to the sequence.
After all, should:

    sequence s
    s = 'foo'
    s[6] = 'o'

append as well, and create filler for s[4] and s[5]? Should the be blanks,
or zeros?

-- David Cuny

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

3. Re: sequence length allocation

>append as well, and create filler for s[4] and s[5]? Should the be
>blanks,
>or zeros?

All right, how about an indefinite sequence.  It just seems that I have t=
o
specify the length of the sequence, initialize it.  Euphoria has routines=

to make this a ton less painful to manipulate sequences, but still.  Your=

example is noted, though.  I did consider the possibility of runaway
sequences.

--Alan
 =

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

4. Re: sequence length allocation

-----Original Message-----
De: Alan Tu <ATU5713 at COMPUSERVE.COM>
Para: EUPHORIA at cwisserver1.mcs.muohio.edu
<EUPHORIA at cwisserver1.mcs.muohio.edu>
Fecha: Miércoles 5 de Agosto de 1998 10:32 AM
Asunto: sequence length allocation


>s[length(s)+1] = new record

>I feel this is a more direct approach, than append could ever be.
>Although, it is possible that C, which Euphoria is written in, forces
>Euphoria to be like this.

You can achieve the same with the '&' operator:

s = s & new_record

Perhaps there is a chance to have a &= operator in Euphoria (as
well as +=, -=, /=, etc...)

Regards,
    Daniel   Berstein
    daber at pair.com

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

5. Re: sequence length allocation

Alan Tu wrote:
> I run the following simple program:
> sequence s
> s = "hell"
> s[5] = 'o'
>
> Most of you will immediately recognize that there
> is an error here, because I allegedly assigned a
> fifth value to a length 4 sequence.  Well, I plead
> guilty, but I appeal because this should not be illegal.

I agree here. One caveat tho, it should only be allowed
for 1 index past length(s).

> Also, I still have a initialize every sequence and specify at
> least an initial length.  This is not complete dynamic storage
> allocation, to me.

On this note, I disagree. Assigning s={} does not necessarily
give "an initial length". Nor do you even need to do that.
ex:
sequence name
puts(SCR,"what is your name?")
name = gets(KB)
if name[1] = GET_SUCCESS then
   name = name[2]
end if

In this example, name is neither initialized NOR given
an initial length... looks pretty dynamic to me... shrug

> At least, I feel there should be a sequence initialized
> as an indefinite length. In Euphoria, I still have to
> initialize the sequence, and tell Euphoria what length
> it should be initially.
errrrrr.... see above?

> It seems that if I have a database, with one
> sequence with each sub-sequence being a record,
> I could just simply do something like this:
> s[length(s)+1] = new record
> I feel this is a more direct approach than append
> could ever be.
Now here I agree. With of course, the caveat mentioned
above. Just like you can slice S[3..2] and come up
{}, you should be able to do the above. Certain routines
could be heavily optimized, simplified and easier to read.

tnx for listening, --Hawke'

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

6. Re: sequence length allocation

The problem I have with this is that your intention is not known.
If you code...
  s[5] = 'o'
the compiler has to guess between two options,
a) You want to extent the sequence,
b) You made a mistake with the index number.

As b) is a real possibility, the safer way of doing
this is to tell the compiler what it is you are trying
to do. Maybe something like...

  s[#5] = 'o'

to explicilty and simply tell the compiler that
you are extending the sequence and element 5 is
to be set to 'o'. Of course, what happens to the
elements between the existing last one and the 5th
one is a mystery. So maybe even this ...

  s[#] = 'o'

could be used to say "append to the sequence". This
way you wouldn't have to know its current length.

cheers,
Derek Parnell
dparnell @ vic.bigpond.net.au
Melbourne, Australia
-----Original Message-----
From: Alan Tu <ATU5713 at COMPUSERVE.COM>
To: EUPHORIA at cwisserver1.mcs.muohio.edu
<EUPHORIA at cwisserver1.mcs.muohio.edu>
Date: Wednesday, August 5 1998 23:32
Subject: sequence length allocation


|I run the following simple program:
|
|sequence s
|s = "hell"
|s[5] = 'o'
|
|Most of you will immediately recognize that there is an error here, because
|I allegedly assigned a fifth value to a length 4 sequence.  Well, I plead
|guilty, but I appeal because this should not be illegal.  Sure, I can use
|append, but the above syntax seems a lot more straightforward.  What would
|we loose?  Also, I still have a initialize every sequence and specify at
|least an initial length.  This is not complete dynamic storage allocation,
|to me.
|
|At least, I feel there should be a sequence initialized as an indefinite
|length.
|
|In Euphoria, I still have to initialize the sequence, and tell Euphoria
|what length it should be initially.  There are tools to append and prepend,
|but that only masks the truth that we still have to tell Euphoria what the
|length of the sequence is.  It seems that if I have a database, with one
|sequence with each sub-sequence being a record, I could just simply do
|something like this:
|
|s[length(s)+1] = new record
|
|I feel this is a more direct approach, than append could ever be.
|Although, it is possible that C, which Euphoria is written in, forces
|Euphoria to be like this.
|
|Just a thought.
|
|Alan
|

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

Search



Quick Links

User menu

Not signed in.

Misc Menu