This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # asami (6)
- # babashka (74)
- # babashka-sci-dev (164)
- # beginners (50)
- # biff (3)
- # calva (71)
- # clj-kondo (4)
- # cljdoc (39)
- # cljsrn (4)
- # clojars (8)
- # clojure (70)
- # clojure-austin (7)
- # clojure-czech (5)
- # clojure-europe (4)
- # clojure-losangeles (1)
- # clojure-nl (10)
- # clojure-norway (1)
- # clojure-uk (3)
- # clojurescript (38)
- # community-development (18)
- # cursive (129)
- # datomic (9)
- # fulcro (7)
- # graalvm (4)
- # improve-getting-started (1)
- # jobs (1)
- # kaocha (2)
- # liberator (9)
- # lsp (22)
- # malli (3)
- # membrane (95)
- # off-topic (86)
- # releases (2)
- # sci (5)
- # specter (2)
I have a folder of babashka scripts in my project folder:
≤project>/bb Is there a way to access them from my project? I guess only stuff in the classpath (`<project>/src/...`) is visible to the project?
Access them without knowing the full path that is.
If you're trying to load them as code, you can add them to your paths. The paths are under https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L311 for lein and
:paths for deps.edn.
If you're just trying to read their contents, then the current working directory is typically the project dir, so you can load them using something like
Note that the latter will work only if you run your project from sources - it won't work if it's packed in a jar.
That was going to be my next question! 🔮 I've never made an überjar before.
@U0232JK38BZ Maybe you can give a bit more context: are you reading bb scripts from the JVM and why?
I have a program that runs scripts. I want to include some predefined scripts in my program. Of course, the predefined scripts could just be implemented with regular compiled Clojure code since they are predefined.
I’ve a macro named
macro-a defined in
(ns a) , now I want to expose that name in another namespace
ns b . What’s the recommended approach?
Or by expose, do you mean that you want for it to be available via
b and not just used in
Potemkin does this: https://github.com/clj-commons/potemkin/blob/master/src/potemkin/namespaces.clj#L35-L56
It's available in its API as
import-vars although in general people don't seem to be in favor of that technique.
Personally, I would probably just use the macro via
Not hidden, but internal, yeah.
Why do you not want to use the macro simply via
a, without exposing it via
Alright, in this case - why is the macro defined in some other ns? :)
If something belongs together - just put it together. And if the implementation takes a lot of space - just move the implementation to separate namespaces.
Clojure does it as well, although via a much older technique - by using
load in combination with
in-ns. But I believe it's been said that if the core team were implementing that functionality nowadays, they would've used a different approach.
So you can have stuff like
(ns b (:require [a])) (defmacro m  (a/m-impl))
a/m-implis a function that implements the macro. Or another macro, but the usage would be slightly different.
this kind of indirection is extremely annoying when trying to read code or debug
impl in a separate ns, potemkin being one way to do it
perhaps your IDE makes it trivial, but I'd like to not need an IDE
(I've gotten away with it for a while...)
But that's a problem with every single
require then, no?
E.g. you need to debug a specific usage of
clojure.core/into from your namespace. That's already indirection.
no, require is simple - I go find the required file, it's the extra indirection (that rarely limits itself to one layer once it starts) that gets tedious
and don't get me started on trying to figure out which file you put a multimethod extension in...
it's not a demand, but a polite request to minimize this style of spreading out codebases - there's a reason clojure's so much easier to read than java or ruby, and I'd like our conventional style to keep it that way
I get it, although I don't get the desire to shun away an IDE. I'd definitely find it incomparably more annoying to not have IDE features than to have to navigate an extra file with a text editor.
I wasted too many days that should have been productive on stupid cider bugs
also, I was working as a mentor on my team to programmers that were new to clojure, and found it extremely useful to be able to give advice and debugging hints that didn't require they use my setup
so I learned how to do everything with the
clojure.repl namespace, and the various introspection features that come with the language
I admit it takes a little longer, but if the time it takes to get code onto the screen is your bottleneck I have severe doubts about your code quality
Alright, so it's not IDE in general by Cider - I don't have an opinion there since I've never used it. But just the simplest "navigate to definition" already makes so many things incomparably easier and streamlined that I'd definitely never consider going full on IDE-less. And if there's ever a (albeit strange) choice between "make something easier for any IDE users" and "make something easier for plain editor users", I'd definitely go for the former. As long as it's not tied to some specific IDE, of course.
clojure.repl/source shows the source and
meta shows the location, and any useful editor can open the jar file pointed to in
and it is IDE in general - I saw no evidence that cursive users were wasting less time to broken config or scrambled setups
it's a difference in speed, not capability
I'm using the same info the IDE uses, clojure makes it easy to access
Right, and all I have to do is Ctrl+B. :) That's the only reason I'm not migrating from Cursive to Calva - the latter can't seamlessly navigate from Clojure code into Java code. I read a lot of code - both my own and thirdparty, - so I have to navigate it a lot. Having to constantly type in commands for that would definitely put me off from exploration.
I must be different, I read code slowly enough that my time is not dominated by typing in file / jar names or finding javadoc
I spend most of that time reading
or perhaps I'm stunting myself and I could be doing a lot more with an IDE?
> That’s the only reason I’m not migrating from Cursive to Calva - the latter can’t seamlessly navigate from Clojure code into Java code. Totally concur. How do you solve the js issue? Does cursive support jump into js (node module) sources?
I see. Yeah, I read code significantly faster than natural languages, including my native one. At least, when it comes to reasonably good code in reasonable languages.
> How do you solve the js issue? Does cursive support jump into js (node module) sources? I keep a stiff upper lip and do it manually. It's a pain.
this is getting philosophical now, but I trust reading quickly in natural language (outside domains like law...) because what the statement means is determined by a human consensus and human norms I do not trust reading code quickly because while writer intent will be shaped by human norms, what the code does is determined by something much less forgiving
Somewhat related note - I absolutely despise, perhaps beyond any reason, long local names. E.g. when instead of
(let [c (make-collection-of-all-my-things)] (do-stuff c))
That makes code reading so much harder. It's like climbing stairs while putting both of your feet on one stair at a time.
const collectionOfAllMyThings = makeCollectionOfAllMyThings(); doStuff(collectionOfAllMyThings);
100% agreed - I am trying to remember where I heard this idea - maybe Rob Pike? - the larger the scope of a variable, the more important it is that it be fully descriptive. so if it's local to a two line funciton, a name like
x or the classic
i might suffice. if it escapes the current file, you need a proper sentence of a name
We might easily have different mental processes going on.
It's the exact opposite for me.
I read text in natural language slowly exactly because I have to consider all the norms that I know.
And with code, I know what
map does, I know what
into does, I know what
(into coll (map ...) ...) does - immediately, without having to think that "map" also means a model of a territory and stuff like that.
> the larger the scope of a variable, the more important it is that it be fully descriptive Something like that yeah - I remember it from reading some paper on cognitive load but I wouldn't be able to recall which one exactly it was.
but I'm not reading for developer intent alone, I'm also reading for what the code does, and most importantly I'm looking for where that diverges from developer intent. so I need to keep track of the common misconceptions that people have about what
map does (in fact I have, effectively a relative "red flag" score for every function in clojure.core, and map is higher than average...)
where 1.0 red flag is for things like flatten and pmap
That makes sense. Still, it's a very robust and rigid set of things relative to what happens in a natural language.
And I concede - I might be overthinking reading in a natural language. :) But that's not something I'd want to change. I make enough mistakes with reading plain text as it is - speeding it up would only make things worse.
What you can do is this:
(ns a) (defn macro-a-impl [a b] ...) (ns b) (defmacro macro-a [a b] (b/macro-a-impl a b))
Does anyone have a snippet that will "find all files on the classpath matching some pattern or named in a certain way" Trying to find all the config.edn and schema.edn files on the classpath to merge them
And if you need just
config.edn, then it has
But if you need to take directories into account, then it has
resource-dir which you could use as a building block.
It's probably worth using given that the distinction between files and jars is annoying. Unless there's a Java-only easy solution to this which I couldn't find.
Am I alone in finding regex difficult to read? Instead of something like
#"\"(?:\\.|[^\\\"])*\"?" I would prefer something much more verbose:
Is there a library that does something like that?
[:concat \" [:star [:union [:concat \\ :any] [:negated-character-class \\ \"]]] [:optional \"]]
many! https://github.com/cgrand/regex https://github.com/lambdaisland/regal https://github.com/AbhinavOmprakash/luna
Thank you both for the quick response! 🙂
java regex (and therefore clojure regex) supports free-spacing mode, a multi line format with embedded comments:
(def re1 #"\"(?:\\.|[^\\\"])*\"?" ) (def re2 #"(?x)\" # just a quote (?:\\. | # \\ followed by any single token OR [^\\\"]) # something that isn't in \\ or \" *\"? # optionally a final \" ")
(ins)user=> (re-find re1 "\"-\"") "\"-\"" (cmd)user=> (re-find re2 "\"-\"") "\"-\""
my comments there are incorrect, but the layout makes it easier to see what the regex is
Thanks @U051SS2EU didn’t know about free-spacing.
After looking at regal a bit, now I wish there was a lexer generator that uses regal syntax for patterns.