Named parameters: Difference between revisions

Content added Content deleted
(Added Lua example)
Line 307: Line 307:
example({grill: "lamb kebab", bar: 3.14});
example({grill: "lamb kebab", bar: 3.14});
// => "foo is 0, bar is 3.14, and grill is lamb kebab"</lang>
// => "foo is 0, bar is 3.14, and grill is lamb kebab"</lang>
=={{header|Lua}}==

<lang Lua>
function CreatePet(options)
local name=options.name
local species=options.name
local breed=options.species
print('Created a '..breed..' '..species..' named '..name)
end
CreatePet{name='Rex',species='Dog',breed='Irish Setter'}
--position does not matter here.
</lang>
=={{header|Modula-3}}==
=={{header|Modula-3}}==
Much like [[Ada]], Modula-3 allows either positional or keyed association of actual parameters. Defaults can also be ignored.
Much like [[Ada]], Modula-3 allows either positional or keyed association of actual parameters. Defaults can also be ignored.