Anonymous user
Named parameters: Difference between revisions
+ forth
(jq) |
(+ forth) |
||
Line 414:
? printName(["first" => "John", "last" => "Doe"])
Doe, John</lang>
=={{header|Forth}}==
As with many of the other languages here, Forth does not have named parameters, but it does have practices that arise in situations where a Forth programmer might want named parameters. In Forth's case, these practices also arise when a more natural control language is wanted (e.g., LEFT ARM 36 DEGREES LIFT) or when a word would otherwise take excessively many arguments.
Two regrettably unnatural examples:
{{works with|Gforth}}
<lang forth>256 buffer: first-name
256 buffer: last-name
: is ( a "name" -- ) parse-name rot place ;
: greet ( -- )
cr ." Hello, " first-name count type space last-name count type ." !" ;
first-name is Bob last-name is Hall greet
require mini-oof2.fs
require string.fs
object class
field: given-name
field: surname
end-class Person
: hiya ( -- )
cr ." Hiya, " given-name $. space surname $. ." !" ;
Person new >o s" Bob" given-name $! s" Hall" surname $! hiya o></lang>
{{out}}<pre>Hello, Bob Hall!
Hiya, Bob Hall!</pre>
=={{header|Fortran}}==
|