Re: Updating parameters in a procedure / function

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

Hi there,

You could also use local variables for the sequences, and pass
the new items name plus a constant to indicate which sequence the
new item should be added too...


constant MYCARS=1,MYTRUCKS=2,MYTHINGS=3 --etc.
sequence MyCars,MyTrucks,MyThings
MyCars={}
MyTrucks={}
MyThings={}

global function AddItem(sequence Item,sequence Type)
  if Type=MYCARS then
    MyCars=append(MyCars,Item) --or whatever
    return length(MyCars)
  elsif Type=MYTRUCKS then
    MyTrucks=append(MyTrucks,Item) --or whatever
    return length(MyTrucks)
  elsif Type=MYTHINGS then
    MyThings=append(MyThings,Item) --or whatever
    return length(MyThings)
  else
    Print("Unknown Type has been specified")
  end if
  return 0
end function

AddItem("Benz",MYCARS)
AddItem("Chevy",MYTRUCKS)
AddItem("Coffee Cup",MYTHINGS)
--etc.

Note there are a lot of variations with doing something like this.
The best choice takes into consideration how you need to add 
catagories as well as how you need to add items.
This 'local' sequence approach is very clean as the sequences are
encapsulated and they are also relatively small, but to add another
catagory you have to add another
constant and another sequence declaration to the file.

You can also use one big sequence to hold everything, where the
'constants' are generated as you add catagories.  You do end up 
with more unreadable code however, because you have to use numbers
instead of constants:
  AddItem("Chevy",2)
and you have to remember the numbers and which are for what.
Perhaps an associative list where you add catagories:
  AddCatagory("MyTrucks")
then you refer to this catagory by name:
  AddItem("Chevy","MyTrucks")

You could also use set names to add items:
  AddTrucks("Chevy")

but this isnt as flexible.



Good luck,
Al

E boa sorte com sua programacao Euphoria!


My bumper sticker: "I brake for LED's"

 From "Black Knight":
"I can live with losing the good fight,
 but i can not live without fighting it".
"Well on second thought, maybe not."

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

Search



Quick Links

User menu

Not signed in.

Misc Menu