Named parameters: Difference between revisions

jq
(Add Nimrod)
(jq)
Line 566:
// => "foo is 0, bar is 3.14, and grill is lamb kebab"</lang>
 
=={{header|jq}}==
jq does not strictly speaking support named function arguments, but since jq is JSON-oriented, it is possible to achieve the desired effect by using JSON objects.
 
For example, here is the jq analog of "print-name" defined in the Common Lisp section above. Here we format the full name and return it as a string:
<lang jq>
def formatName(obj):
({ "name": "?"} + obj) as $obj # the default default value is null
| ($obj|.name) as $name
| ($obj|.first) as $first
| if ($first == null) then $name
else $name + ", " + $first
end;
</lang>
 
Here are examples of how the function can be invoked:
<lang jq>
formatName({"first": "George", "name": "Eliot"})
 
formatName({"name": "Eliot", "first": "George"})
 
formatName({"name": "Eliot"})
 
formatName({"first": "George"})
 
formatName({})
</lang>
=={{header|Julia}}==
Julia supports arbitrary named keyword arguments, which are listed (with their default values) after a <code>;</code> in the function definition:
2,496

edits