Optional parameters: Difference between revisions

Content added Content deleted
m (Fixed lang tags.)
(Added Oz example.)
Line 490: Line 490:


OCaml does not support optional positional parameters, because, since OCaml supports currying, it would conflict with partial applications, where you do not provide all the arguments to a function, and it results in a function which expects the remaining arguments.
OCaml does not support optional positional parameters, because, since OCaml supports currying, it would conflict with partial applications, where you do not provide all the arguments to a function, and it results in a function which expects the remaining arguments.

=={{header|Oz}}==
Oz supports optional parameters only for methods, not for functions.
<lang oz>declare
class Table
attr
rows

meth init(Rows)
rows := Rows
end

meth sort(ordering:O<=Lexicographic column:C<=1 reverse:R<=false)
fun {Predicate Row1 Row2}
Res = {O {Nth Row1 C} {Nth Row2 C}}
in
if R then {Not Res} else Res end
end
in
rows := {Sort @rows Predicate}
end
end

fun {Lexicographic As Bs} %% omitted for brevity
end

T = {New Table init([["a" "b" "c"] ["" "q" "z"] ["zap" "zip" "Zot"]])}
in
{T sort}
{T sort(column:3)}
{T sort(column:2)}
{T sort(column:2 reverse:true)}
{T sort(ordering:fun {$ A B} {Length B} < {Length A} end)}</lang>



=={{header|Perl}}==
=={{header|Perl}}==