This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-15
Channels
- # aws (4)
- # beginners (98)
- # boot (23)
- # cider (63)
- # cljsrn (3)
- # clojure (259)
- # clojure-boston (1)
- # clojure-dev (2)
- # clojure-italy (6)
- # clojure-nl (17)
- # clojure-russia (1)
- # clojure-serbia (1)
- # clojure-spec (36)
- # clojure-uk (74)
- # clojurescript (11)
- # cursive (2)
- # datascript (12)
- # datomic (36)
- # defnpodcast (1)
- # devops (1)
- # docs (1)
- # emacs (15)
- # euroclojure (3)
- # fulcro (13)
- # graphql (1)
- # juxt (2)
- # lumo (27)
- # off-topic (46)
- # onyx (23)
- # pedestal (6)
- # planck (2)
- # portkey (27)
- # re-frame (18)
- # reagent (12)
- # remote-jobs (2)
- # ring-swagger (11)
- # rum (4)
- # shadow-cljs (104)
- # spacemacs (4)
- # sql (3)
- # tools-deps (5)
- # vim (45)
Best guess at this point is that one project had some test dependencies different than the other, and one of those deps was pulling in an alpha version of 1.9. I think the ns
spec might have gotten overwritten.
@dave.dixon If 1.9 was complaining about a ns
form in a library, then that library has a syntax error -- that just wasn't detected before 1.9 🙂 Quite a few libraries had syntax errors that were uncovered by 1.9 and needed to be updated...
Yes, it definitely had an error, empty ()
in the :import
.
Is there a way to mark a var as final in the same way you can mark a Java variable as final, to prevent it from being re-bound to another value?
@jamesvickers19515 a Var can always be redefined (in several ways)...
I was just randomly wondering because final is one technique for immutability in Java, wondered if Clojure has an equivalent
@jamesvickers19515 data in Clojure is immutable -- that's a more powerful promise than Java's final.
@jamesvickers19515 Consider
final ArrayList<Long> l = new ArrayList<Long>();
l.add( new Long( 42 ) );
// l = new ArrayList<Long>();
Here l
is final
but still mutable -- you can change the ArrayList
it refers to -- you just can't make l
point at a different ArrayList
One of the most deathful things about Java, you could use a final immutable list and that is almost like clojure, but it's very easy to make mistakes.
One of... a long list of such nasty things 🙂
I think the biggest strength with regards to clojures immutability is the implementation of the immutable collections, which negates a lot of the fuss in regards to the shortfalls of what most people think immutability means. Most people don't realize that you aren't necessarily copying a collection within memory to create an updated immutable collection from a previous immutable collection.
Actually i'm curious on whether clojure's collections are fully persistent, or only partially
i’ve always assumed they were fully persistent. what would it mean for them to be partially persistent?
the jvm’s garbage collector also helps make clojure’s immutable datastructures cool. not sure what the memory management would be like for immutable datastructures in something like c++
@smith.adriane You'd have to rely heavily on counted/auto pointer stuff I suspect 👀
from the wiki "partially persistent if all versions can be accessed but only the newest version can be modified"
@benzap They're fundamentally different on a number of levels.
@benzap Is there some specific sort of comparison you're thinking of?
I'm trying to study their codebases, so I can work out an implementation strategy for something similar
prepl looks like it's using stuff that isn't available till clojure 1.10 (tap>, add-tap, remove-tap)
prepl is a simple, data-oriented streaming REPL. You can use it directly or programmatically.
nREPL is a complete protocol that must be supported by the client (and is not a streaming system).
Why does everyone seem to think that whatever Clojure/core produce is aimed at replacing some community project?
Could you build an adapter between an nREPL client and a prepl server? No idea. Not sure why you'd want to... could you explain?
Have you looked at unrepl/unravel @benzap?
From a design standpoint, i'm trying to figure out how each one works. Trying to get some insight into implementing something similar for a scripting language I wrote in clojure
I would say: simpler is better.
nREPL is pretty heavyweight.
I'm not that familiar with socket repls whatsoever, so i'm trying to get more insights into whether I could maybe program prepl to do what I want
The nice thing about unrepl/unravel is that you can take a plain old Socket REPL and bootstrap it so you can use code completion, documentation insight, and so on. You don't need a heavy layer of protocols and libraries to make that happen.
At work, we regularly start a process with a Socket REPL (via the Java property), then we connect via unravel, specifying compliment as a dependency to enable completion/insight, then we have a fairly full-featured local REPL connected via an SSH tunnel to our server process. Works great. We don't need nREPL loaded into the server process, nor a fat client.
I'd just rather not reinvent the wheel. So what i've gathered, nrepl is pretty heavyweight, and unravel is similar and offers a similar feature while being simpler?
Define "similar features".
It depends what you need. I think nREPL is way over-complicated for most situations.
We used to have an automated test that used an nREPL connection to modify a running process to mock something so the test could verify an API behavior. We dropped down to a simple Socket REPL and it hugely simplified our test code.
Compliment is an auto-complete library (at a high-level).
The standard REPL is designed to support all sorts of lightweight client-side extensions. Look at Bruce Hauman's Rebel Readline stuff.
Socket REPL is a standard bare REPL running over a socket.
i.e., what clojure.main
can start up.
alright, so this is nothing like lein repl
, which uses its own repl protocol called nrepl?
prepl takes away the prompt and produces standardized data responses instead of a mix of text, data, and exceptions.
lein repl
(and boot repl
) is based on nREPL.
It requires nREPL on both the client and the server.
lein repl
starts an nREPL server (on port 65432 or whatever) then starts an nREPL client and connects to that port.
so nrepl was a community-made protocol, and prepl is something that is going to be part of clojure as a more extensive standard repl that is data-oriented
Yeah, basically.
Per Clojure 1.10, you'll be able to guarantee prepl with no additional dependencies.
just like you can assume Socket REPL per Clojure 1.8
I'm not really sure what it does, my guess is there will be an article in the future explaining what they are for exactly
It's a nice way to add debugging into the REPL.
prepl exposes the data sent to the tap so it's easy to access programmatically.
a process can send data out to all connected taps (whether there's no taps active or a dozen)
It's a nice extension point for debugging.
I'm not familiar enough with core.async to say.
Yeah, sort of.
I think that makes sense. Instead of pulling in core.async as a dependency, they implemented a small subset for that purpose
I think my advice in general would be "don't over-think it". Clojure/core / Cognitect are very focused on "simple" and "composable".
I need to hit the sack, thanks for the feedback @seancorfield
G'nite...
I'm using carmine
library for redis
. it's likely there's no way to shutdown(or close) the connection pool(I use lsof -i:6379
on redis server and can't find way make the connection disconnected). also don't know how can i customize the redis connection pool size.
I am getting a dependency mismatch with s3. In my project I have specified dependency on com.amazonaws/aws-java-sdk-s3 {:mvn/version "1.11.261"}
.
Also, I have a library whose transitive dependency include a different version of sdk . I have specified a exclusion for s3 as:
libB {:mvn/version "2.0.0-SNAPSHOT"
:exclusions [com.amazonaws/aws-java-sdk-s3]}
Now, when I do clj -Stree
. I can see that only the correct version is being included.
But when I tried to find the location of sdk being included using
System.out.println(SDKGlobalConfiguration.class.getProtectionDomain().getCodeSource().getLocation());
as per https://github.com/aws/aws-sdk-java/issues/1071
I see that it is referring to the location of the jar of the transitive dependency which is the older version of aws sdk.
FWIW I am using the clj tool and deps.edn and the conflicting libraries are java based.Wild guess : Try resolve-dep
to see if the correct version is resolved (Little confused since -Stree gives correct version). There seems to be an option :override-deps
that is worth a try.
Seems like a relevant issue : https://dev.clojure.org/jira/browse/TDEPS-13
I tried :override-deps using an alias:
sth like
:aliases {:dev {:override-deps {com.amazonaws/aws-java-sdk-s3 {:mvn/version "1.11.261"}}}}
but I see the same behaviour.
hmm according the issue it should support exclusion of the transitive dependency on the maven project level. In my case the conflicting library is a transitive dependency of a dependency, could that be an issue ?
This seems to be a clj specific bug, the same chain of deps work in boot.
This doesn’t make sense to me - could you file a TDEPS bug with the deps.edn to repro so I can take a look? If you’re seeing the right thing with -Stree, you should see the same thing at runtime
I was able to find some more details. This happens when the dependent library has maven shade plugin enabled. Is this expected ?
maven shade has some known bugs around timestamping that can cause issues
that is, not preserving file timestamps during shading (Clojure load logic for .clj vs .class uses timestamps)
This seems to be a clj specific bug, the same chain of deps work in boot.
Hi, Im trying to figure out a way to prevent calling/referencing certain functions of an external clojure library in our project for security reasons. One way that Ive come up with would be to have a test that searches for those symbols and makes sure that the ns list comes out empty. Unfortunately I haven't figured out how to code that test up. I know that cursive and emacs does support that. The closest Ive come is the https://github.com/clojure-emacs/refactor-nrepl#find-symbol function, but I didn't get it to work with the external library as the file path is either on the classpath or inside a jar in the local maven cache. Any help and other solutions are very welcome. Thanks in advance.
You will maybe interested in https://travis-ci.org/DomainDrivenArchitecture/pallet
@matt220 We're working currently on lifting dependencies to clojure 1.9 😉
@jerger_at_dda yes, that is interesting! i had no idea
So, is Travis CI reviving Pallet or is that someone's project at Travis CI? I'm really curious who is behind this work
@matt220 We forked pallet at https://github.com/DomainDrivenArchitecture/pallet and will provide pull-request and / or maintain the fork. As we're using pallet heavily (e.g. at https://github.com/DomainDrivenArchitecture/dda-serverspec-crate) we're very interested in keeping pallet in a good shape. Travis is just showing, that we're working on pallet just in this moment.
Travis has clojure builders, so you can build clojure projects there. We build all our open source projects in this way 🙂
hi all, im getting myself wrapped around the axle on trying to programmatically intern a bunch of java interop
in a nutshell, I think what I want is similar in function to the memfn form, except I need to generate the symbol dynamically
as an example, theres a bunch of CodedOutputStream/computeXXXSize functions: https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/CodedOutputStream
what I would like is to intern a bunch of these from a list, like (map intern-my-interop [“Byte” “Bool” “Int32”]), etc
my approach was something like this: https://gist.github.com/ghaskins/ea35fb5e2376b749d18f7de388698229
I suspect a macro could pull this off; where the macro emits all of the desired variants
but its proving difficult to get any of the interop forms to accept a symbol for eval rather than a literal
@mfikes yeah, i tried that too…i was slamming into “cant eval local” problems, more than likely PABCAC
@mfikes was trying something like
(defmacro interopfn [member]
`(memfn ~(eval member)))
(defn- ->sizefn [type]
(let [name (-> (str "size-" type)
symbol)
sym (-> (str "CodedOutputStream/compute" type "Size")
symbol)
f (interopfn sym)]
(intern *ns* name
(fn [tag value]
(if value
(f tag value)
0)))))
i think I am in macro-on-macro land at this point, which is probably part of my problem
maybe, i tried something like that initially before I discovered intern, and was having problems
Looks like clojure was used to bootstrap sku-vault's apparently successful use foundationdb. https://abdullin.com/sku-vault/2017-01-22-dsl-impression/
How to do type hints inside threading macros?
(def a "foo")
(.length ^String a)
(->> a (.length ^String)) ;; error
As a work-around I used as->
:
(-> foo
parse
(select “li.previous”)
first
(as-> elt (.text ^Element elt)))
type hints are a reader macro, which means they happen at read time (before macroexpansion) - so there's no way to get ^Element
to work with ->>
. you'd need to use with-meta
or vary-meta
But -- if you want to debug it, first
(set! *print-meta* true)
then macroexpand your formsI’m going for this one:
(defn text
"Gets text from Jsoup Element"
[^Element elt]
(.text elt))
🙂 looks clearer
Clojail is an option. Personally I prefer to use lua for this kind of things. Luaj makes it super easy to use clj datastructures from lua without copying via proxies, it can also be sandboxed and resource limited easily.
fwiw, positano provides a nice api for querying information like this: https://github.com/stathissideris/positano/blob/master/src/positano/analyze.clj#L763-L770
@U050AACJB said the same thing when I showed him the datomic namespace in tools.analyzer 🙂
@dominicm thanks for promoting it, but @U060FKQPN please note that this is super beta and written with a hangover 😄
man this is exactly what I wanted to enable people to do when I wrote that, it makes me so happy to see it works (even if still alpha) :)
@U060FKQPN I ended up remixing one of your functions to also convert :meta
and :env
info to EAV
this could be super useful for Eastwood /cc @U04V5VAUN @andy.fingerhut
@U060FKQPN thanks, but it’s a tiny bit of code that belongs in positano anyway I think 🙂
and positano needs a major cleanup, it contains endless comments with lots of experiments, it’s just not presentable the way it is
I'm looking to do some NLP in Clojure and I'm wondering if anybody with some experience can recommend a particular library. I see postagga, clojure-opennlp and clojure-nlp-parse as 3 semi-popular github repos. Any suggestions?
that, of course, only finds static uses, if you lookup the var manually you can by pass it
I'm guessing from the context that this is more about linting rather than actual secure execution at runtime. Otherwise, I'd recommend trying clojail.
wow, thanks @alexmiller @hiredman and @dominicm, you really got me unstack here, thats awesome!
I wonder what would happen if you explicitly destroyed all the vars in the ns after all your code loads? - then worst case is a runtime failure when trying to call a var, but you know the vars are not called
(unless something was inlined...)
so removing the var from the namespace doesn't mean an already compiled function can't use it
I believe if you use direct linking, those vars are not included statically
but a similar outcome, removing the vars from the namespace doesn't stop you from accessing the vars value. without direct linking you could nil out all the vars, but with direct linking even doing that wouldn't stop you (but direct linking is only for invoking functions)
question about namespaced keywords: in the reframe app template, in the myproject.core namespace, there is a key that looks like this:
(defn ^:export init []
(re-frame/dispatch-sync [::events/initialize-db])
(dev-setup)
(mount-root))
in the myproject.events namespace, there is an event handler registered for ::initialize-db
so how does the ::events/initialize-db
in myproject.core
get associated with ::initialize-db
in myproject.events
?
it's an alias, it will expand to the namespace that has the events
alias
can someone shed some light on regexes in clojure? I think I'm missing a something basic. I'm trying to write a spec for a string, and that string needs to be all lower case letters or a hyphen:
re-matches matches the entire string, it doesn't do sub-string matches
re-find does substring matches
youre regex does not match the entire string, so doesn't do what you describe - yeah, what @andy.fingerhut said
that's not what you described
[a-z-]+ would match that
If you want hyphens in as many places as you can have letters, put the hyphen inside the square brackets (but at the end, or the beginning, since otherwise it has a special meaning between square brackets)
Then you don't need the |-
part of the regex any more, of course
so, re-find is looking at substring (in this case, each letter), and my regex says it can be any lower case letter or a hyphen
don't use re-find if you want to check the entire string
but you need to use a regex that describes the entire string in that case, naturally
re-find will look for any substring it can find that matches the regex. e.g. (re-find #"[a-z-]+" "1923-1930")
returns "-"
whereas re-matches returns nil (no match), because the regex does not match the entire string.
How to correctly exclude file from uberjar
? Both
:uberjar-exclusions [#"frontend" #"resouces/scripts" #"aws_config" #"user.clj"]
:jar-exclusions [#"user.clj"]
doesn't really work (`src/user.clj` is the file I am concerned about)that’s just a function in clojure.core
http://clojure.github.io/clojure/branch-master/clojure.core-api.html#clojure.core/PrintWriter-on
yeah, it was added for prepl, but is useful otherwise too
I’ve got some date/parse interop that takes Instant::from
. How do I do that in Clojure? Instant/from
gives me an “Unable to find static field” error.
https://stackoverflow.com/questions/17913409/what-is-a-sam-type-in-java/17913661#17913661
Oh nice. I didn’t think that’d be so easy to search. I thought this was called a “functional interface” before. Never heard of called SAM. Thanks for link
I think that term was one I saw in a lot of the lead up to indy, I suspect they wanted a different term from "functional interface" because java got a bunch of interfaces named Function
so (reify TemporalQuery ...fill in method stuff to invoke the from static method...)
the :: syntax effectively tells the java compiler to generate an implementation of the expected interface that invokes the given static method
.stream().map(MyType::xform)
etc, etc, assumes you’re mapping MyType data, so apply the xform method to it. I see.
it is more or less short hand for creating anonymous classes to wrap calls to static methods
The super cool thing about Intellij for the bits of Java programming I still do: it suggests all those things without me ever having to understand anything!
You mean clojure.instant
?