Named parameters: Difference between revisions

Content added Content deleted
m (→‎{{header|Haskell}}: whitespace)
No edit summary
Line 30: Line 30:
WinWaitClose, %A_ScriptFullPath%
WinWaitClose, %A_ScriptFullPath%
}</lang>
}</lang>

=={{header|Clojure}}==

Clojure doesn't have built-in support for named or keyword arguments, but you can use destructuring to achieve a similar effect.

<lang lisp>(defn foo [& opts]
(let [opts (merge {:bar 1 :baz 2} (apply hash-map opts))
{:keys [bar baz]} opts]
[bar baz]))</lang>

You can also use <code>defnk</code> from <code>clojure.contrib.def</code>, which is a macro that works similarly.

<lang lisp>(use 'clojure.contrib.def)
(defnk foo [:bar 1 :baz 2]
[bar baz])</lang>

Sample output for both:

<pre>user> (foo :baz 123)
[1 123]

user> (foo :bar 456)
[456 2]</pre>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==