This, I suppose? https://www.itprotoday.com/compute-engines/why-poet
The article has a lot of nice things to say about it 🙂
“Object-oriented database management systems (also known as OODBMSs) are better suited than relational databases (such as SQL Server) for many of today’s new information types.” — but not for long 🙂
Just to double check, how do I best in a string of json like a response from a http api call. Do I use data.json
or is there something in built like read-string
>
?
The two main libraries are going to be data.json or cheshire. data.json is a lightweight from scratch clojure json library, cheshire is built on jackson which weighs in substantially heavier
I am pretty anti-dependency these days, the last personal project I did I hacked together just enough of a json encoder to avoid having any dependency for it
At work we just had a big push to switch to data.json from cheshire everywhere, but we still could get rid of our Jackson dep (some other java libraries bring it in)
https://git.sr.ht/~hiredman/lions/tree/master/item/src/com/manigfeald/json.clj is the hacked together encoder, not correct for all data, but generates correct json for the data I feed it
@zackteo Yup, what @hiredman said. Now that data.json
has had a big performance overhaul courtesy of @slipset I would say try to use that for all situations unless you have something that is so performance-critical you need to look at Jsonista (built around the problematic Jackson libraries).
data.json
2.1.0 just came out with UUID support, so the main difference between data.json
and Cheshire is the latter has built-in date support, but with the former and its :value-fn
option, you can manage dates pretty easily (IMO).
Cheshire has a lot of optional functionality, based on what you have on your classpath, but it's very popular and tends to get dragged in via several other popular community libraries, so you can end up with quite a mess of transitive dependencies... which I'm increasingly frustrated with these days.
Alright! Thanks 🙂 Yeah I saw your posts about getting managing dependencies and doing the best to get with of jackson . Performance definitely isn't too much a concern so data.json would work
I’m trying to use the #inst
reader macro to create an instant time for a Datomic database. But I want this time to be programmatic: for instance, here I am trying to make a new inst from the current time:
#inst (current-time)
But i suspect this doesn’t work because the #inst
sees a list, not a string. Is there a way to make this work?#inst
is for writing constant date+time values in Clojure, not run-time variable values: https://clojure.org/reference/reader#_built_in_tagged_literals
If you want to create a Clojure data structure with a run-time variable data+time value inside of it, just call whatever function or method you want that returns the desired value, e.g. (current-time)
Note: I do not know if current-time
in your example is a function in your code base -- I am not aware of any such function built into Clojure, but there are several Java APIs for getting the current data and/or time, e.g. those in the java.time package: https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html
Yea… my current-time
function is just
(defn current-time []
(java.time.LocalDateTime/now))
But it seems that is very near to what #inst
does anyway. I think I can figure this out from here, thanks a lot!Recommendations for a lightweight library websocket client on JVM?
If you're on Java 11 or newer, you could just use http://java.net.http.WebSocket (https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/WebSocket.html).
Or if you want a wrapper, you could look into e.g. https://github.com/gnarroway/hato#websockets
Hi, I was watching Stu Halloway's talk Running With Scissors, and he mentioned the 'inverted REPL' he wrote for his personal financial software. It includes a snippet
(let [action (edn/read in)
result (perform-cat-action action conn ftx)],,,)
With the idea being he provides an action by writing edn to indicate action which is then processed.
I'm fiddling with something similiar, and I was wondering what the in
variable would be here. I was thinking stdin, but the way he described it, it's sounds like he's inputting via the REPL itself. Is that possible, and if so, how would in
be defined to read from the REPL?I wonder what is the difference between clojure.java.jdbc
and clojure.jdbc
?
I don’t recall seeing clojure.jdbc
before, but this post may be of interest: https://corfield.org/blog/2019/07/04/next-jdbc/
also checkout #sql for discussions of next.jdbc
clojure.jdbc is a defunct project IIRC, and it attempted to be a more clojure flavored alternative to clojure.java.jdbc
Perhaps it was *in*
meaning STDIN?
"The project is tested under JDK7 and JDK8."
clojure.jdbc was an unfortunately named library
namespace squatting
I have 2 maps,
;author-id and nick
{:author-id "1", :nickname "nic"}
;author-id and post-content
{:author-id "1", :post-content "h4x"}
I want to merge :nickname into the author-id and post-content map. is there a simple way to do that on matching :author-id ?if all the data is consistent, you could group-by author-id and then apply merge to the maps that are grouped by that key
that is, if all the data is either disjoint or where it coincides it agrees
It oughta be consistent, yeah, I think that is reasonable to expect.
I think it makes more sense to have an indexed map, now that I try reasoning about it in the REPL...
{"1" {:author-id "1" :nickname "S"} "2" {:author-id "2" :nickname "R"}}
so maybe smashing them together on matching index is possible in a simple way?
@sova It’s not very clear to me what you’re trying to do precisely; Do you have a sequence of many maps that all have :author-id in them? Because if you only have just 2 maps that look exactly like those, you can just (merge m1 m2) 🙂
(def posts (atom {"1" {:author-id "1" :post-content "SNnax"} "2" {:author-id "2" :post-content "Drolle"}}))
(def nicks (atom {"1" {:author-id "1" :nickname "Vace"} "2" {:author-id "2" :nickname "Luke"}}))
I'd like the result:
{"1" {:author-id "1" :post-content "SNnax" :nickname "Vace"} "2" {:author-id "2" :nickname "luke" :post-content "Drolle"}}
I thought this is what merge
was for but I'm not getting the expected result
i think you could (merge-with merge
here
😮
That works 😄
(clojure.set/join
[{:author-id "1" :post-content "SNnax"}
{:author-id "2" :post-content "Drolle"}]
[{:author-id "1" :nickname "Vace"}
{:author-id "2" :nickname "Luke"}])
=>
#{{:author-id "1", :post-content "SNnax", :nickname "Vace"} {:author-id "2", :post-content "Drolle", :nickname "Luke"}}
Nice.
Okay i'm not indexing by user-id though, I am indexing posts by post-id and users by user-id... so my apologies my needs are a little different. I think it's more like "find and replace" where I want to inject the nickname into the post-map
(def posts (atom {"eee9" {:author-id "1" :post-content "SNnax" :post-id "eee9"} "eeea" {:author-id "2" :post-content "Drolle" :post-id "eeea"}}))
(def nicks (atom {"1" {:author-id "1" :nickname "Vace"} "2" {:author-id "2" :nickname "Luke"}}))
(notice posts indexing changed, post-ids (their index) live inside each map as well)
Desired result: posts map with correct nickname injected
{"eee9" {:author-id "1" :post-content "SNnax" :nickname "Vace" :post-id "eee9"} "eeea" {:author-id "2" :post-content "Drolle" :nickname "Luke" :post-id "eeea"}}
Maybe I'll just start writing nicknames straight into the posts atom, and do find-and-replace if the nicknames ever change.
thanks for the help it's much appreciated
😃
@sova a little late but you could do
(reduce-kv
(fn [m k v]
(assoc m k (merge v (get nicks (:author-id v)))))
{} posts)
not exactly find-and-replace, but useful if you want to to merge posts into nicks
To mitigate Clojure’s slow startup, I want to have a running nREPL in the background and then periodically run babashka scripts. Is it possible for babashka to interact with the REPL? I know the nREPL exposes a port but how do I interact with it without the nrepl package on the babashka end?
@michaellan202 This is documented here: https://book.babashka.org/#_interacting_with_an_nrepl_server
This library isn’t documented under the “Libraries” section, so I got confused. Thanks borkdude
@michaellan202 which library do you mean?
Oh, nevermind. I was mistakenly Cmd-F’ing for “nrepl” when the library is called “bencode.” Silly me
Understandable. Maybe a babashka.nrepl-client
library would be nice in time, but this is the low level way how to do it
Hi. I have a question about reify
, I'm not sure where to post it, so I'll try here. I don't understand why my code is returning java.lang.Object
and not java.lang.Double
? I am trying to reify a functional interface from http://generated.ojalgo.org/org/ojalgo/function/PrimitiveFunction.Unary.html.
(reify
org.ojalgo.function.PrimitiveFunction$Unary
(invoke [this ^Double arg]
(double arg)))
Returns
; eval (current-form): (reify org.ojalgo.function.PrimitiveFunction$Un...
; (err) Syntax error (IllegalArgumentException) compiling reify*
; (err) Mismatched return type: invoke, expected: java.lang.Double, had: java.lang.Object
Any help would be greatly appreciated :)hi everyone, what is the recommendation for implementing money with currencies in Clojure, should it be done with Records to enforce some rigidity or just use maps with namespaced keys?
Just a thought but a lot of financial institutions represent currency values using long values by removing the decimal place and using the smallest currency unit i.e. cents instead of dollars or pence instead of pounds.
you need
(invoke ^double [this ^double arg]
arg))
see https://clojure.org/reference/java_interop#primitives for more info!how do you plan to represent the amounts?
Works perfectly, thanks!
with bigdecimal
nice 👌
I have
(^double invoke [this ^double arg]
arg))
if you’re gonna have a ton of these things, I suggest records for performance, otherwise start with maps 🙂
type hints can go before the name or the args list, before args list is preferred since before name doesn’t work for functions with multiple arities :thumbsup:
Java has some libs for this too like JodaMoney
@alexmiller yeah, but it would force us to use interop and bring many types
There’s this, it seems like it hasn’t been updated in a while, but I’ve used in the past (at a basic level); it worked fine https://github.com/clojurewerkz/money
It does wrap joda-money
AFAICT