Variadic function
editable example
Click the pencil to open this in an editor, change it, and run it in your browser. The same solution is posted on Rosetta Code.
ghul
use IO.Std.write_line
use Collections.LIST
use Ghul.Pipes
print_all[T](values: T[]) is
for value in values do
write_line("{value}")
od
si
class ▼Animal(name: string) abstract is
◆▼speak() -> string
▲to_string() -> string => "{name} says {speak()}"
si
class CAT(name: string): Animal is
super(name)
▲speak() -> string => "meow"
si
class DOG(name: string): Animal is
super(name)
▲speak() -> string => "woof"
si
herd(animals: Animal[]) is
for animal in animals do
write_line("{animal}")
od
si
print_all(["one", 2, 3.5])
herd([CAT("felix"), DOG("rex")])
let animals = LIST[Animal]()
animals.add(CAT("tom"))
animals.add(DOG("spot"))
herd(animals |> collect_array())