This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-14
Channels
- # announcements (3)
- # babashka-sci-dev (22)
- # beginners (6)
- # calva (36)
- # cljsrn (1)
- # clojure (59)
- # clojure-europe (31)
- # clojure-france (3)
- # clojure-gamedev (1)
- # clojure-nl (1)
- # clojure-norway (1)
- # clojure-uk (4)
- # clojurescript (6)
- # conjure (1)
- # cursive (11)
- # data-oriented-programming (1)
- # datahike (2)
- # docker (8)
- # duct (4)
- # emacs (1)
- # figwheel-main (5)
- # kaocha (1)
- # leiningen (8)
- # lsp (64)
- # malli (10)
- # membrane (5)
- # nrepl (11)
- # off-topic (5)
- # portal (6)
- # quil (9)
- # reagent (62)
- # reitit (15)
- # releases (3)
- # ring-swagger (2)
- # shadow-cljs (36)
- # specter (2)
- # tools-deps (21)
I don't know if this is the correct channel to ask, but does anyone else have the feeling that because Clojure is so simple, they no longer get the satisfaction of building complicated software?
Lisp curse?
2 weeks ago I was traveling for work. Today, I am looking back at some of the messages I missed. This one warrants feedback! 🙂
I find that Clojure gets out of my way. It lets me focus on the problem at hand. In the past, relatively simple problems required complex software to address it. Complex problems were almost impossible for an individual. They needed a team. I've worked on such problems with large code bases in C, C++, Delphi, VB (IKR?), and Java. With Clojure, relatively simple problems are typically solved with relatively simple solutions! Complex problems take work, but now it's tractable for an individual to work on them. For instance, I have a single project of nearly 9k lines, of which I wrote almost every line. I could never have attempted such a thing in, e.g. Java
More like I’m bewildered at everyone else’s fascination with it (even though I was on the same train myself 10 years ago).
I’m plenty satisfied with solving real complicated problems instead of self-induced ones.
Well. “Real” meaning: Not due to programming-language-level choices. I suppose “postgres scaling” or “pipeline processing” is somewhat self-induced, just at a different level :)
I wish I was at that point< i'm still at the stage with some stuff where I don't know how to do the thing I want to do, and I'm not even sure what the question is I need to ask.
Apologies if this has been asked before but given that there's an int?
/`integer?`, a float?
and a double?
, how come there isn't a long?
core function?
int?
and integer?
don’t check for the particular type of integer. Their docstrings are “Returns true if n is an integer” and “Returns true if x is a fixed precision integer”. They are not looking for the integer/Integer java classes
Sorry, I should have been more specific:
float?
is analogous to int?
in the sense that you describe, it checks if the input is a floating point number (either an instance of Double or a Float)
Still, there's a double?
that checks specifically if n is an instance of Double. So I suppose my question should have been, how come there's a double?
but not a long?
?
My thinking is that there hasn’t really been a need. From the double?
function you can see its just an instance check but in my 6+ years of Clojure i’ve never needed such a predicate. And outside of interop I’m wondering what need it might serve
I definitely have some colleagues who find it very satisfying to wrestle with our complex beast of a (non-Clojure) codebase and production environment, and win. I've come to view that as a deep, personality-type difference in software development. for me it's all friction making it hard to achieve whatever we're actually trying to do, but not everyone feels that way.
Heya folks! Suppose I have a spec definition for a map whose values are only booleans and sets (i.e. the number of combinations that satisfy the spec is small). Is there a way to exhaustively generate all possible valid maps? I've looked through test.check
but unless I'm missing something I couldn't find anything that generates all possible values. Thanks! 🙂
If it's actually that small you can probably just use a for
expression over the booleans and sets (though you might need to nest it to generate the set values)
@U2FRKM4TW what I mean is that I have a specced map like:
(s/def ::foo boolean?)
(s/def ::bar boolean?)
(s/def ::baz #{:dog :cat :mouse})
(s/def ::foobar-map (s/keys :req-un [::foo ::bar ::baz]))
and I want to enumerate every possible map satisfying this spec, rather than simply sampling from the space of valid maps.Yeah, for
is probably your best bet here. Should be enough here and you can throw in clojure.math.combinatorics
if you need more complex values, like all possible subsets of a set.
Thanks! I'll try that, although it would be great if it would be based on the spec for consistency reasons 🙂
I guess I was hoping that there was some generate-all-possible
function lurking somewhere
Not really @U01BP1CB37B considering the way spec sees sets is as predicates, and so every possible value in the clojure runtime would need to be tested against it unless special cases were added for sets. Which I can see why it'd look like there is a special case, but there is not.
There actually is a special case for sets. :)
(defn gen-for-pred
"Given a predicate, returns a built-in generator if one exists."
[pred]
(if (set? pred)
(elements pred)
(get @gen-builtins pred)))
Ah, yeah, in the generator it makes sense there's a special case.
I was thinking more about spec itself, not spec's generators
thanks for pointing that out
You could use
to read the file into a byte array, then use buddy-core
’s bytes->hex
:
https://funcool.github.io/buddy-core/latest/buddy.core.codecs.html#var-bytes-.3Ehex
(Don’t do that for large files though)
Here is a file->bytes
function that we have lying around somewhere:
(defn file->bytes [file]
(with-open [xin (io/input-stream file)
xout (ByteArrayOutputStream.)]
(io/copy xin xout)
(.toByteArray xout)))
OK cool. If you don’t mind the dep to buddy, it has what you need
Behind the curtain it just delegates to apache commons, or you could HexFormat
as @U050ECB92 suggested if you don’t need to support older Java versions
@U04V15CAJ’s approach is the best here IMHO, except for a larger file you probably want to partition the bytes and calculate N at a time (instead of making one BigInteger out of the entire file at once)
Actually it is not a very good solution because it will skip leading zeros. (.toString (BigInteger. "1") 16)
will return "1"
instead of "01"
.
And before writing code to encode in chunks using BigInteger
, I would go with apache commons codec and write:
(defn file->hex [file]
(with-open [in (io/input-stream file)
b (ByteArrayOutputStream.)
out (Base16OutputStream. b true true)]
(io/copy in out)
(String. (.toByteArray b))))
@U031CHTGX1T thanks, that's a good point, though I still think there's a lot of value to avoiding dependencies if there's a way to avoid commons
I don’t agree at all. If your program needs to encode files to Hex / Base16, depending on commons.codec is totally reasonable. Beware of “Not invented here”
(cmd)user=> (transduce (map #(format "%02X" %))
(fn ([] (StringBuilder.))
([done] (str done))
([sb s] (.append sb s)))
(byte-array (range 20)))
"000102030405060708090A0B0C0D0E0F10111213"
for smaller inputs that fn should just be str
should have included above, it correctly translates -1 to FF
That works. But please note that you still need to read the file, it’s hard to argue that it is simpler, and it is about 40x slower than just using streams 🤷
Hey guys, currently trying to compile a project using clojure -T:build
. I think my build.clj
is alright, but I attached it since I might be doing something wrong.
I get this error:
$ clojure -T:build uber
$ java -jar target/bee-solver-0.1.1-standalone.jar
Error: Could not find or load main class wildwestrom.bee_solver.core._main
Caused by: java.lang.ClassNotFoundException: wildwestrom.bee_solver.core._main
you look like you have taken the symbol naming your main function
wildwestrom.bee-solver.core/-main
and then turned into the symbol