Re: Updating parameters in a procedure / function
- Posted by ZNorQ <znorq at holhaug.com> Jul 14, 2006
- 563 views
don cole wrote: > > ZNorQ wrote: > > > > I want to create a function that adds an element to a sequence, and returns > > the index in the sequence. I want it to be flexible, so that it can > > update any sequence - but how do I do that? > > > > For example; > > > > }}} <eucode> > > atom idx idx = 0 > > sequence myCars myCars = {} > > sequence myPhones myPhones = {} > > sequence myGirlFriends myGirlFriends = {} > > > > function addElement(sequence Element, sequence mySequence) > > mySequence = append(mySequence, Element) > > return length(mySequence) > > end function > > > > idx = addElement("Audi", myCars) > > idx = addElement("99 99 99 99", myPhones) > > idx = addElement("Trine", myGirlFriends) > > </eucode> {{{ > > > > Regards, > > Kenneth / ZNorQ > > Hello ZNorQ, > > It seems to me you would want: > > }}} <eucode> > atom idx idx = 0 > sequence myCars myCars = {} > sequence myPhones myPhones = {} > equence myGirlFriends myGirlFriends = {} > > function addElement(sequence Element, sequence mySequence) > mySequence = append(mySequence, Element) > return mySequence > end function > > myCars=addElement("Audi",myCars) > idx=length(myCars) > > myPhones = addElement("99 99 99 99", myPhones) > idx=length(myPhones) > > myGirlFriends = addElement("Trine", myGirlFriends) > idx=length(myGirlFriends) > > ----------------also you could------------------- > function addElement(sequence Element, sequence mySequence) > mySequence = append(mySequence, Element) > return {mySequence }& {length(mySequence}) > end function > > junk=addElement("Audi",myCars) > myCars=junk[1] > idx=junk[2] > > junk=addElement("99 99 99 ",myPhones) > myPhones=junk[1] > idx=junk[2] > > junk=addElement("Trine", GirlFriends) > myGirlFriends=junk[1] > idx=junk[2] > > > </eucode> {{{ > > > Don Cole Hey Don, Yeah, I thought of both those examples, but I was kinda hoping I could do it in one go only, like in my example... :) I remember back in the pascal days, you could use a "var" statement (I think) in the procedure/function declaration, and that would tell it that it should manipulate the global variable, instead of using a copy of the global. I guess we call them pointers.. :) Regards, Kenneth