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

Simplify inline Clojure code #109

Merged
merged 2 commits into from
Oct 3, 2015
Merged

Simplify inline Clojure code #109

merged 2 commits into from
Oct 3, 2015

Conversation

daveyarwood
Copy link
Member

Closes #108

@daveyarwood daveyarwood mentioned this pull request Sep 28, 2015
@crisptrutski
Copy link
Member

After all my hard work simplifying things 😉

@daveyarwood
Copy link
Member Author

Sorry @crisptrutski! :)

@daveyarwood
Copy link
Member Author

Quoth @crisptrutski in #89:

The "try alda.lisp namespace first, then fallback to current namespace" has some issues, to furnish an example:

(test-parse :clj-expr "(let [tempo 1] (+ 1 tempo))")
=> (clojure.core/let [alda.lisp/tempo 1] (clojure.core/+ 1 alda.lisp/tempo))

So perhaps a better approach would be to set up a "clean room" namespace, with the appropriate alda.lisp functions referenced, and the conflicting clojure.core functions as exclusions.

We should probably fix this before merging this PR -- seems like it could lead to unexpected behavior :/

@daveyarwood
Copy link
Member Author

Hmm... this is a tricky problem. The Clojure reader must be able to differentiate somehow between symbols in bindings (and their subsequent references) and symbols elsewhere, so that it doesn't try to resolve them, but I haven't figured out how.

@daveyarwood
Copy link
Member Author

@crisptrutski Check this out -- I talked to @micha, and it turns out that all we really need to do to get this working is to refer alda.lisp into the boot.user context. This leverages the way that Boot creates a script at run-time and then evaluates it (you can see the script by running boot -b) in the boot.user namespace.

I've added (require '[alda.lisp :refer :all]) to both the alda script and the build.boot, so that this will work both when running the script and the boot alda task.

This will get trickier in 1.0.0 when we're packaging Alda as an uberjar, and thus won't have access to boot.user, but I think this will do for now.

@daveyarwood daveyarwood removed the WIP label Oct 2, 2015
@crisptrutski
Copy link
Member

Looks great, this is exactly what I was thinking also 👍

daveyarwood added a commit that referenced this pull request Oct 3, 2015
@daveyarwood daveyarwood merged commit 454df77 into master Oct 3, 2015
@daveyarwood daveyarwood deleted the simplify-inline-clojure branch October 3, 2015 11:46
@daveyarwood
Copy link
Member Author

Brandon Bloom (creator of backtick) had this to say:

Backtick is an implementation of syntax-quote, which operates at the reader level. While Clojure's syntax-quote does leverage knowledge of the dynamic environment (namespaces, vars, etc), it does not have any notion of lexical scope or any high-level understanding of Clojure forms. When your templating code, the normal advice for writing macros applies: Use gensyms:

`(let [tempo# 1] (+ 1 tempo#))

But really, you probably don't want syntax-quote or backtick at all for this use case. Instead, use the normal reader, wrap with `#(list 'fn [] %) and use a combination of in-ns/use/eval.

That last idea -- wrapping the expressions in an anonymous function and using in-ns and/or use in combination with eval -- is worth a try.

@crisptrutski
Copy link
Member

Reminds me a bit of JavaScript 😉

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.

None yet

2 participants