Skip to content

Commit

Permalink
Fix use of macroexpand-all in loopy-iter and loopy.
Browse files Browse the repository at this point in the history
We should always be passing an environment to the function, otherwise the
environment is reset to nil, which breaks macros like `cl-flet`.

- Stop doing top-level and sub-level expansion with different functions.
  - Instead, add `loopy-iter--level`.
  - Remove `loopy-iter--sub-level-expanders`, `loopy-iter--top-level-expanders`,
    `loopy-iter--macroexpand-sub`, `loopy-iter--macroexpand-top`,
    `loopy-iter--keyword-expander-sub`, and `loopy-iter--keyword-expander-top`.
- Pass the macro temporary environment in all places where we didn't before:
  - `loopy-iter`
  - `loopy`
  - `loopy-iter--parse-at-command`
  - `loopy-iter--opt-accum-expand-val`
- Add a `loopy--with-protected-stack` and `loopy--bind-main-body`.
- Add tests.
  • Loading branch information
okamsn committed Oct 6, 2023
1 parent 795f95e commit acf8a42
Show file tree
Hide file tree
Showing 9 changed files with 916 additions and 669 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ This document describes the user-facing changes to Loopy.

- Better signal an error with conflicting arguments in `numbers`. See [#172].

- Fix macro expansion in some cases by not resetting the macro environment.
For example, we failed to pass the current/modified environment to
`macroexpand-all` in some cases.

```emacs-lisp
;; Previously failed to use `cl-flet''s internally defined function
;; for `10+':
;; => (11 12 13 14 15)
(loopy (named outer)
(list i '((1 2) (3 4) (5)))
(loopy-iter (listing j i)
(cl-flet ((10+ (y) (+ 10 y)))
(at outer
(collecting (10+ j))))))
```

### Breaking Changes

- Make it an error to re-use iteration variables with multiple iteration
Expand Down
2 changes: 2 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ please let me know.
- The non-keyword arguments of =numbers= are deprecated. Use the keyword
arguments instead. A =:test= keyword argument was added, which is more
flexible and explicit than the non-keyword arguments.
- Fixed a problem with macro expansion in some cases for sub-macros
that created a new macro environment (e.g., ~cl-flet~).
- Versions 0.11.1 and 0.11.2: None. Bug fixes.
- Version 0.11.0:
- More incorrect destructured bindings now correctly signal an error.
Expand Down
Loading

0 comments on commit acf8a42

Please sign in to comment.