This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-23
Channels
- # announcements (6)
- # aws (4)
- # babashka (66)
- # beginners (70)
- # calva (2)
- # cider (62)
- # clara (1)
- # clojars (5)
- # clojure (101)
- # clojure-dev (67)
- # clojure-europe (1)
- # clojure-nl (3)
- # clojure-uk (13)
- # core-async (15)
- # datomic (11)
- # defnpodcast (10)
- # duct (22)
- # emacs (6)
- # events (1)
- # fulcro (34)
- # kaocha (3)
- # off-topic (20)
- # pathom (1)
- # re-frame (8)
- # reagent (14)
- # remote-jobs (1)
- # shadow-cljs (58)
Hi, I'm messing with SPARQL/RDF using aristotle. I'd like to write RDF queries that hit dbpedia/wikidata. aristotle wants an implementation of Jena's Graph interface, but all the SPARQL stuff seems to skip the Graph and just take a SPARQL query. I managed to get Jena working directly:
(let [q (QueryFactory/create "SELECT ?prop ?place WHERE { ?prop ?place .}")
qx (QueryExecutionFactory/sparqlService "" q)]
(.addParam ^QueryEngineHTTP qx "timeout" "10000")
(ResultSetFormatter/out System/out (.execSelect qx) q))
but nothing there looks like a Graph. I eventually got to a Graph by clicking around in the apidocs and came up with:
(-> "" RDFConnectionFactory/connect .fetch .getGraph)
... but I don't really know what that means and it errors out with a 400 Bad Request anyway. Has anyone tried this?Do you guys know a way to easaly copy/clone an InputStream without consuming it. OR if i really need to consume it (I think i cant scape this) how do i easaly clone it
Like copying it to an output stream for instance?
Not sure if this is what you are looking for but the first example here can help: https://clojuredocs.org/clojure.java.io/input-stream#example-5542a631e4b01bb732af0a8f
Yeah. Byte array is loaded to memory i guess, not quite effective for very large files
There is almost always a solution, π. Lemme see what i can find incase i find something I'll share if someone won't already have.
Ha thanks. Yeah i meant because I imagine that the whole idea of the stream is that its a stream so i may not know when it ends. so maybe copying without consuming it doesnt make sense Or thats what i figure
i think ill just create a function that takes an input stream and returns two. consuming one and creating two out of that one
Yes makes sense. What i am not sure is if it will be loaded to memory when you are creating it and for every time you are creating another one out of the main one.
If the original content is a file it would be better to use with open, return a lazy seq, do your ops on the lazy sequence before realizing them only when necessary. There is an example in the clojure docs let me try to find it.
@U8JTE9PG8 this is the example i was talking about, if the original data is a file. Something close to https://clojuredocs.org/clojure.core/with-open#example-5ac3318fe4b045c27b7fac2f
Welcome. But i guess too much of an overkill for a one liner. π .
Assuming, the loading to memory is done three times as stated earlier. Ps: I stand to be corrected, i haven't really worked with streams in CLJ, so i might be misinterpreting the clojure operation on Input streams, just done them in java.
I'm looking at scrollback now, but in case you didn't see this yet: FilterInputStream takes your inputstream, and returns a new inputstream that performs your extra actions on the data as the new InputStream
(import ( InputStream FilterInputStream ByteArrayInputStream))
(defn proof-of-concept
[s]
(let [is (ByteArrayInputStream. (.getBytes s "UTF-8"))
filter-stream (proxy [FilterInputStream] [is]
(read
([]
(println "reading, no arg")
(.read is))
([b]
(println "reading, one arg")
(.read is b))
([b off len]
(println "reading, three args")
(.read is b off len))))]
(slurp filter-stream)))
(cmd)user=> (load-file "/tmp/streams.clj")
#'user/proof-of-concept
(cmd)user=> (proof-of-concept "hello")
reading, three args
reading, three args
"hello"
for real code you likely want to implement the full interface (you can find that via javadoc), but read is enough for a focused demo
sure, and you can wrap a FilterInputStream the same as you can wrap any InputStream
(and somebody else aready did that before you)
var question 1: has anyone here ever relied on the thread-safety of alter-var-root
directly?
on 3, it's unused, was from some older version. there's a jira to remove that.
on 2, that's an impl of the Settable interface, which Var implements
I don't think the Settable stuff is used from anywhere, so that's probably legacy stuff too I'd guess
on 1, not sure what you're asking
Well, there isn't a function in clojure called reset-var-root
, only alter-var-root
that can atomically swap the value of a var, so I wonder what's the reason for that: I usually only need to set the root value of a var, but not atomically using a function. Why is it important for vars to have this feature / property?
all refs types have an "update" function of this shape, some also have "reset"
in Programming Clojure, we (here the royal we meaning Stu, me, and via discussion Rich) call this the Unified Update Model. Has also been called the Uniform State Transition Model in the past.
vars kind of fit into the model, but are a little special
Yes, I was aware of that. Just wondered in the case of vars where the atomically updating is used in practice by anyone. I have a Clojure interpreter which implements its own vars, but they are not atomic yet... Therefore I probably have to use locking
... and if I do that, I get issues with Graal π
ah, I understand the original question now
I'd say it's unusual for many programs to rely on this directly
some of the tag hierarchy / derive stuff does but that's again relatively unusual
and is probably not typically thread-sensitive
Maybe I could also just use an atom as the container for the var type. Then I would get this for free
they are similar in many ways (but differ in dynamic scope support etc)
I guess it probably would be rare to have multiple threads race towards doing an alter-var-root
Isn't def
the "reset" of Vars?
Yeah, but there isn't a function
like swap!
or reset!
or alter-var-root!
that does this with a var object.
Don't think def resets the var root. I think it justs sets a new Var to the same interned symbol
funny, it seems with-open
generates one redundant expression:
(macroexpand '(with-open [a b]))
(let* [a b] (try (clojure.core/with-open []) (finally (. a clojure.core/close))))
Sorry, didn't expand the entire thing:
user=> (walk/macroexpand-all '(with-open [a b]))
(let* [a b] (try (do) (finally (. a clojure.core/close))))
doesn't that macroexpand out by the end?
I've seen the use of *
to indicate derefable values.
(let [*my-atom (atom nil)])
Is there a library rather than http-kit that can be more reliable? Using http kit has gave me some headaches in terms of querying some API endpoints that return data but http kit treats the response as text
ahh yes. It is kind of annoying to deref my responses
which tool are you using?
sorry, don't know about boot
lein deps :tree
clj -Stree
in clj
@fabrao You can install clj
for Windows via Scoop -- it's a nice package manager π
See https://github.com/littleli/scoop-clojure and https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows -- it's what I use on Windows.
@fabrao boot show -d
shows the full dependency tree for me:
[ring "1.6.0-beta6"]
βββ [ring/ring-core "1.6.0-beta6"]
β βββ [clj-time "0.11.0"]
β βββ [commons-fileupload "1.3.2"]
β βββ [commons-io "2.5"]
β βββ [crypto-equality "1.0.0"]
β βββ [crypto-random "1.2.0"]
βββ [ring/ring-devel "1.6.0-beta6"]
β βββ [clj-stacktrace "0.2.8"]
β βββ [hiccup "1.0.5"]
β βββ [ns-tracker "0.3.0"]
β βββ [org.clojure/java.classpath "0.2.2"]
β βββ [org.clojure/tools.namespace "0.2.10"]
@seancorfield thanks
(that's with boot 2.7.2)
boot show -d
[com.climate/claypoole "1.1.4"]
[com.microsoft.sqlserver/mssql-jdbc "7.0.0.jre8"]
[com.taoensso/timbre "4.10.0"]
??? [com.taoensso/encore "2.91.0"]
? ??? [com.taoensso/truss "1.5.0"]
? ??? [org.clojure/tools.reader "0.10.0"]
??? [io.aviso/pretty "0.1.33"]
[lock-key "1.5.0"]
??? [base64-clj "0.1.1"]
??? [charset "1.2.1"]
[mount "0.1.16"]
[org.apache.poi/ooxml-schemas "1.4"]
??? [org.apache.xmlbeans/xmlbeans "3.0.1"]
[org.apache.poi/poi-ooxml "4.1.1"]
??? [com.github.virtuald/curvesapi "1.06"]
??? [org.apache.commons/commons-compress "1.19"]
??? [org.apache.poi/poi-ooxml-schemas "4.1.1"]
[org.apache.poi/poi "4.1.1"]
??? [commons-codec "1.13"]
??? [org.apache.commons/commons-collections4 "4.4"]
??? [org.apache.commons/commons-math3 "3.6.1"]
[org.clojure/clojure "1.10.1"]
??? [org.clojure/core.specs.alpha "0.2.44"]
??? [org.clojure/spec.alpha "0.2.176"]
[org.clojure/java.classpath "0.3.0"]
[org.jfree/jfreechart "1.5.0"]
[org.jfree/jfreesvg "3.3"]
[overtone/at-at "1.2.0"]
[seancorfield/next.jdbc "1.0.10"]
??? [org.clojure/java.data "0.1.4"]
??? [org.clojure/tools.logging "0.2.3"]
using [org.clojure/java.classpath "0.3.0"]
I canΒ΄t see [org.apache.commons/commons-compress "1.18"] in dep tree
the way maven deps are resolved, only one version of a given dep will be pulled in, and this run of the dep resolver picked 1.19 if the version matters, you can explicitly ask for a version before the other lib implicitly requires the lib
regarding "where is it came from" - the dep is resolved recursively, the tree shows poi-ooxml as a top level dep, and the dep wasn't specified before that, so the version it asks for was used
@fabrao If you believe you have a conflict, use boot show -p
-- pedantic mode -- which will show you all possible conflicts, how they were resolved, and which dependency brought them in.