Skip to content

Conversation

@alysbrooks
Copy link
Contributor

Tests are based on the tests for when-first.

@alysbrooks alysbrooks marked this pull request as ready for review November 18, 2025 15:06
@alysbrooks
Copy link
Contributor Author

alysbrooks commented Nov 18, 2025

when-let only accepts a single pair of bindings so it occurs to me that we could check that additional pairs aren't accepted by checking doing so it throws an exception.

This is how when-let does it in Clojure itself:

(assert-args
    (vector? bindings) "a vector for its binding"
    (= 2 (count bindings)) "exactly 2 forms in binding vector")

@jeaye
Copy link
Member

jeaye commented Nov 18, 2025

when-let only accepts a single pair of bindings so it occurs to me that we could check that additional pairs aren't accepted by checking doing so it throws an exception.

Yeah, I think this makes sense. It is on the macro to validate its own inputs, so we can test that logic.

Tests are based on the tests for when-first.
@alysbrooks
Copy link
Contributor Author

It turned out clunkier than I expected, as the exception is thrown during compilation and can't be caught. I also couldn't test for a very specific exception, as I think that could vary by implementation.

@alysbrooks
Copy link
Contributor Author

Hmm, looks like that doesn't work for ClojureScript.

@jeaye
Copy link
Member

jeaye commented Nov 20, 2025

CLJS does weird stuff with macros. We could just disable that test for CLJS using a reader conditional.

@E-A-Griffin
Copy link
Collaborator

Yeah I'd second the suggestion to just not test cljs for that case, there's still value for the other dialects

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.

3 participants