Optional parameters: Difference between revisions

Content added Content deleted
(→‎{{header|Tcl}}: note on language conventions, minor formatting improvements)
Line 163: Line 163:
=={{header|OCaml}}==
=={{header|OCaml}}==


OCaml has optional named parameters. It is conventional to place a non-optional parameter after the optional parameters, because if the optional parameters were at the end, then if you don't provide them, it will just look like a partial application (because OCaml supports currying), resulting in a function which still expects the optional parameters.
OCaml has optional named parameters.


<lang ocaml>let sort_table ?(ordering = compare) ?(column = 0) ?(reverse = false) table =
<lang ocaml>let sort_table ?(ordering = compare) ?(column = 0) ?(reverse = false) table =
Line 188: Line 188:
- : string list list =
- : string list list =
[["zap"; "zip"; "Zot"]; ["a"; "b"; "c"]; [""; "q"; "z"]]</lang>
[["zap"; "zip"; "Zot"]; ["a"; "b"; "c"]; [""; "q"; "z"]]</lang>

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|Python}}==
=={{header|Python}}==