Skip to content

Commit

Permalink
Improve destructuring and re-implement in pcase.
Browse files Browse the repository at this point in the history
- Re-implement destructuring of normal values using `pcase`, reducing the
  maintenance burden and making further improvements easier.
  - Make it so that the existing destructuring features will signal
    an error if the `pcase` pattern doesn't match, instead of failing silently
    as in `pcase`.
- Improve `&key`:
  - Make `&key` signal an error when there are unmatched keys in the property
    list.
  - Add `&allow-other-keys`.
  - Support the full form `((KEY VAR) DEFAULT SUPPLIED)`.
- Add `&optional` form `(VAR DEFAULT SUPPLIED)`.
- Add `&map` as `(KEY VAR DEFAULT SUPPLIED)`.
- Support full forms being vectors as well as lists.
- Update README and CHANGELOG.

- Move some destructuring features from `loopy-misc.el` to
  `loopy-destructure.el`.
- Move some instruction features from `loopy-misc.el` to
  `loopy-instr.el`
- Add many tests.
  • Loading branch information
okamsn committed Jan 27, 2024
1 parent 5af0db0 commit 6df1b39
Show file tree
Hide file tree
Showing 20 changed files with 2,803 additions and 939 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/emacs-matrix-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ jobs:
- name: Make folder for base package.
run: |
mkdir 'test-install'
cp loopy-commands.el loopy.el loopy-vars.el loopy-misc.el loopy-pkg.el test-install
cp loopy-iter.el loopy-pcase.el loopy-seq.el test-install
# Match all files of "loopy*.el" except for "loopy-dash.el".
echo Shell is $SHELL
shopt -s extglob
cp loopy!(-dash).el test-install
shopt -u extglob
- name: Install packages
run: emacs -batch -l tests/install-script.el
- name: Basic tests
Expand Down
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ This document describes the user-facing changes to Loopy.
(collecting (10+ j))))))
```

- The documentation describes Loopy's default destructuring style as a super-set
of that of `cl-lib`. `&key` now behaves more like it does in `cl-lib`,
signaling an error when appropriate ([#182]) and supporting the full form
`((KEY VAR) DEFAULT SUPPLIED)`.

### Breaking Changes

- Fix how the first accumulated value is used in `reduce`. See [#164] and the
Expand All @@ -89,6 +94,14 @@ This document describes the user-facing changes to Loopy.
TESTED-ITEM)`, similar to `seq-contains-p`. The argument order was previously
undocumented and not guaranteed. See [#170] and [#177].

- Like in `cl-lib`, destructuring with `&key` will now signal an error if there
are unmatched keys and `&allow-other-keys` was not given or
`:allow-other-keys` is not present in the property list with a non-nil value
([#182]).

- The default destructuring style now uses `pcase` underneath ([#182]). To
accomodate this, some of the defined errors and error detections have changed.

#### Removals

- The deprecated flag `split` was removed ([#165], [#131], [#124]). Instead,
Expand Down Expand Up @@ -203,12 +216,28 @@ This document describes the user-facing changes to Loopy.
uses the constant value directly, which Emacs can optimize to avoid some uses
of `funcall`.

### Destructuring Improvements

- A `loopy` `pcase` pattern has been added ([#182]). Destructuring is now based
on `pcase`.
- A `&map` construct was added for destructuring, analogous to `&key` but using
`map-elt` and the `map` `pcase` pattern ([#182]). Extending the `map`
pattern, `&map` also has a `SUPPLIED` parameter, as in `(KEY VAR DEFAULT
SUPPLIED)`.
- An `&optional` construct was added, like in `cl-lib` ([#182]).
- `&key` now works like it does in `cl-lib`, including the `DEFAULT`,
`SUPPLIED`, and `KEY` values in the full form and signaling an error
when appropriate ([#182]).

### Other Changes

- Add `loopy--other-vars`, given the more explicit restriction on
`loopy--iteration-vars` ([#144]). For example, these are the variables bound
by the `set` command, which are allowed to occur in more than one command.

- To reduce the maintenance burden, destructuring was re-implemented using
`pcase` ([#182]).

[#144]: https://github.com/okamsn/loopy/issue/142
[#144]: https://github.com/okamsn/loopy/pull/144
[#145]: https://github.com/okamsn/loopy/issue/145
Expand All @@ -227,6 +256,7 @@ This document describes the user-facing changes to Loopy.
[#176]: https://github.com/okamsn/loopy/issues/176
[#177]: https://github.com/okamsn/loopy/pull/177
[#180]: https://github.com/okamsn/loopy/pull/180
[#182]: https://github.com/okamsn/loopy/pull/182

## 0.11.2

Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ tests:

iter-tests:
emacs -Q -batch -l ert -l tests/load-path.el -l tests/iter-tests.el -f ert-run-tests-batch-and-exit


.PHONY: misc-tests

misc-tests:
emacs -Q -batch -l ert -l tests/load-path.el -l tests/misc-tests.el -f ert-run-tests-batch-and-exit
2 changes: 2 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ please let me know.
- Change the argument order of =test= to be (1) the sequence element then (2)
the tested value, like in ~seq-contains-p~ and _unlike_ in ~cl-member~, and
explicitly state this order in the documentation.
- =&key= now signals an error when there are unmatched keys in the plist, as
in =cl-lib=. =&allow-other-keys= has been added.
- See the [[https://github.com/okamsn/loopy/blob/master/CHANGELOG.md][change log]] for less recent changes.

# This auto-generated by toc-org.
Expand Down
Loading

0 comments on commit 6df1b39

Please sign in to comment.