replace object in list

Anything that doesn't fit elsewhere.
Post Reply
pfortier
Posts: 43
Joined: Thu Apr 20, 2006 8:02 am
Location: University of Ottawa

replace object in list

Post by pfortier » Wed Dec 05, 2018 12:46 pm

For:
objref alist
alist=new List()
alist.append(new Vector())
alist.o(0) = new Vector() // Does not work !!!

My real task is to make several conversions of the vector using several obfunc created
1. put vector in alist
2. alist.o(0) = returnvectorconversion1(alist.o(0))
3. alist.o(0) = returnvectorconversion2(alist.o(0))
But this does not work.

Of course, I could
1. put vector in objref vbuffer
2. vbuffer = returnconversion1(vbuffer)
3. vbuffer = returnconversion2(vbuffer)
4. alist.append(vbuffer)

Thanks,
Pierre

ted
Site Admin
Posts: 5370
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: replace object in list

Post by ted » Thu Dec 06, 2018 1:51 pm

pfortier wrote:
Wed Dec 05, 2018 12:46 pm
For:
objref alist
alist=new List()
alist.append(new Vector())
alist.o(0) = new Vector() // Does not work !!!
Yep. According to the documentation of List in the Programmer's Reference, list.o(i) returns the object at index i. That is consistent with the documentation's statement that list.append(object) appends an object to list, and suggests that list.append(objref) appends the object instance that is referenced by objref. And it raises the question of "what happens if objref references the NULLobject?" The answer: hoc complains that "object prefix is NULL". This is bound to drive pythonistas nuts.

Ah, well, life would indeed be a vale of tears and sorrow were it not for workarounds. Thanks for sharing yours!

Post Reply