Skip to content

Commit c223576

Browse files
committed
Document allowing keyword args before positional
I can't believe I never wrote this down. Maybe it's in the manual elsewhere and now I've misplaced it. Oh well.
1 parent e41fcc3 commit c223576

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

docs/syntax.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ at compile-time. To prevent a literal keyword from being treated specially in
190190
an expression, you can :hy:func:`quote` the keyword, or you can use it as the
191191
value for another keyword argument, as in ``(f :foo :bar)``.
192192

193+
Whereas Python requires all positional arguments in a call to precede all
194+
keyword arguments, Hy allows them to mingled, as in ``(f 1 :foo 2 3)``. This is
195+
implemented by simply moving the keyword arguments back, as in ``(f 1 3 :foo
196+
2)``, with the attendant consequences for order of evaluation (:ref:`which
197+
shouldn't generally be relied upon in Hy <order-of-eval>`).
198+
193199
Otherwise, keywords are simple model objects that evaluate to themselves. Users
194200
of other Lisps should note that it's often a better idea to use a string than a
195201
keyword, because the rest of Python uses strings for cases in which other Lisps

docs/tutorial.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ Set a function parameter by name with a ``:keyword``::
229229

230230
(test 1 2 :d "y") ; => [1, 2, None, 'y', ()]
231231

232+
Keyword arguments may be placed before or among positional arguments, with the
233+
same effect as putting all the positional arguments first::
234+
235+
(test 1 :d "y" 2) ; => [1, 2, None, 'y', ()]
236+
232237
Note that unlike Python, Hy doesn't always evaluate function arguments (or the
233238
items in a literal list, or the items in a literal dictionary, etc.) :ref:`in
234239
the order they appear in the code <order-of-eval>`. But you can always force a

0 commit comments

Comments
 (0)