1. 1 little sequence problem
------=_NextPart_000_005C_01BF9057.280A9580
charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable
Can you help me out here, I just can't get over this.
when i use this code:
sequence s1
for i=3D1 to 10 do
s1[i]=3Di
end for
i get error message: variable s1 has not been assigned a value=20
And when i add this:
s1=3D{}
i get this error message:=20
subscript value 1 is out of bounds, assigning to a sequence of length 0=20
Are sequences in general so compilcated and error making? I have stuck =
several times now with sequence problem (when using integer, object,... =
types with them ...), and i have used euphoria for programming little =
time.
Though I think sequences are the best thing in Euphoria, specially when =
compared with C.(!!awful!!) I wont be using C anymore (not so often) =
because i cant get anywhere wit it.
------=_NextPart_000_005C_01BF9057.280A9580
charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-2" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3401" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Can you help me out here, I just can't =
get over=20
this.<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>when i use this code:</FONT></DIV>
<DIV> </DIV>
<DIV><FONT color=3D#808000 face=3DArial size=3D2><EM>sequence s1<BR>for =
i=3D1 to 10=20
do<BR> s1[i]=3Di<BR>end for</EM></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>i get error message: <FONT =
color=3D#ff0000>variable=20
s1 has not been assigned a value </FONT></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>And when i add this:</FONT></DIV>
<DIV><FONT color=3D#808000 face=3DArial size=3D2>s1=3D{}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>i get this error message: </FONT></DIV>
<DIV><FONT color=3D#ff0000 face=3DArial size=3D2>subscript value 1 is =
out of bounds,=20
assigning to a sequence of length 0 </FONT></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2>Are sequences in =
general so=20
compilcated and error making? I have stuck several times now with =
sequence=20
problem (when using integer, object,... types with them ...), and i have =
used=20
euphoria for programming little time.</FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2>Though I think =
sequences are the best=20
thing in Euphoria, specially when compared with C.(!!awful!!) I wont be =
using C=20
anymore (not so often) because i cant get anywhere wit=20
------=_NextPart_000_005C_01BF9057.280A9580--
2. Re: 1 little sequence problem
Try this:
sequence s1
s1 =3D {}
for a =3D 1 to 10
s1 =3D s1 & a
end for
& is the concatenation command, and works best for adding an atom to a =
sequence, or merging two sequences together. To add a sequence as an =
element of a sequence, use s1 =3D append(s1,s2) or s1 =3D prepend(s1,s2).
HTH,
Michael J. Sabal
>>> tone.skoda at SIOL.NET 03/17/00 03:24PM >>>
Can you help me out here, I just can't get over this.
when i use this code:
sequence s1
for i=3D1 to 10 do
s1[i]=3Di
end for
3. Re: 1 little sequence problem
>From: =A9koda
>sequence s1
>for i=3D1 to 10 do
> s1[i]=3Di
>end for
>i get error message: variable s1 has not been assigned a value=20
Sequences are dynamic, but you can't subscript something that's not =
already
there. There are a couple of things you can do:
s1 =3D repeat(0, 10)
for i=3D1 to 10 do
s1[i]=3Di
end for
-- This is probably the fastest (see performance tips in the Eu docs)
s1 =3D { 0,0,0,0,0,0,0,0,0,0}
for i=3D1 to 10 do
s1[i]=3Di
end for
or:
sequence s1
s1 =3D {}
for i=3D1 to 10 do
s1 &=3D i
end for
Matt
4. Re: 1 little sequence problem
=A9koda wrote:
> i get error message: variable s1 has not been assigned a value=20
true.
> subscript value 1 is out of bounds, assigning to a sequence of length =
0=20
think of the slice as trying to *replace* an existing item. so when you
write:
s1[1] =3D i
you say:
"replace the first item in the sequence s1 with i"
since there is no *first item* in s1 (it's empty, remember?), you get =
an
error.=20
these are logical errors of the same type. think of the sequence as an =
array
in this case - you can't ask for the nth item in the array if the array =
is
*smaller* than the index. in basic:
dim s1[0]
print s1[1] <-- error, the array has zero items in it.
when you wrote:
s1 =3D {}
you initialized the variable to an empty sequence - it still has no =
items in
it. so you can't ask for the nth item - there is no such animal. first
*fill* the sequence, and then replace the values, it will work:
sequence s1
' fill it with 10 zeros
s1 =3D repeat( 0, 10 )
for i =3D 1 to 10 do
' replace the i'th zero with i
s1[i] =3D i
end for
in this case:
s1 =3D repeat( 0, 10 )
is more or less akin to:
dim s1[10]
or you could build the sequence by appending value to the end of it:
sequence s1
' make it empty
s1 =3D {}
for i =3D 1 to 10 do
' append to the sequence
s1 =3D s1 & i
end for
or more succinctly, write:
s1 &=3D i
insead of:
s1 =3D s1 & i
Hope this helps!
-- David Cuny
5. Re: 1 little sequence problem
On Fri, 17 Mar 2000 21:24:19 +0100, =?iso-8859-2?B?qWtvZGE=?=
<tone.skoda at SIOL.NET> wrote:
>Can you help me out here, I just can't get over this.
>
>when i use this code:
>
>sequence s1
>for i=1 to 10 do
> s1[i]=i
>end for
>
>i get error message: variable s1 has not been assigned a value
>
>And when i add this:
>s1={}
>i get this error message:
>subscript value 1 is out of bounds, assigning to a sequence of length 0
sequences are dynamic but must be created to a given size
or be grown by appending a value.
Your example can be corrected in two ways
sequence s1
-- this creates a sequence of 10 zeros
s1 = {0,0,0,0,0,0,0,0,0,0}
for i=1 to 10 do
s1[i]=i
end for
or
sequence s1
-- this creates an empty sequence and appends to it
s1 = {}
for i=1 to 10 do
s1 &= i
end for
the reason you have an error is because Euphoria does not know
a beginning size of your sequence.
Bernie