This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-02
Channels
- # babashka (68)
- # beginners (22)
- # calva (8)
- # cider (10)
- # cljs-dev (31)
- # clojure (35)
- # clojure-europe (6)
- # clojure-norway (17)
- # clojurescript (5)
- # conjure (10)
- # data-science (8)
- # datascript (10)
- # emacs (3)
- # fulcro (20)
- # humbleui (3)
- # london-clojurians (1)
- # membrane (9)
- # nbb (34)
- # off-topic (16)
- # pathom (15)
- # releases (1)
- # shadow-cljs (15)
- # sql (15)
Is there a simple way to optionally load certain namespaces in a project? For example, let’s say there’s a namespace (some directory under src
, e.g. src/optional_namespace
) that I want to load optionally b/c it is under development and incomplete, how might I do that?
Hmmmm, I think maybe I should have said optionally compile. I.e. so that users of the library would have to provide some sort of configuration option perhaps in their project.clj or deps.edn in order to be able to load the specific namespace project.namespace-under-develpoment
.
You could put the project.namespace-under-development in a separate optional library
Or just call the namespace project.namespace-experimental
or so - shouldn't that be enough?
Hmmm that’s true, maybe tagging the namespace is a good way to be very clear.
Note that when you will change the name of this namespace later, it will be a breaking change for those who are using it, which might be a small price to pay, but you could also be very clear in your README.md, ns docstring or function docstrings that it is experimental
Yeah maybe it’s just a communication thing. I was just curious if there was some technical method available. At work, we use feature flags as a way to shield features until they are complete, but this is different…
Yeah that makes sense.
does clojure have quasiquote? syntax-quote produces (clojure.core/seq (clojure.core/concat (clojure.core/list (quote clojure.core/cond) ...
which makes it hard to nest macros
I know I have wanted it on several occasions. Thank you for digging up some history around it.
@UEENNMX0T What do you mean, hard to nest macros? Can you give an example and how does quasi-quoting differ from syntax-quoting?
I must say that syntax-quoting results in a giant blob of code which could make things slower than they have to be when evaluating that
Here’s an example of how Clojure’s built-in syntax-quote works: <ahttps://stackoverflow.com/questions/3704372/how-does-clojures-syntax-quote-work|https://stackoverflow.com/questions/3704372/how-does-clojures-syntax-quote-work>
Instead of working like quote
but with namespace resolving and unquoting (interpolation), syntax-quote is implemented directly in the reader which means that writing a macro that accepts a quasiquoted list is hard/impossible to process
@UEENNMX0T I have actually a related issue in grasp: https://github.com/borkdude/grasp/issues/28#issuecomment-1148716223
Ugh yeah that's rough. I like how syntax-quote works in the happy path but the way it expands is really cumbersome. Sadly, I think we're too late to change how it works now, right @U064X3EF3 ? Lol
I think @U060FKQPN once said there was to generate less verbose code, but I'm not sure if he actually looked into it.
Cc @U053S2W0V , just in case
@UEENNMX0T is backtick not the quasiquote solution you were looking for?
or is it important that it happens as a reader macro instead of a normal macro time?
I think my issue is that the clojure reader outputs the nested form at read time, instead of having an internal representation of “quasiquoted form”, as it does with quote. The reader can be changed to output a “normal list” form except for unquote-splicing, which would require a new function or special character/form.
For example (I’m on my phone, so apologies for mistakes), if unquote-splicing wasn’t expanded until compile time, then the reader could read (+
a b ~@c)` and output (clojure.core/quasiquote (clojure.core/+ user/a user/b (clojure.core/unquote-splice user/c)))
, and then at evaluation time, it is turned into (clojure.core/+ 1 2 3 4 5)
Not sure of your use case, but it looks like this might do what you want:
(backtick/template (+ ~a ~b ~@c))
My issue was nested syntax quotes, which backtick doesn’t handle, sadly
from a cursory google search, it seems there was a lot of discussion around adding quasi-quote back in 2008 and in 2009 @hiredman fully implemented quasiquote in clojure https://github.com/hiredman/clojure/blob/readerII/src/clj/clojure/reader.clj#L367, but it doesn't look like that was picked up by the core team nor has any library come out since to fill the gap
for reference, here's a discussion on the clojure mailing list in 2009 about quasiquote: https://groups.google.com/g/clojure/c/bQxffjeQkFU
Cannot invoke "Object.getClass()" because "x" is null
must be one of those award-winning error messages I've been hearing so much about 😄
(let [person {}]
(string/upper-case (:name person)))
Execution error (NullPointerException) at user/eval1929 (form-init10226617705429974004.clj:2).
Cannot invoke "Object.toString()" because "s" is null