Skip to content

Commit

Permalink
Fix some Sphinx links
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodiologist committed Apr 17, 2024
1 parent da93d33 commit 5c8bc95
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/macros.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Hy offers two types of macros: regular macros and reader macros.

**Regular macros**, typically defined with :hy:func:`defmacro`, are the kind Lispers usually mean when they talk about "macros". Regular macros are called like a function, with an :ref:`expression <expressions>` whose head is the macro name: for example, ``(foo a b)`` could call a macro named ``foo``. A regular macro is called at compile-time, after the entire top-level form in which it appears is parsed, and receives parsed :ref:`models <models>` as arguments. Regular macros come in :ref:`three varieties, which vary in scope <macro-namespaces>`.

**Reader macros**, typically defined with :hy:func:`defreader`, are lower-level than regular macros. They're called with the hash sign ``#``; for example, ``#foo`` calls a reader macro named ``foo``. A reader macro is called at parse-time. It doesn't receive conventional arguments. Instead, it uses an implicitly available parser object to parse the subsequent source text. When it returns, the standard Hy parser picks up where it left off.
**Reader macros**, typically defined with :hy:func:`defreader <hy.core.macros.defreader>`, are lower-level than regular macros. They're called with the hash sign ``#``; for example, ``#foo`` calls a reader macro named ``foo``. A reader macro is called at parse-time. It doesn't receive conventional arguments. Instead, it uses an implicitly available parser object to parse the subsequent source text. When it returns, the standard Hy parser picks up where it left off.

Related constructs
~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -159,7 +159,7 @@ Ultimately it's wisest to use only four kinds of names in macro expansions: gens
Reader macros
-------------

Reader macros allow you to hook directly into Hy's parser to customize how text is parsed into models. They're defined with :hy:func:`defreader`, or, like regular macros, brought in from other modules with :hy:func:`require`. Rather than receiving function arguments, a reader macro has access to a :py:class:`HyReader <hy.reader.hy_reader.HyReader>` object named ``&reader``, which provides all the text-parsing logic that Hy uses to parse itself (see :py:class:`HyReader <hy.reader.hy_reader.HyReader>` and its base class :py:class:`Reader <hy.reader.reader.Reader>` for the available methods). A reader macro is called with the hash sign ``#``, and like a regular macro, it should return a model or something convertible to a model.
Reader macros allow you to hook directly into Hy's parser to customize how text is parsed into models. They're defined with :hy:func:`defreader <hy.core.macros.defreader>`, or, like regular macros, brought in from other modules with :hy:func:`require`. Rather than receiving function arguments, a reader macro has access to a :py:class:`HyReader <hy.reader.hy_reader.HyReader>` object named ``&reader``, which provides all the text-parsing logic that Hy uses to parse itself (see :py:class:`HyReader <hy.reader.hy_reader.HyReader>` and its base class :py:class:`Reader <hy.reader.reader.Reader>` for the available methods). A reader macro is called with the hash sign ``#``, and like a regular macro, it should return a model or something convertible to a model.

Here's a moderately complex example of a reader macro that couldn't be implemented as a regular macro. It reads in a list of lists in which the inner lists are newline-separated, but newlines are allowed inside elements. ::

Expand Down
6 changes: 4 additions & 2 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ Access the elements of a list, dictionary, or other data structure with
(setv (get fruit 1) "durian")
(print (get fruit 1)) ; => durian

Access a range of elements in an ordered structure with :hy:func:`cut`::
Access a range of elements in an ordered structure with
:hy:func:`cut <hy.pyops.cut>`::

(print (cut "abcdef" 1 4)) ; => bcd

Expand Down Expand Up @@ -231,7 +232,8 @@ Note that unlike Python, Hy doesn't always evaluate function arguments (or
the items in a literal list, or the items in a literal dictionary, etc.) in
the order they appear in the code. But you can always force a particular
evaluation order with :hy:func:`do`, or with other macros that provide an
implicit :hy:func:`do`, like :hy:func:`when` or :hy:func:`fn`.
implicit :hy:func:`do`, like :hy:func:`when <hy.core.macros.when>` or
:hy:func:`fn`.

Define classes with :hy:func:`defclass`::

Expand Down
2 changes: 1 addition & 1 deletion hy/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ def hy_eval_user(model, globals = None, locals = None, module = None, macros = N
(hy.eval '(my-test-mac) :module hyrule) ; NameError
(hy.eval '(list-n 3 1) :module hyrule) ; => [1 1 1]
Finally, finer control of macro lookup can be achieved by passing in a dictionary of macros as the ``macros`` argument. The keys of this dictionary should be mangled macro names, and the values should be function objects to implement those macros. This is the same structure as is produced by :hy:func:`local-macros`, and in fact, ``(hy.eval … :macros (local-macros))`` is useful to make local macros visible to ``hy.eval``, which otherwise doesn't see them. ::
Finally, finer control of macro lookup can be achieved by passing in a dictionary of macros as the ``macros`` argument. The keys of this dictionary should be mangled macro names, and the values should be function objects to implement those macros. This is the same structure as is produced by :hy:func:`local-macros <hy.core.macros.local-macros>`, and in fact, ``(hy.eval … :macros (local-macros))`` is useful to make local macros visible to ``hy.eval``, which otherwise doesn't see them. ::
(defn f []
(defmacro lmac [] 1)
Expand Down

0 comments on commit 5c8bc95

Please sign in to comment.