Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In the manual, use separate auto lines for members #84

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
# testing PyPy.

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
# Install dependencies. Test on Hy `master`, not the latest Hy
Expand Down
116 changes: 85 additions & 31 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,73 +14,127 @@ Reference

``anaphoric`` — Anaphoric macros
----------------------------------------------------------------------

.. hy:automodule:: hyrule.anaphoric
:macros: ap-if, ap-each, ap-each-while, ap-map, ap-map-when,
ap-filter, ap-reject, ap-dotimes, ap-first, ap-last, ap-reduce,
ap-when, ap-with
:readers: %

.. hy:autotag:: %
.. hy:automacro:: ap-if
.. hy:automacro:: ap-each
.. hy:automacro:: ap-each-while
.. hy:automacro:: ap-map
.. hy:automacro:: ap-map-when
.. hy:automacro:: ap-filter
.. hy:automacro:: ap-reject
.. hy:automacro:: ap-dotimes
.. hy:automacro:: ap-first
.. hy:automacro:: ap-last
.. hy:automacro:: ap-reduce
.. hy:automacro:: ap-when
.. hy:automacro:: ap-with

``argmove`` — Macros for calls with unusual argument placement
----------------------------------------------------------------------

.. hy:automodule:: hyrule.argmove
:macros: ->, ->>, as->, doto

.. hy:automacro:: ->
.. hy:automacro:: ->>
.. hy:automacro:: as->
.. hy:automacro:: doto

``collections`` — Tools for data structures
----------------------------------------------------------------------

.. hy:automodule:: hyrule.collections
:macros: assoc
:readers: s

.. hy:automacro:: assoc
.. hy:automacro:: ncut
.. hy:autofunction:: postwalk
.. hy:autofunction:: prewalk
.. hy:autotag:: s
.. hy:autofunction:: walk

``control`` — Control structures
----------------------------------------------------------------------

.. hy:automodule:: hyrule.control
:macros: block, branch, ebranch, case, ecase, cfor, defmain, do-n,
ifp, lif, list-n, loop, unless

.. hy:automacro:: block
.. hy:automacro:: branch
.. hy:automacro:: case
.. hy:automacro:: cfor
.. hy:automacro:: defmain
.. hy:automacro:: do-n
.. hy:automacro:: ebranch
.. hy:automacro:: ecase
.. hy:automacro:: ifp
.. hy:automacro:: lif
.. hy:automacro:: list-n
.. hy:automacro:: loop
.. hy:automacro:: unless

``destructure`` — Macros for destructuring collections
----------------------------------------------------------------------

.. hy:automodule:: hyrule.destructure
:macros: defn+, defn/a+, dict=:, fn+, fn/a+, let+, setv+

.. hy:automacro:: defn+
.. hy:automacro:: defn/a+
.. hy:automacro:: dict=:
.. hy:automacro:: fn+
.. hy:automacro:: fn/a+
.. hy:automacro:: let+
.. hy:automacro:: setv+

``iterables`` — Tools for iterable objects
----------------------------------------------------------------------

.. hy:automodule:: hyrule.iterables
:members: butlast, coll?, distinct, drop-last, flatten, rest

.. hy:autofunction:: butlast
.. hy:autofunction:: coll?
.. hy:autofunction:: distinct
.. hy:autofunction:: drop-last
.. hy:autofunction:: flatten
.. hy:autofunction:: rest

``macrotools`` — Tools for writing and handling macros
----------------------------------------------------------------------

.. hy:automodule:: hyrule.macrotools
:members: macroexpand-all
:macros: defmacro/g!, defmacro!, with-gensyms
:readers: /

.. hy:autotag:: /
.. hy:automacro:: defmacro/g!
.. hy:automacro:: defmacro!
.. hy:autofunction:: macroexpand-all
.. hy:automacro:: with-gensyms

``pprint`` — Pretty-printing data structures
----------------------------------------------------------------------

.. hy:automodule:: hyrule.hypprint
:members: PrettyPrinter, pformat, pp, pprint, saferepr,
readable?, recursive?

.. hy:autoclass:: PrettyPrinter
.. hy:autofunction:: pformat
.. hy:autofunction:: pp
.. hy:autofunction:: pprint
.. hy:autofunction:: readable?
.. hy:autofunction:: recursive?
.. hy:autofunction:: saferepr

``sequences`` — Lazy, indexable iterables
----------------------------------------------------------------------

.. hy:automodule:: hyrule.sequences
:members: end-sequence
:macros: defseq, seq

.. hy:automacro:: defseq
.. hy:autofunction:: end-sequence
.. hy:automacro:: seq

``misc`` — Everything else
----------------------------------------------------------------------

.. hy:automodule:: hyrule.misc
:members: constantly, dec, inc, parse-args, xor
:macros: comment, of, profile/calls, profile/cpu, smacrolet
.. hy:automodule:: misc

.. hy:automacro:: comment
.. hy:autofunction:: constantly
.. hy:autofunction:: dec
.. hy:autofunction:: inc
.. hy:autofunction:: parse-args
.. hy:automacro:: profile/calls
.. hy:automacro:: profile/cpu
.. hy:automacro:: smacrolet
.. hy:autofunction:: xor

Contributing to Hyrule
======================
Expand Down
4 changes: 2 additions & 2 deletions hyrule/anaphoric.hy
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ concise and easy to read.
acc))

