Fork me on GitHub
#clojure
<
2022-07-02
>
Ethan Miller12:07:12

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?

borkdude12:07:53

(when false
  (require '[optional-namespace]))

Ethan Miller12:07:30

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.

borkdude12:07:20

You could put the project.namespace-under-development in a separate optional library

borkdude12:07:57

Or just call the namespace project.namespace-experimental or so - shouldn't that be enough?

Ethan Miller12:07:29

Hmmm that’s true, maybe tagging the namespace is a good way to be very clear.

borkdude12:07:46

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

Ethan Miller12:07:52

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…

borkdude12:07:04

They way to do it on a dependency level is to introduce another dependency

Ethan Miller12:07:23

Yeah that makes sense.

Noah Bogart16:07:34

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

maxt17:07:07

I know I have wanted it on several occasions. Thank you for digging up some history around it.

borkdude17:07:39

@UEENNMX0T What do you mean, hard to nest macros? Can you give an example and how does quasi-quoting differ from syntax-quoting?

borkdude17:07:02

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

Noah Bogart18:07:39

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

Noah Bogart18:07:42

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

borkdude18:07:39

I think @U060FKQPN once said there was to generate less verbose code, but I'm not sure if he actually looked into it.

shaunlebron14:10:37

@UEENNMX0T is backtick not the quasiquote solution you were looking for?

shaunlebron14:10:42

or is it important that it happens as a reader macro instead of a normal macro time?

Noah Bogart15:10:26

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)

shaunlebron21:10:50

Not sure of your use case, but it looks like this might do what you want:

(backtick/template (+ ~a ~b ~@c))

Noah Bogart00:10:00

My issue was nested syntax quotes, which backtick doesn’t handle, sadly

Noah Bogart16:07:23

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

Noah Bogart16:07:38

for reference, here's a discussion on the clojure mailing list in 2009 about quasiquote: https://groups.google.com/g/clojure/c/bQxffjeQkFU

Kamuela19:07:24

Cannot invoke "Object.getClass()" because "x" is null must be one of those award-winning error messages I've been hearing so much about 😄

dpsutton20:07:34

That’s the improvement from jvms 14+

❤️ 1
emccue01:07:38

hmm, so hear me out here

emccue01:07:58

(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

emccue01:07:31

what if the compiler named variables mechanically based on an inferred access path?

emccue01:07:45

at least for keyword lookup sites

p-himik12:07:28

Wouldn't that imply that for each call site you'd need its own version of str/upper-case, with a custom parameter name?

p-himik12:07:10

I'd say this is a solved problem - we already have stack traces, they have all the information in them.