Re: lists in breve
jon klein <[email protected]> Sat, 3 Sep 2005 13:26:48 -0400
| Newsgroups | gmane.comp.breve |
|---|---|
| Message-ID | <[email protected]> |
--===============94539072478933006==
Content-Type: multipart/alternative; boundary=Apple-Mail-1--715162912
--Apple-Mail-1--715162912
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed
On Sep 3, 2005, at 1:15 PM, Anand Veeraswamy wrote:
> Hi,
>
> I have 2 issues while using lists in breve.
>
> 1) If I have a nested list like tempList={ {1,2}, {3,4} }
> I am able to access individual elements of this
> list using tempList{0}{0} or tempList{0}{1} which will give 1 and 2
> respectively
> But I am unable to create a nested list using the
> following commands
> tempList{0}{0} = 1
> tempList{0}{1} = 2
> when I try using the above 2 commands I get an
> error saying that the "list index 0 is out of bounds"
>
> Why does this happen??
>
> Is there any other method to create nested lists??
> I need to assign the individual elements of the nested list.
I think the problem is that breve doesn't know that tempList{0} is a
list, since there is nothing there yet. Try doing this:
tempList{0} = {}. # initialize to an empty list
tempList{0}{0} = 1. # now assign the elements.
> 2) In order to over come this issue I started using the push list
> function
> I create 2 lists like .....
>
> tempList1 = { LifePatch (0A458E38) , LifePatch
> (0A459080) } # LifePatch is the name of the class which inherits
> the Patch class
> tempList2 = { LifePatch (0A458E38) , LifePatch
> (0A458760) } # The elements of the list are Patches
>
> Then I use the push function in this way
>
> push tempList1 onto pathList.
> push tempList2 onto pathList.
>
> Now when I check the pathList I get something like this
> pathList = { { LifePatch (0A458E38) , LifePatch
> (0A458760) }, [circular list reference 0A49FED0] }
>
> What is Circular list reference??
>
> Actually I am using a while loop to implement the above
> coding
>
> while(length3>=0): {
> i=0.
> tempList2{i} = tempList1{0}.
> i++.
> tempList2{i} = neighborList{length3}.
> push tempList2 onto pathList. # At each iteration
> the list created is pushed
> length3--.
> }
>
A circular list reference means that a reference to the list itself
is embedded in the list somehow! Here's the simplest way this might
happen:
myList{ 0 } = myList.
I don't see exactly where it's happening in your code because I don't
know the exact contents of the lists you're manipulating, but it's
likely that something similar is happening there.
Circular list references can be useful if, for example, you're
encoding some sort of directed graph, but most of the time they're
not used and can cause infinite loops or other problems as you
attempt to use the list.
- jon klein
--Apple-Mail-1--715162912
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=ISO-8859-1
<HTML><BODY style=3D"word-wrap: break-word; -khtml-nbsp-mode: space; =
-khtml-line-break: after-white-space; "><BR><DIV><DIV>On Sep 3, 2005, at =
1:15 PM, Anand Veeraswamy wrote:</DIV><BR =
class=3D"Apple-interchange-newline"><BLOCKQUOTE type=3D"cite"> =
<DIV><FONT face=3D"Arial" size=3D"2">Hi,</FONT></DIV> <DIV><FONT =
face=3D"Arial" size=3D"2"></FONT>=A0</DIV> <DIV><FONT face=3D"Arial" =
size=3D"2">I have 2 issues while using lists in breve.</FONT></DIV> =
<DIV><FONT face=3D"Arial" size=3D"2"></FONT>=A0</DIV> <DIV><FONT =
face=3D"Arial" size=3D"2">1)=A0 If I have a nested list like tempList=3D{ =
{1,2}, {3,4} }</FONT></DIV> <DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0=
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 I am able to access individual elements =
of this list using tempList{0}{0} or tempList{0}{1} which will give 1 =
and=A02 respectively</FONT></DIV> <DIV><FONT face=3D"Arial" size=3D"2">=A0=
=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 But I am unable to create a nested =
list using the following commands </FONT></DIV> <DIV><FONT face=3D"Arial" =
size=3D"2">=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =
tempList{0}{0}</FONT>=A0<FONT face=3D"Arial" size=3D"2">=3D =
1</FONT></DIV> <DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 tempList{0}{1} =3D 2</FONT></DIV> =
<DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=
when I try using the above 2 commands I get an error saying that the =
"list index 0 is out of bounds"</FONT></DIV> <DIV><FONT face=3D"Arial" =
size=3D"2"></FONT>=A0</DIV> <DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0=
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 Why does this happen?? </FONT></DIV> =
<DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0</FONT></DIV> <DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0 =A0=A0=A0=
=A0=A0=A0 =A0=A0=A0 Is there any other method to create nested lists?? =
I need to assign the individual elements of the nested =
list.</FONT></DIV> </BLOCKQUOTE><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>I think the problem is that =
breve doesn't know that tempList{0} is a list, since there is nothing =
there yet.=A0 Try doing this:</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>tempList{0} =3D {}. # =
initialize to an empty list</DIV><DIV>tempList{0}{0} =3D 1. # now assign =
the elements.</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><BR><BLOCKQUOTE =
type=3D"cite"><DIV></DIV> <DIV><FONT face=3D"Arial" size=3D"2">2) In =
order to over come this issue I started using the push list =
function</FONT></DIV> <DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0 =A0=A0=
=A0 =A0=A0=A0 I create 2 lists like .....</FONT></DIV> <DIV><FONT =
face=3D"Arial" size=3D"2">=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =
</FONT></DIV> <DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0 =A0=A0=A0 =
=A0=A0=A0 tempList1 =3D { LifePatch (0A458E38) , LifePatch (0A459080)=A0 =
} # LifePatch is the name of the class=A0which inherits the Patch =
class</FONT></DIV> <DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0 tempList2=A0=3D { LifePatch (0A458E38) , LifePatch =
(0A458760)=A0 } # The elements of the list are Patches</FONT></DIV> =
<DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0</FONT></DIV> <DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0 =
=A0=A0=A0 =A0=A0=A0 Then I=A0use the push function=A0in this =
way</FONT></DIV> <DIV><FONT face=3D"Arial" size=3D"2"></FONT>=A0</DIV> =
<DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 push =
tempList1 onto pathList.=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 </FONT></DIV> =
<DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 push =
tempList2 onto pathList.</FONT></DIV> <DIV><FONT face=3D"Arial" =
size=3D"2"></FONT>=A0</DIV> <DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0=
=A0=A0=A0 =A0=A0=A0 Now when I check the pathList I get something like =
this</FONT></DIV> <DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0 =A0=A0=A0=
=A0=A0=A0 pathList =3D { { LifePatch (0A458E38) , LifePatch (0A458760)=A0=
}, <U><STRONG>[circular list reference 0A49FED0] =
</STRONG></U>}</FONT></DIV> <DIV><FONT face=3D"Arial" =
size=3D"2"></FONT>=A0</DIV> <DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0=
=A0=A0=A0 =A0=A0=A0 <STRONG>What is Circular list reference?? =
</STRONG></FONT></DIV> <DIV><FONT face=3D"Arial" size=3D"2"></FONT>=A0</DI=
V> <DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =
Actually I am using a while loop to implement the above =
coding</FONT></DIV> <DIV><FONT face=3D"Arial" size=3D"2"></FONT>=A0</DIV> =
<DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =
while(length3>=3D0): {<BR>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
i=3D0.<BR>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 tempList2{i} =3D =
tempList1{0}. </FONT></DIV> <DIV><FONT face=3D"Arial" size=3D"2">=A0=A0=A0=
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 i++.=A0=A0=A0<BR>=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0 tempList2{i} =3D neighborList{length3}.</FONT><FONT =
face=3D"Arial" size=3D"2"><BR>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
push tempList2 onto pathList.=A0# At each iteration the list created is =
pushed <BR>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =
length3--.<BR>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }</FONT></DIV> <DIV><BR =
class=3D"khtml-block-placeholder"></DIV></BLOCKQUOTE><BR></DIV><DIV>A =
circular list reference means that a reference to the list itself is =
embedded in the list somehow!=A0 Here's the simplest way this might =
happen:</DIV><DIV><BR class=3D"khtml-block-placeholder"></DIV><DIV>myList{=
0 } =3D myList.</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>I don't see exactly where =
it's happening in your code because I don't know the exact contents of =
the lists you're manipulating, but it's likely that something similar is =
happening there.</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>Circular list references =
can be useful if, for example, you're encoding some sort of directed =
graph, but most of the time they're not used and can cause infinite =
loops or other problems as you attempt to use the list.</DIV><DIV><BR =
class=3D"khtml-block-placeholder"></DIV><DIV>- jon =
klein</DIV></BODY></HTML>=
--Apple-Mail-1--715162912--
--===============94539072478933006==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
breve mailing list
[email protected]
http://lists.spiderland.org/mailman/listinfo/breve
--===============94539072478933006==--