Skip to content

Commit 37d1637

Browse files
committed
Minor documentation edits
1 parent 1231804 commit 37d1637

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

docs/macros.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ You don't need to always return a model because the compiler calls :hy:func:`hy.
7070
Arguments are always passed in as models. You can use quasiquotation (see :hy:func:`quasiquote`) to concisely define a model with partly literal and partly evaluated components::
7171

7272
(defmacro set-to-2 [variable]
73-
`(setv ~variable 2))
73+
`(setv ~variable 2))
7474
(set-to-2 foobar)
7575
(print foobar)
7676

@@ -160,19 +160,26 @@ By the way, despite the need for ``eval-and-compile``, extracting a lot of compl
160160
The important take-home big fat WARNING
161161
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
162162

163-
A typical macro should use only four kinds of names in its expansion: gensyms, core macros, objects that Python puts in scope by default (like its built-in functions), and ``hy`` and its attributes. It's possible to rebind nearly all these names, so surprise shadowing is still theoretically possible. Unfortunately, the only way to prevent these pathological rebindings from coming about is… don't do that. Don't make a new macro named ``setv`` or name a function argument ``type`` unless you're ready for every macro you call to break, the same way you wouldn't monkey-patch a built-in Python module without thinking carefully. This kind of thing is the responsibility of the macro caller; the macro writer can't do much to defend against it. There is at least a pragma :ref:`warn-on-core-shadow <warn-on-core-shadow>`, enabled by default, that causes ``defmacro`` and ``require`` to warn you if you give your new macro the same name as a core macro.
163+
A typical macro should use only names of these four kinds in its expansion:
164+
165+
- gensyms
166+
- core macros
167+
- objects that Python puts in scope by default (like its built-in functions)
168+
- ``hy`` and its attributes
169+
170+
It's possible to rebind nearly all these names, so surprise shadowing is still theoretically possible. Unfortunately, the only way to prevent these pathological rebindings from coming about is… don't do that. Don't make a new macro named ``setv`` or name a function parameter ``type`` unless you're ready for every macro you call to break, the same way you wouldn't monkey-patch a built-in Python module without thinking carefully. This kind of thing is the responsibility of the macro caller; the macro writer can't do much to defend against it. There is at least a pragma :ref:`warn-on-core-shadow <warn-on-core-shadow>`, enabled by default, that causes ``defmacro`` and ``require`` to warn you if you give your new macro the same name as a core macro.
164171

165172
.. _reader-macros:
166173

167174
Reader macros
168175
-------------
169176

170-
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:`hy.HyReader` object named ``&reader``, which provides all the text-parsing logic that Hy uses to parse itself (see :py:class:`hy.HyReader` and its base class :py:class:`hy.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.
177+
Reader macros allow you to hook 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:`hy.HyReader` object named ``&reader``, which provides all the text-parsing logic that Hy uses to parse itself (see :py:class:`hy.HyReader` and its base class :py:class:`hy.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.
171178

172179
The simplest kind of reader macro doesn't read anything::
173180

174181
(defreader hi
175-
`(print "Hello."))
182+
'(print "Hello."))
176183

177184
#hi #hi #hi
178185

@@ -233,7 +240,7 @@ There are three scoped varieties of regular macro. First are **core macros**, wh
233240

234241
(defmacro m []
235242
"This is a docstring."
236-
`(print "Hello, world."))
243+
'(print "Hello, world."))
237244
(print (in "m" _hy_macros)) ; => True
238245
(help (get-macro m))
239246
(m) ; => "Hello, world."

hy/core/macros.hy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
(help (get (local-macros) "m")))
122122
(f)
123123
124-
The equivalency is rough in the sense that ``local-macros`` returns a literal dictionary, not a preexisting object that Hy uses for resolving macro names. So, modifying the dictionary will have no effect.
124+
The equivalency is rough in the sense that ``local-macros`` expands to a literal dictionary, not a preexisting object that Hy uses for resolving macro names. So, modifying the dictionary will have no effect.
125125
126126
See also :hy:func:`get-macro <hy.core.macros.get-macro>`.]]
127127
(_local-macros _hy_compiler))

0 commit comments

Comments
 (0)