Page 1 of 1

replace object in list

Posted: Wed Dec 05, 2018 12:46 pm
by pfortier
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

Re: replace object in list

Posted: Thu Dec 06, 2018 1:51 pm
by ted
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!