This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-12
Channels
- # aleph (10)
- # beginners (62)
- # boot (12)
- # cider (97)
- # cljs-dev (171)
- # clojars (1)
- # clojure (224)
- # clojure-italy (4)
- # clojure-nl (2)
- # clojure-russia (1)
- # clojure-spec (41)
- # clojure-uk (68)
- # clojured (7)
- # clojurescript (115)
- # community-development (4)
- # cursive (2)
- # data-science (1)
- # datomic (18)
- # duct (40)
- # emacs (1)
- # events (1)
- # fulcro (148)
- # funcool (2)
- # graphql (2)
- # immutant (3)
- # jobs (3)
- # keechma (1)
- # luminus (2)
- # numerical-computing (1)
- # off-topic (19)
- # om (6)
- # parinfer (10)
- # pedestal (15)
- # precept (86)
- # reagent (12)
- # ring (3)
- # ring-swagger (2)
- # shadow-cljs (42)
- # spacemacs (19)
- # specter (17)
- # sql (11)
- # tools-deps (78)
- # unrepl (62)
- # vim (28)
Anyone around at the moment who knows the details of how clojars versioning works? I've got a lib up that's at a stable production version, say 1.0.0. I'd like to put a snapshot of 2.0.0 up so that folks can kick the tires, but I don't want it to get displayed as the current version. Does anyone happen to recall what gets shown as the default if the newer version ends in -SNAPSHOT
?
(I don't want to let it get shown as the default version, because I don't want folks to start using it when it may not be fully ready -- but I'd like to give beta testers easy access)
Not really answering your question @eggsyntax but if you use the new clj
tool, you can use git deps. Point to a commit sha directly, no need to "release"
@eggsyntax if it ends in -SNAPSHOT anyone who switches to it deserves whatever they get
Yeah, but in the interest of being kind to users, it'd be nice to have the default version be the production version...
wait whose defining a default?
Clojars, visually. If I got to a project page on clojars (eg https://clojars.org/adgoji/cascalog-graph ), I tend to add a dep to whatever version is shown on the main part of the screen (not the sidebar). If it's a snapshot, I try to look at the sidebar, but it would be easy to forget. So by "default," I just mean whatever version is shown on the main part of the screen.
I don't know - I would consider it a clojars problem if pushing a SNAPSHOT made it the version clojars suggests, but others might disagree
Yeah, I can see an argument either way, so I can't guess what the actual behavior will be. I'll find out, though đ
Ghadi can your lib be extended to make a jar not just an uberjar? Or are there better tools for that
Was looking at modifying it but it produced invalid jars with my changes. It looks like it relies on the dependencies manifest files?
What is the simplest way to convert an int-array (INT_ARGB data from an image) to a byte-array ?
Not sure. I don't know jvm that well so I don't know what should be in there. Just modified it so I could specify the class path from command line rather than asking for the full class path
@qqq do you want one byte per int, or bytes representing the same bytes that would represent the ints?
@noisesmith: well, each int is 4 bytes packed into it, representing ARGB
ByteBuffer
you can push ints into a ByteBuffer, then read bytes out
right, that's what ByteBuffer does for you
I don't know of a method to cast the pointers, but with ByteBuffer writes and reads you can get the same result
I don't get it, are you telling me to call putInt on ebery element of the int-array ? https://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html
that's exactly what I'm saying
then ask for the byte-array that's in it when you are done
if you find a way to do it in java via a cast, let me know, I'd be fascinated
as far as I know there's no such thing
@qqq alternately you could just bit-mask and bit-shift the ints
ah i meant the META/INF stuff
(re-find #"^META-INF/services/" filename)
:concat-lines
@noisesmith: an unrelated issue that is baffling me, PNG appears to be stored 0 - 255, java only has signed bytes, so "averaging" has interesting results.
@qqq there's a simple trick to get an unsigned value from the byte... let's see who finds it first
user=> (bit-and -1 0xFF) => 255
that's it
bit-and returns an int
right, right
the original java trick uses & which returns an int đ
there is: https://docs.oracle.com/javase/7/docs/api/java/awt/image/Raster.html#getPixels(int,%20int,%20int,%20int,%20float[]) but the problem is, it apperas to be single channel
i'm porting chas emerick's URL lib into the new stuff. the current version is 5 years without a commit and in cljx land
i mean create an artifact. one of the dependencies of URL is just as old. pathetic. i've got it converted and need to figure out how to make an artifact. but for sure you're right the rewrite could depend on a commit of it
For anyone who's curious about the question I brought up earlier re clojars: deploying a newer snapshot version to clojars does not make it the "default" version, ie the one shown on the main part of the page. It only appears in the sidebar. I'll paste a screenshot as a self-comment. @noisesmith @ghadi
I think that's probably the sanest choice on their part. Can't post images in a thread, I forgot; I'll imgur it up.
0.1.12 is the version that was already there. 0.1.17-SNAPSHOT is the version I just deployed.
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html endsWith will do string -> string -> boolean is there a function which does string -> string (returning the actual suffix/extension/ part after the last .)
In Clojure+JVM, how do I do 'back pressure' ? I have one queue who's behaviour is:
(java.util.concurrent.Executors/newFixedThreadPool 48)
which basically says: create a queue where there are 48 workers popping stuff off
now, when I submit things to this queue, I want to say:
if there's < 1000 items, submit to this queue
if there is >=1000 items, pause current thread until < 1000 items, then resubmit
maybe https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/BlockingQueue.html ?
Is that also not exactly what (chan 1000)
would do? Channels with a fixed size will never accept more than that number of values
is there a way in clojure to do keys-destructuring on something like:
(my-fn :arg-a "val-a" :arg-b "val-b" "non-map-value")
i.e. I would like a specific set of keys to get destructured into arg-a
, arg-b
etc and then have a & rest
or similar match the remaining args?
Note the uneven number of args in the call. I suspect this is not possible....yeah not possible i think. you have to do it manually; something like
=> (defn foo [& args]
(let [{:keys [a b]} (apply hash-map (butlast args))
c (last args)]
[a b c]))
#'boot.user/foo
boot.user=> (foo :a 2 :b 3 "42")
[2 3 "42"]
Was hoping there was some way of getting editor intellisense help with params for functions like this...guess we are out of luck there
ha! is that what the editors pull out? will definitely look into this. The functions in question are generated code so adding things to the metadata could definitely be an option
indeed it does work, then again, that makes the arglists a "lie" in that you can not do this in clojure
So, would this diagram (based on https://es.slideshare.net/adorepump/clojure-an-introduction-for-java-programmers ) be correct? (tried to add tagged literals)
I donât think there are any lines between the data reader and the evaluator/compiler
doesn't a tag literal invoke a function, returning the result of that function to replace the original tagged literal? Invoking a function is evaluating something?
yes, but I took the lines you already have from the reader as being that. it uses read-time evaluation for that
ok, right, I just tried to do something similar as 'macro': the compiler is just doing it's job, but in that diagram (I took from Rich), it's just a different block in the diagram. But yeah, I need to adapt it a little. No lines going back to the reader and replacing 'data reader' with 'tagged literal/function' may be more in line with the original diagram? (just to emphasis what happens with tagged literals)
tagged literal is a kind of value, data reader is the code evaluated to construct one
macro expansion is also evaluation (compile-time rather than read-time)
And I donât know what âprogramâ is there at all
just copied it from a talk from Rich Hickey đ. I just added the blue stuff.
Where you have tagged elements those are also data structures
right... just data structures which happen to be tagged literals. get it.
Hi, I was experimenting with a macro similar in concept to this one: (defmacro defdyn [name & body] '(def ^:dynamic ~name ~@body))
and I noticed that defining dynamic vars like this doesnât seem to work, am I doing something wrong?
@inbox you are applying the metadata to the wrong symbol, try ~(vary-meta name assoc :dynamic true)
instead of ^:dynamic ~name
1. Does the JVM use SSE instructions? 2. If so, if there anyway to control it? (I don't see it in the JVM bytecode).
look up -XX:+UseSuperWord option
I need a function where: input: namespace, symbol name output: string, which can be a valid Java classname I also need the function to be deterministic and one-to-one Suggestions ?
The Clojure compiler has a munge function to do this but itâs n to 1
As things like - and _
both map to _
thereâs a demunge
too
(let [my-queue (java.util.concurrent.ArrayBlockingQueue. 5)
my-pool (java.util.concurrent.ThreadPoolExecutor.
24 24 0
java.util.concurrent.TimeUnit/MILLISECONDS
my-queue)]
(doseq [i (range 10)]
(println "before put queue " i)
(.put my-queue
(fn []
(println "line " i)))
(println "after put queue " i)))
this code enqueues 0, 1, 2, 3, 4
but nothing is printed (i.e. executed)
why? what am I doing wrong I'm expecting the ThreadPoolExecutor to be draining the ArrayBlockingQueueHow is the thread pool executor involved? I see it created but not used.
Nvm. I see it now.
so the issue is that, if I use thre threadpool executor's .execute, if the queue is full, it rhwos an exception
why do you need a ThreadPoolExecutor ? start N threads, make them poll the queue, then feed the queue
I don't have a good reason for using ThreadPoolExecutor. I saw that it was available, it seemed to proviide the right abstractions (managing tthe threadcpool for me), so I tried it. It's entirely possible the right solution is to manage threads manually. Is that what you suggest ?
@bfabry: when the "queue" hits a certai nsize, I want all enqueues to block -- newFixedThreadPool only provides: 1. unlimited queue or 2. throw exception on full
oh sorry you want to block the caller. yeah I don't think anything provides that out of the box
there's nothing wrong using threads directly if you know in advance what they're dedicated for
kind of the same question isn't it? not unless you consider an exception back pressure
core.async has a mechanism for back pressure. otherwise if your producer is only one thread it's easy enough to do yourself
@ghadi: yes, I'm aware of the possibility of throwing exception on queue being full; is there a way to turn this into a blocking op? the best I can do is turn this into a delay + retry
"It is possible to define and use other kinds of RejectedExecutionHandler classes"
@qqq what about using CallerRunsPolicy? that is effectively blocking
and it's a form of backpressure surely
One way to write a ByteArrayOutputSream to a file is:
(let [baos (java.io.ByteArrayOutputStream.)
os (java.io.FileOutputStream. out-fname)]
(.writeTo baos os))
is there a way to do this async, so the .writeTo does not block the calling thread ?hello everyone. Iâm trying to generate a namespaced keyword from a string.
"hello" -> ::hello
is it possible to do this?
(keyword "hello") ;; => :hello
(keyword ":" "hello") ;; => ::/hello
@bravilogy ::hello is a shorthand for auto-namespacing to the current ns - one way to do it programatically would be (keyword (name (.name *ns*)) "hello")
(keyword (str *ns*) "foo")
will product :currentNs/foo
; or you can manually specify the ns with: (keyword "user" "foo")
oh I forgot (str *ns*)
worked
we already have java 8 interop?
can you explain what you're trying to do, your build tool settings, and any error messages you might be seeing?
nothing stops you from interacting with functional interfaces
I wouldn't expect clojure core to ever have a syntax for them like java does of course
@jimenezsaezjoseantoni more specifically you can use reify or proxy to make an instance of Function or Producer etc.
that's a separate question, even if we targetting minimum java 8 I'm not sure IFn would ever implement those interfacs
you don't need to convert - use reify or proxy instead of fn
out of curiousity, does https://github.com/ajoberstar/ike.cljj#converting-clojure-functions-to-java-sams do what you want?
also known as, I've never attempted to make use of Java's function stuff even within java, let alone Clojure
@noisesmith @tanzoniteblack thanks, that works! đ
when writing jvm bytecode, is there a way to say: I highly recommend you inline this :invokestatic ?
Hi all, do you know of an alternative of with-redefs
that is thread-safe so I can use it in a concurrent test-suite scenario?
@anler the two best ways to avoid with-redefs are to take stateful or out of scope elements as an argument so they can easily be substituted in a test (eg. stuartsierra/component simplifies doing this) or using a dynamic var so that it can have a per-thread binding
yes, Iâm aware, ironically we are using component in the project Iâm working on, but the business logic code is all coupled and I want to unit test a function with lots of deps to other functions
so I was using with-redefs
but in my mind I had the idea it was binding
, so it was a bit of a surprise when I saw my test suite failing đ
I generally just dynamic variables in this case, @inbox.
but if what I want to mock is another function, those function vars arenât dynamic right?
they can be
(defn ^:dynamic my-fn ...)
works just fine
@anler I actually use component to decouple function logic (since I'm already paying for it to manage stateful things), and it makes testing much simpler
just pass in a hash map with stubs of the things you need, customized for testing
yeah, but our codebase needs a lot of changes before we are able to do that, I would do it but moving things around make my team nervous ÂŻ\(ă)/ÂŻ
you can also do this via a wrapper (not using component)
refactor the function to be tested to use a new function that takes an implementation as an argument
then instead of testing the function, test the implementation, passing in a stub
for example, one of the dependencies for our functions is a db, but that db is passed directly to jdbc functions, so I guess we should first create a DB protocol or something that decouples our code from jdbc itself, but doing such changes right now seems unlikely
you can just do this with a higher order function, no protocol needed
found this though, it seems it works, it might be the quick and dirty solution: https://gist.github.com/gfredericks/7143494
from
(defn foo [db x] (blah db (bar x)))
to (defn foo-impl [instance x] (instance (bar x))
(defn foo [db x] (foo-impl (partial blah db) x))
@anler yeah, that gist does a few things that I'd be wary of. It's pretty much a hack
@anler the idea with the above is that you don't need to test (partial blah db)
- it's some database function provided by your adaptor
so you can test foo-impl with a different stub replacign the db stuff
oh I see, Iâll take note and see how I can introduce such changes without too much drama đ thanks!
that pattern shouldnât require more than splitting one function and making the second function a thin wrapper - definitely add a doc string describing why foo-impl exists though, because in my experience people will ask
and really the above could be a protocol with reify implementing it, but that tends to raise even more confusion
where a first class function makes it more âhumbleâ and doesnât make people assume some bigger design that isnât there
yeah, I like it, to put you in context the function Iâm trying to test is 57 lines long and depends on ~13 other functions đ
haha, that's an argument for refactor in itself
usually about this point i refactor so that the thing i'm trying to reder is an argument
>quote These temporary changes will be visible in all threads. Useful for mocking out functions during testing.
with-redef redefs named vars, which are by definition global, so by using it you immediately have global mutable state
I say that not as a dogmatic thing, but as someone who has worked on a large clojure code base with a large test suite that used with-redefs a lot, it sucks
if you are using with-redefs, whatever it is should be passed as an argument instead of def'ed as a global value
https://en.wikipedia.org/wiki/Java_bytecode_instruction_listings <-- are there no builtins for log / exp ?
I have a macro where I need the arguments to be evaluated first. I tried making it a function instead, but then the code I return doesn't get evaluated. So my only solutions right now are either to call eval on the args inside the macro, or call eval inside the function.
can you not do:
(defmacro foo
[x y & body]
`(let [x# ~x
y# ~y]
; do stuff with body
,,,)
then youâll need to parse the structure - this is one of the use-cases that clojure.spec was built for, so you could write a spec for the body and then use conform to pull out the pieces you need
you may want to rethink the design of this though if that turns out to be too complex; to me that points to a macro that is going to be hard to understand
can you write a sample "input to amcro" and "output to macro" pair so we can see what you have in mind?
and/or the function, since I need a and b in normal evaluation order, I don't really need a macro, but then I need to wrap combine-keys in an eval if I make it a function
Anyone have experience writing Cucumber tests in , then generating a class to be called in Java?
Not sure if cucumber-jvm-clojure
would help w/ that; it seems intended for writing Cucumber tests in and testing via a plugin. https://github.com/cucumber/cucumber-jvm-clojure
@U2J7JRTDX should be possible, bit it might be easier to write macro's for #etaoin wich van connectie to a webbrowser driver.
I'm looking at:
https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html
https://docs.oracle.com/javase/8/docs/api/java/lang/Float.html
and I see an exp(double)
but no exp(float)
Does exp only operate on doubles, and not floats ?
@greg316 Well, that's where things are a bit more complicated, I use a modified keys macro which prevents additonal keys, so it doesn't work with merge properly
Overall, I find its a situation I often get into. I want to control when the arguments would be evaluated, and maybe also when the return would be evaluated. What's the edge cases to watch out for when using eval
or resolve
in a macro?
resolve leads to spooky runtime errors with little clue at how to solve it, eval leads to bad performance
So, appart from performance and safety if used with untrusted input, eval executes in the same environment?
Would (defn foo [] (+ 10 global-symbol))
be equal to (defn bar [] (eval '(+ 10 global-symbol)))
you'd have to try and see, I forget some of the details of eval's environment resolution (I know it does not capture locals)