Skip to content

Fix issue #645: Implement binding macro#646

Closed
jonasseglare wants to merge 1 commit intosquint-cljs:mainfrom
jonasseglare:implement-binding-macro
Closed

Fix issue #645: Implement binding macro#646
jonasseglare wants to merge 1 commit intosquint-cljs:mainfrom
jonasseglare:implement-binding-macro

Conversation

@jonasseglare
Copy link
Copy Markdown
Contributor

This PR implements a macro called binding to dynamically bind variables.

Fixes issue #645 .

Please answer the following questions and leave the below in as part of your PR.

(is (= 4 (jsv! "(def ^:dynamic a 3) (binding [a 4] a)")))
(is (= 3 (jsv! "(def ^:dynamic a 3) (binding [a 4] a) a")))
(is (eq #js [#js [3 4] #js [100 10] #js [3 4]] (jsv! "(def ^:dynamic a 3) (def ^:dynamic b 4) [[a b] (binding [a 100 b 10] [a b]) [a b]]")))
(is (eq #js [500 119] (jsv! "(def ^:dynamic x 119) (def y (try (binding [x 120] (throw (js/Error \"Failed.\")) x) (catch js/Error _ 500))) [y x]")))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I included ^:dynamic here even if it is not needed to make the code look like Clojure. But maybe I should simply remove it.

@borkdude
Copy link
Copy Markdown
Member

borkdude commented Apr 4, 2025

A big caveat with binding and ES6 modules is that it only works within one and the same module, since you can't alter "vars" from other modules. This is why I haven't included it in squint (yet).

@jonasseglare
Copy link
Copy Markdown
Contributor Author

Thanks! I will close the PR now since this is not supported.

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.

2 participants