Call a function: Difference between revisions

m
Line 2,040:
=={{header|Phix}}==
Phix has three kinds of routines: procedure, function, and type. A procedure does not return a value, whereas a function does.
A type is a specialised kind of function, that permits declarations of instances ofwhich thatare type,automatically whichvalidated whenever they are changed, further a type routine always returns either true or false.
automatically validated whenever they are changed, and further the type routine always returns true or false.
* Phix does not allow implicit discard of function results. The explicit discard statement takes the form
<lang Phix>{} = myfunction()</lang>
* This is in fact a simple contraction of standard multiple assigment (which can be nested as deeply as you like):
<lang Phix>{cities,populations} = columize(muncipalities)
{{},populations} = columize(muncipalities) -- discard result[1]
{cities,{}} = columize(muncipalities) -- discard result[2]
{cities} = columize(muncipalities) -- ""</lang>
* Calling a function with no parameters still requires the "()" empty argument list.
* Optional arguments are denoted simply by the presence of a default, and must be grouped on the right:
<lang Phix>function myfunction(integer a, string b="default")
return {a,b}
Line 2,062 ⟶ 2,061:
--?myfunction(b:="though") -- compile-time error</lang>
* The programmer is free to use either positional parameters or named parameters, or a mixture of both (with positional parameters first).
* Phix does not support first-class functions, but instead uses an integer routine_id mechanism (and obviously integers are first -class):
<lang Phix>constant integer r_my_func = routine_id("myroutine")
?call_func(r_my_func,{1}) -- displays {1,"default"}</lang>
Line 2,072 ⟶ 2,071:
* All arguments are passed by reference with copy-on-write semantics: to modify the value of a parameter you must both return and assign it, as in:
<lang Phix>s = append(s,item)</lang>
* Implicit forward calls are supported, as are optional explicit forward declarations, which occasionallycan giveoccasionally bettercure compilation error messages.
 
=={{header|PicoLisp}}==
7,820

edits