Skip to content

Conversation

@kchanqvq
Copy link
Member

@kchanqvq kchanqvq commented Nov 21, 2025

This fixes #517 and is essential towards complete CL. It does introduce some code churn so I'd like some eyes on it!

This introduces parse-macro (from CLtL2) and use it to bootstrap defmacro, instead of using destructuring-bind directly. Currently !parse-macro just has additional &whole handling. In the future we might add &environment as well, which should then make macro lambda list support complete.

@kchanqvq
Copy link
Member Author

kchanqvq commented Nov 22, 2025

There's one more thing that I might want to change. The problems:

  1. macroexpand and friends should operate in the null (global) lexical environment when called without env argument, while currently they take current value of *environment*
  2. lookup-in-lexenv is not the most efficient and we aren't using the full functionality of push-to-lexenv -- there's at most one definitions in one lexenv frame.

1 can be solved by saving another *global-environment* variable. However I think the cleanest way is to define environment as a list of lexenvs instead (maybe rename to lexenv-frame), and variables functions... can be hash tables. Previously we store a single lexenv struct whose variables functions ... list structures implicitly contain data from parent frames (and we're limited to represent them as list), and the frame structure weren't explicit.

@kchanqvq kchanqvq force-pushed the macro-function branch 2 times, most recently from 55387ae to 7eccde5 Compare November 23, 2025 08:45
@kchanqvq
Copy link
Member Author

After working on it I think the current environment representation is fine. I won't change it.

Update:

  • save global environment in *environment* and use them in macroexpand(-1)
  • support &environment parameter

The code we ported (CLOS, loop) seems to have some hacks making up for not supporting &environment before. I'll undo them.

@davazp
Copy link
Member

davazp commented Nov 23, 2025

I never looked well how the environments work in CL. 🙂 So hard for me to catch any issue on the PR if there is any.

But let's merge it and see if we find something.

@kchanqvq kchanqvq merged commit 63f8530 into jscl-project:master Nov 24, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macro function interface and &whole

2 participants