From 5c8bc958328101f9cf68c2bdae39dd6bd8adec46 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Wed, 17 Apr 2024 09:59:28 -0400 Subject: [PATCH] Fix some Sphinx links --- docs/macros.rst | 4 ++-- docs/tutorial.rst | 6 ++++-- hy/compiler.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/macros.rst b/docs/macros.rst index 24a3eb397..232d0d251 100644 --- a/docs/macros.rst +++ b/docs/macros.rst @@ -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 ` 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 ` as arguments. Regular macros come in :ref:`three varieties, which vary in scope `. -**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 `, 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 ~~~~~~~~~~~~~~~~~~ @@ -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 ` object named ``&reader``, which provides all the text-parsing logic that Hy uses to parse itself (see :py:class:`HyReader ` and its base class :py:class:`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 `, 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 ` object named ``&reader``, which provides all the text-parsing logic that Hy uses to parse itself (see :py:class:`HyReader ` and its base class :py:class:`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. :: diff --git a/docs/tutorial.rst b/docs/tutorial.rst index 2d769451f..86909504d 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -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 `:: (print (cut "abcdef" 1 4)) ; => bcd @@ -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 ` or +:hy:func:`fn`. Define classes with :hy:func:`defclass`:: diff --git a/hy/compiler.py b/hy/compiler.py index 5aaa4b1a3..0800f087a 100755 --- a/hy/compiler.py +++ b/hy/compiler.py @@ -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 `, 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)