Jump to content

Named parameters: Difference between revisions

Lingo added
(Added Maple implementation.)
(Lingo added)
Line 706:
 
54#45
 
Lingo does not support named function parameters, but this can be simulated by using a single property list (hash) with named properties as function argument. You can also create a function that either excepts e.g. 3 integers or a single property list with such named properties:
<lang lingo>-- accepts either 3 integers or a single property list
on foo (arg1, arg2, arg3)
if ilk(arg1)=#propList then
args = arg1
arg1 = args[#arg1]
arg2 = args[#arg2]
arg3 = args[#arg3]
end if
put "arg1="&arg1
put "arg2="&arg2
put "arg3="&arg3
end
 
foo(1,2) -- 3rd argument omitted
-- "arg1=1"
-- "arg2=2"
-- "arg3="
 
foo([#arg3:3]) -- only 3rd argument specified
-- "arg1="
-- "arg2="
-- "arg3=3"</lang>
 
=={{header|Lua}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.