Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix check for extracting var from definition #484

Merged
merged 10 commits into from
Jun 16, 2023
Merged

Fix check for extracting var from definition #484

merged 10 commits into from
Jun 16, 2023

Conversation

zampino
Copy link
Collaborator

@zampino zampino commented May 15, 2023

Fixes #499. At present, a user defined macro which starts with def and expands to code like

(defmacro defmy [name body]
  `(do 
     (def ~name ~body) 
     return-some-val))

(defmy stuff bla)

when called produces a cell result wrapped in a {::clerk/var-from-def #'stuff} while the intended return value is actually discarded.

zampino added 5 commits May 15, 2023 15:06
forms arising from macroexpansions containing side effects e.g. (do (def foo) do-that) might unintentionally
end up wrapped with a ::clerk/var-from-def where the intended return value is discarded
(and (seq? form) (symbol? (first form)) (str/starts-with? (name (first form)) "def")))
(and (seq? form)
(symbol? (first form))
(contains? #{'def 'defonce 'defn} (first form))))
Copy link
Member

Choose a reason for hiding this comment

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

The intent here was to actually account for user-defined macros that are like defs, so more than just those three concrete instances.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we could check the returned value is a var of the same name as the one inferred by the analyzer, to decide when to do the wrapping.

@mk mk marked this pull request as ready for review June 16, 2023 08:50
@mk mk merged commit 6fcab98 into main Jun 16, 2023
@mk mk deleted the fix-deflike branch June 16, 2023 08:54
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.

Return value from deflike macros is ignored
2 participants