ops, my bad ... and i thought i knew python :)

Rado

On Aug 3, 4:04 pm, Kwankyu <ekwan...@gmail.com> wrote:
> On Aug 4, 5:21 am, Rado <rki...@gmail.com> wrote:
>
>
>
> > Hello,
>
> > (I apologize if this has been discussed and it is a design decision).
> > I just noticed that graphs are passed by value instead of passed by
> > reference (which i think is standard in python).
>
> > example:
>
> > sage:def modify(G):
> > sage:    G=graphs.CompleteGraph(4)
> > sage:G=graphs.PetersenGraph()
> > sage:modify(G)
> > sage:G
> > Petersen graph: Graph on 10 vertices
>
> > However, a normal python behavior should be.
>
> > sage:def modify_list(L):
> > sage:    L.append(3)
> > sage:L=[1,2]
> > sage:modify_list(L)
> > sage:L
> > [1,2,3]
>
> > This can be disastrous if your are passing big graphs.
> > Rado
>
> Graphs are nothing special. Try the following:
>
> def modify(G):
>     G.delete_vertex(0)
> G=graphs.PetersenGraph()
> modify(G)
> G
>
> In your example, you assign a different object to G, thus losing the
> original reference.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to