(defmacro ap-when [test-form #* body]
"As :ref:`when <when>`, but the result of the test form is named ``it`` in
the subsequent forms.
"As :hy:func:`when <hy.core.macros.when>`, but the result of the test
form is named ``it`` in the subsequent forms.

Examples:
::
Expand Down
6 changes: 3 additions & 3 deletions hyrule/control.hy
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
instead.)

The macro is implemented as a :hy:func:`for` loop over a
:func:`range` call, with the attendent consequences for negative
:py:class:`range` call, with the attendent consequences for negative
counts, :hy:func:`break`, etc. As an exception, if the count is
`Inf`, the loop is run over an infinite iterator instead. ::

Expand All @@ -211,7 +211,7 @@

If you want fancy command-line arguments, you can use the standard Python
module :mod:`argparse` in the usual way, because ``defmain`` doesn't change
``sys.argv``. See also :hy:func:`parse-args <hyrule.misc.parse-args>`.
``sys.argv``. See also :hy:func:`parse-args`.
::

(import argparse)
Expand All @@ -238,7 +238,7 @@
<hy.core.macros.cond>`. Its most notable property is that it tests
the condition with ``(is-not condition None)`` instead of ``(bool
condition)``, so values such as the integer 0, the empty string, and
:py:keyword:`False` are considered true, not false. The general
``False`` are considered true, not false. The general
syntax is
::

Expand Down
28 changes: 7 additions & 21 deletions hyrule/destructure.hy
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ their arguments.
Introduction
============

Destructuring allows one to easily peek inside a data structure and assign names to values within. For example,

.. code-block:: hy
Destructuring allows one to easily peek inside a data structure and assign names to values within. For example, ::

(setv+ {[{name :name [weapon1 weapon2] :weapons} :as all-players] :players
map-name :map
:keys [tasks-remaining tasks-completed]}
data)

would be equivalent to

.. code-block:: hy
would be equivalent to ::

(setv map-name (.get data ':map)
tasks-remaining (.get data ':tasks-remaining)
Expand All @@ -28,9 +24,7 @@ would be equivalent to
weapon1 (get (.get (get all-players 0) ':weapons) 0)
weapon2 (get (.get (get all-players 0) ':weapons) 1))

where ``data`` might be defined by

.. code-block:: hy
where ``data`` might be defined by ::

(setv data {:players [{:name Joe :weapons [:sword :dagger]}
{:name Max :weapons [:axe :crossbow]}]
Expand All @@ -40,9 +34,7 @@ where ``data`` might be defined by
This is similar to unpacking iterables in Python, such as ``a, *b, c = range(10)``, however it also works on dictionaries, and has several special options.

.. warning::
Variables which are not found in the expression are silently set to ``None`` if no default value is specified. This is particularly important with ``defn+`` and ``fn+``.

.. code-block:: hy
Variables which are not found in the expression are silently set to ``None`` if no default value is specified. This is particularly important with ``defn+`` and ``fn+``. ::

(defn+ some-function [arg1
{subarg2-1 \"key\"
Expand Down Expand Up @@ -74,9 +66,7 @@ Patterns
Dictionary Pattern
------------------

Dictionary patterns are specified using dictionaries, where the keys corresponds to the symbols which are to be bound, and the values correspond to which key needs to be looked up in the expression for the given symbol.

.. code-block:: hy
Dictionary patterns are specified using dictionaries, where the keys corresponds to the symbols which are to be bound, and the values correspond to which key needs to be looked up in the expression for the given symbol. ::

(setv+ {a :a b \"b\" c #(1 0)} {:a 1 \"b\" 2 #(1 0) 3})
[a b c] ; => [1 2 3]
Expand All @@ -88,9 +78,7 @@ The keys can also be one of the following 4 special options: ``:or``, ``:as``, `
- ``:keys`` takes a list of variable names which are looked up as keywords in the expression.
- ``:strs`` is the same as ``:keys`` but uses strings instead.

The ordering of the special options and the variable names doesn't matter, however each special option can be used at most once.

.. code-block:: hy
The ordering of the special options and the variable names doesn't matter, however each special option can be used at most once. ::

(setv+ {:keys [a b] :strs [c d] :or {b 2 d 4} :as full} {:a 1 :b 2 \"c\" 3})
[a b c d full] ; => [1 2 3 4 {:a 1 :b 2 \"c\" 3}]
Expand All @@ -107,9 +95,7 @@ There are 2 special options: ``:&`` and ``:as``.
- ``:&`` takes a pattern which is bound to the rest of the expression. This pattern can be anything, including a dictionary, which allows for keyword arguments.
- ``:as`` takes a variable name which is bound to the entire expression.

If the special options are present, they must be last, with ``:&`` preceding ``:as`` if both are present.

.. code-block:: hy
If the special options are present, they must be last, with ``:&`` preceding ``:as`` if both are present. ::

(setv+ [a b :& rest :as full] (range 5))
[a b rest full] ; => [0 1 [2 3 4] [0 1 2 3 4]]
Expand Down
14 changes: 2 additions & 12 deletions hyrule/macrotools.hy
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
any symbol that starts with
``g!``.

For example, ``g!a`` would become ``(hy.gensym \"a\")``.

.. seealso::

Section :ref:`using-gensym`
"
For example, ``g!a`` would become ``(hy.gensym \"a\")``."
(setv syms (list
(distinct
(filter (fn [x]
Expand Down Expand Up @@ -149,12 +144,7 @@
... (setv a (hy.gensym)
... b (hy.gensym)
... c (hy.gensym))
... ...)

.. seealso::

Section :ref:`using-gensym`
"
... ...)"
(setv syms [])
(for [arg args]
(.extend syms [arg `(hy.gensym '~arg)]))
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ def run(self):
"Development Status :: 4 - Beta",
"License :: DFSG approved",
"License :: OSI Approved :: MIT License", # Really "Expat". Ugh.
"Operating System :: OS Independent"],
"Operating System :: OS Independent",
"Programming Language :: Hy"],
cmdclass={'install': install})