This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-05
Channels
- # architecture (2)
- # aws (1)
- # bangalore-clj (4)
- # beginners (97)
- # boot (35)
- # cider (8)
- # cljsjs (3)
- # cljsrn (35)
- # clojure (190)
- # clojure-dusseldorf (4)
- # clojure-italy (7)
- # clojure-poland (1)
- # clojure-russia (17)
- # clojure-spec (74)
- # clojure-uk (30)
- # clojureremote (2)
- # clojurescript (298)
- # code-reviews (18)
- # component (18)
- # cursive (18)
- # datascript (3)
- # datavis (2)
- # datomic (24)
- # dirac (17)
- # emacs (3)
- # garden (7)
- # hoplon (51)
- # jobs (2)
- # jobs-rus (2)
- # leiningen (4)
- # luminus (11)
- # mount (24)
- # off-topic (1)
- # om (32)
- # onyx (25)
- # pedestal (1)
- # powderkeg (9)
- # protorepl (6)
- # re-frame (11)
- # reagent (15)
- # spacemacs (6)
- # sql (35)
- # uncomplicate (1)
- # unrepl (74)
- # untangled (130)
- # yada (6)
Please help with newbie java-source-paths question: When I’m repl I can easily import java classes from java-source-paths
directories, if I restart REPL and leave code importing those classes it fails with Caused by: java.lang.ClassNotFoundException:
@rmuslimov How are you “restart[ing the] REPL” and how is that different to how you start it the first time?
I wrote some code, left few import of local java classes. Check that it were working well, then closed REPL and tried to launch new one.
If you’re new to Clojure and the Clojure ecosystem, we might want to move this discussion to the #beginners channel.
But I’ll ask: when you launched the new REPL, did you launch it exactly the same way, in the same folder as before?
Are you using Leiningen? Or Boot?
but no success, REPL can't import local java classes. If I comment all local java imports - it works
is there a way to know what the "root" namespace of an application is, what it's name is, etc? ie, if i do lein new app name1
, could i, in clojure code, recover name1?
not really - it's valid to have multiple entrypoints for starters
and core is just a convention
i can't rely on (System/getProperty "user.dir")
and just check the last part of the path, etc
you can look at project.clj if it exists
i'm analyzing a stacktrace in cider-nrepl and i'd like to mark whether it came from the user's application or not
for a given resource, you can inquire for the path
so that the stacktrace can be filtered down to just user code with the click of abutton
yeah, the path works but that leaves me with conventions like underscores and hoping that the name of the directory is the name of the application
eg if you know 'src' is the only part of the classpath on the local disk, you can use io/resource to ask for the file the namespace asks from, and check if the uri starts with ./src
or wait - not exactly that, but it works
+user=> (.getPath ( "org/noisesmith/coordinator.clj"))
"/media/justin/806084F16084EEEA/clojure/coordinator/src/org/noisesmith/coordinator.clj"
really - just check if it's a file!
+user=> (.getProtocol ( "org/noisesmith/coordinator.clj"))
"file"
if it came from a file. then the user probably cares 😄
exactly. unfortunately, it looks all of the file info at this point is the compiled temp files
:user=> (.getProtocol ( "clojure/core.clj"))
"jar"
oh yuck - yeah, this is a project that doesn't use lein so I have the actual files as the resources
also for underscore conversion etc. clojure exposes that as a reusable function
{:fn "divi",
:method "invoke",
:ns "cider.nrepl.middleware.stacktrace-test",
:name "cider.nrepl.middleware.stacktrace_test$divi/invoke",
:file "stacktrace_test.clj",
:type :clj,
:line 29,
:var "cider.nrepl.middleware.stacktrace-test/divi",
:class "cider.nrepl.middleware.stacktrace_test$divi",
:flags #{:tooling :clj}}
it's guaranteed that the path has to match the full ns name, for require to work at all
(not counting the /tmp/init-foo type files of course which you don't require but contain code from the real files)
yeah - with the . becoming / etc. and munging parts of the ns name
what guarantees are there on the :file
k/v in the meta hashmap for vars in a namespace?
@dpsutton In general I wouldn't assume any meta to be a guarantee. A variety could be interned without even a file existing
@dpsutton can you run inside the same app? if so then would it be sufficient to parse the value of *ns*
to get the first component? Just thought I'd offer another alternative in case it's relevant.
@dpsutton but in the case of file on Vars, I think they're set when interned, and that's the only code path for defining them, so I think it can be true trusted. Just be aware what it does when no file exists.
Is the following intended behaviour ?
(assoc nil 1 2) ==> { 1 2 }
(assoc! (transient nil) 1 2) ==> exception
I know that replacing nil with {} makes it work; its just the difference surprises me.@qqq Given what persistent!
and transient
do, it's not too surprising that they can only operate on concrete collections and not nil
...?
@seancorfield : good point, wtf is (transient nil)
supposed to return ?
If you look at (type (transient []))
you'll see a specific transient vector type -- but (type nil)
is just nil
. There's no type to transform.
in theory, one could make this work via a (transient nil) => :transient-unkonown, and it stays unkonwn until one uses assoc! or conj! at which point it determines the type; but that is unnecessairly complex, and throwin gexceptino on (transient nil) makes more sense
Yeah, the problem is that nil
steps outside the type system -- to have a "transient nil" you'd have to cascade it through everything.
besides writing a macro (which screws up debugging info), is there a nice way to use:
(let [ [a 1]
[ b 2 ]] ...)
instead of
(let [a 1
b 2] ...)
why would I want this? easier eamcs navigation@tbaldridge: regarding midje, iirc you mentioned preferring to avoid DSLs; with regards to spec, do you view spec as: (1) a DSL, but worth learning, or (2) not a DSL ?
Hello 🙂 I'm trying to use JRuby binding.pry
debug REPL from a Clojure REPL, any idea how to do it?
instead of writing
(defn blah [a b c]
(assert ::x a)
(assert ::y b)
(assert ::z c))
is there a way to write
(defn-speced blah [ ::x a ::y b :: z c])
?@qqq Don't go overboard with macros. For instance, Cursive users would hate that. You'd lose much of the IDE functionality. Just write a macro that assert multiple values like (assert-s ::x a ::y b)
I don't care about cursive users; but macros makes exceptions ahrd to debug, whcih I do care about.
I'm struggling connecting luminus to oracle db using the following URL jdbc:oracle:thin:username/password:@10.29.10.214:1521:orcl I'm getting -- Error creating DB connection for jdbc:oracle:thin....
Hi folks! Just in case somebody uses (or going to use) mocks in their tests, here is my small library to mock Clojure functions: https://github.com/igrishaev/mockery
hi all, I need to implement a solution which traverses some data-structure and updates the state on the way. Ideally without taking the state as an explicit parameter. I've checked funcool's cats but they removed the state monad saying _They are not very useful in clojure_ https://github.com/funcool/cats/releases . What is the clojure idiomatic way of dealing with state in distributed set of functions?
I’m not sure if this is what you’re looking for but anyway an interesting read: https://clojure.org/about/state
I mean, you can make a recursive function that processes the first item in a data structure, then updates external state, then recurses to the rest
of the list
@lambder I normally use postwalk
and prewalk
for that. For simplicity sake I'll keep the state in an atom:
(let [state (atom {})]
(walk/postwalk
some-data
(fn [node]
(swap! state ...)
node)))
Or if I really cared about avoiding mutability I would write my own version of postwalk that threaded the state as an extra param to the walk function.
@qqq Yes, I consider spec to be a DSL. So the next thing I have to ask is how much the DSL forces me to learn new semantics and syntax. Here spec doesn't bother me much since the syntax is normal clojure, and the semantics match normal clojure fairly closely. Except of course (s/cat) and other regexes, but that closely matches parser combinator logic.
In fact almost all of Spec could be seen as a form of parser combinators, which really just boil down to function composition.
@tbaldridge one thing, I can't walk my datastrucure in single function.
explain?
@tbaldridge I'm thinking if I can have something similar to `(def state {}) (defn foo [x] (altervarroot state (assoc state :a x))) (defn bar [x] (altervarroot state (assoc state 😛 x))) `
no, you don't want to do that
So why can't you walk the structure from one function, or dispatch from one function?
there's no reason to use a monad for this
so why not dispatch from one function?
@qqq read the docs on assert
Another option is to use s/assert within your code to assert that a value satisfies a spec. On success the value is returned and on failure an assertion error is thrown. By default assertion checking is off - this can be changed at the REPL with s/check-asserts or on startup by setting the system property clojure.spec.check-asserts=true.
@tbaldridge let me think on this, I'll get back to you. many thanks
@lambder I will say this: monads are very rarely used in Clojure, they don't really offer much benefit for the cost.
@lambder: don't listen to the nay sayers; I'm writing a typed DSL in clojure just so I can get monads 🙂
@tbaldridge I'm not walking the datastrucuture this way.
@lambder: is https://github.com/killme2008/defun the defun you are yousing?
Well something to consider: 1) store your nodes in a hashmap, those are much easier to work with than vectors. 2) use multimethods. Even using vectors it's fairly trivial to do (defmulti eval (fn [state node] (first node))
3) thread the state as a parameter. Implicit args just confuse readers
@lincpa do you have a question? I'm not sure why you're posting these images
i’m generating sql with honeysql and its working out great but i’d like to get a fully-formed sql query as a string with the placeholders resolved
does anyone know if there are any jdbc classes I can call that can take this: ["SELECT * FROM my_table WHERE time > ?" #inst”1970-01-01T00:00:00.001000000-00:00"]
to this SELECT * FROM my_table WHERE time > ‘1970-01-01’
the result being a string
i’m trying to avoid doing this manually
@jaydeesimon most SQL libraries don't support this directly, instead they'll hand these parameters to a SQL prepare statement, as that's a bit more secure against SQL-injection. What are you trying to accomplish?
i’m trying to generate select statements that i’m going to wrap in a postgres COPY .. TO statement
Also notice the loss in precision in the conversion you are trying to perform, it's going from a full timestamp (with a timezone) to just a date (with no timezone)
noted (just an example)
when i try executing those statements using clojure.java.jdbc/execute! i get an error
and I think its because postgres doesnt allow me to do the placeholders with COPY .. TO (emphasis on i think)
passing a string with the placeholders resolved seems to work
at the moment, i have a function that can resolve placeholders but it occurred to me that this happens already so theres gotta to be a way to reuse that code but i think i ran into what you said about how most sql libraries dont support this
Mind pasting the full query that doesn't work?
sure, let me scrub it down to something thats easier to understand (that also doesnt work, of course)
If I have a defrecord
with sensitive field values, should I implement both toString
and provide a print-method
method to help keep its values out of logs, or is one or the other sufficient?
i could be wrong but i think that error is because postgres doesnt allow placeholders that are not inserts, updates, delete, etc (http://dba.stackexchange.com/questions/121453/error-there-is-no-parameter-1-in-execute-using-statement-in-plpgsql)
Yeah, I don't have any other advice then, besides that wrangling a SQL DSL may be harder than using a stored proc for something like this.
no problem. thanks for your help though. i’ll just stick with resolving the placeholders manually. the datatypes i need to support are only integers and dates so the code i have written is simple enough. would prob be simpler than reaching into the jdbc driver depths of hell to reuse any potential placeholder resolving code anyway
side note: i enjoyed your clojure/west talk!
I don't think many people run Korma at all, most I have talked to have moved on to HoneySQL, or HugSQL, or the like
We ran/currently run Korma on a previous project I was on. I'm not on that project anymore but I don't recall using the utf8mb4
character set =/
There is a #sql room which might be a better place for a discussion, but having spent a good deal of time digging into korma, I would be a little bit surprised to discover that korma had a bad sql charset behavior that clojure.java.jdbc didn’t have
@scknkkrer I realize this might sound snarky, but the easiest solution to utf8mb4 issues is not to use mysql and the issues just don't come up
korma has nothing to do with it, it's about the db config, whether the issue even applies to the db backend, and the db driver
that's going to be specific to your db and adaptor, and it's going to be the same answer you'd get if you were asking about java, so my first step would be to google for answers about configuring that db for java
there's maybe a small conversion from the java config to the clojure, but it should be trivial
what is your db and the specific error happening/
I just tried all my language’s special characters and it’s just “ı” the problem here.
what database? what adapter for that database?
Take this to #sql — people are already answering there.
@lambder "a solution which traverses some data-structure and updates"-> https://clojuredocs.org/clojure.zip/zipper ?
=> (defn trun! "like run! but with a transducing arg" [xf proc coll] (transduce xf (completing #(proc %2)) nil coll))
is that silly? is there already something else in core I should use instead of it?
the completing shouldn't hurt, since it's meant to ignore the reduction and return nil
partion-by builds up batches, then flushes them when a new partition value shows up, and the final batch is flushed by the completion arity
=> (trun! (comp (map inc) (filter even?) (mapcat #(vector % %)) (partition-by identity)) println [1 2 3 3 4 5])
[2 2]
[4 4 4 4]
[6 6]
nil
; looks fine to meunless this isn't the kind of usage of partition-by you had in mind? I'm slightly confused
@hiredman I wrapped completing around the anonymous function because I got errors for the one argument arity, and I knew that should always return nil anyway, so completing seemed more elegant than making a multi-arity fn
no, I think I just forget all the corner cases where transduce and transducers either use or ignore the completing stuff
OK - thanks for the feedback
right, and that checks, the proc would always be passed nil, and the ultimate f produced inside transduce (by applying xf to proc) will have the completing arities intact for the transducers
hi guys, could you suggest a way to solve this koan?
it comes from this koan file https://github.com/functional-koans/clojure-koans/blob/master/src/koans/15_destructuring.clj
which is about destructuring
I'm wondering if it is possible to make it pass by only changing the _ part of the code
@piotr.owsiak (fn [[name surname] {:keys [street-address city state]}] (clojure.string/join ", " [(str name " " surname) street-address city state]))
maybe can be shorter
@hcarvalhoaves oh, right, thanks!
Is there a way to turn s/assert on-off PER FILE ? i.e. I want s/assert to be on for foo.cljc but off for bar.cljc
@qqq those are also global
logging systems give you that level of control - maybe that would be a better match
I want the following: is this a canary I'm doing something wrong? For each file, I have public and private functions. For the public functions, I want the assets to always be on. For the private functions, I want one toggle for all theri pre/post conditions (for debugging vs production).
the built-in assertions don’t give you that level of control
Your best course of action is probably writing a prodassert
that's always on, and using assert
for dev
you could write your own assert that looks at a global map in an atom or something
depends how perf sensitive you are but it’s pretty easy to macro this up