Skip to content

Commit 531533b

Browse files
authored
Merge pull request #2632 from Kodiologist/doc-tweaks
Documentation tweaks
2 parents 1097ac8 + 42d1f40 commit 531533b

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

docs/api.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ Context managers and pattern-matching
793793
Python's ``with e1 as _: …``), ``with`` will leave it anonymous (as Python's
794794
``with e1: …``).
795795

796-
Finally, any variable-manager pair may be preceded with the keyword
796+
Finally, any variable-manager pair may be preceded by the keyword
797797
``:async`` to use an asynchronous context manager::
798798

799799
(with [:async v1 e1] …)
@@ -991,8 +991,8 @@ Functions
991991
Type parameters require Python 3.12, and have the semantics specified by
992992
:pep:`695`. The keyword ``:tp`` introduces the list of type parameters. Each
993993
item of the list is a symbol, an annotated symbol (such as ``#^ int T``), or
994-
an unpacked symbol (such as ``#* T`` or ``#** T``). As in Python, unpacking
995-
and annotation can't be used with the same parameter.
994+
an unpacked symbol (such as ``#* T`` or ``#** T``). As in Python, a single
995+
parameter can't be both annotated and unpacked.
996996

997997
.. hy:macro:: (fn [args])
998998

docs/syntax.rst

+12-2
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
@@ -454,8 +460,12 @@ example, ``{"a" 1 "b" 2}`` produces a dictionary mapping ``"a"`` to ``1`` and
454460
``"b"`` to ``2``. Trying to compile a :class:`Dict <hy.models.Dict>` with an
455461
odd number of child models is an error.
456462

457-
As in Python, calling :class:`dict` with keyword arguments is often more
458-
convenient than using a literal dictionary.
463+
As in Python, calling :class:`dict` with keyword arguments may be more
464+
convenient than using a literal dictionary when all the keys are
465+
strings. Compare the following alternatives::
466+
467+
(dict :a 1 :b 2 :c 3 :d 4 :e 5)
468+
{"a" 1 "b" 2 "c" 3 "d" 4 "e" 5}
459469

460470
.. autoclass:: hy.models.Dict
461471

docs/tutorial.rst

+11
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,17 @@ 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+
237+
You can unpack iterable objects into positional arguments with ``#*`` (:hy:func:`unpack-iterable`), or dictionary-like objects into keyword arguments with ``#**`` (:hy:func:`unpack-mapping`)::
238+
239+
(setv x [1 2 3])
240+
(setv y {"d" 4})
241+
(test #* x #** y) ; => [1, 2, 3, 4, ()]
242+
232243
Note that unlike Python, Hy doesn't always evaluate function arguments (or the
233244
items in a literal list, or the items in a literal dictionary, etc.) :ref:`in
234245
the order they appear in the code <order-of-eval>`. But you can always force a

0 commit comments

Comments
 (0)