Re: Updating parameters in a procedure / function

new topic     » goto parent     » topic index » view thread      » older message » newer message

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:

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]

> 



Don Cole

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu