This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-08
Channels
- # aleph (4)
- # beginners (5)
- # cljs-dev (21)
- # clojure (155)
- # clojure-dev (3)
- # clojure-italy (10)
- # clojure-losangeles (3)
- # clojure-nl (2)
- # clojure-russia (5)
- # clojure-spec (42)
- # clojure-uk (11)
- # clojurescript (170)
- # code-art (1)
- # component (3)
- # core-async (28)
- # cursive (70)
- # data-science (3)
- # datascript (1)
- # datomic (28)
- # emacs (6)
- # gorilla (1)
- # graphql (2)
- # jobs (1)
- # lein-figwheel (4)
- # lumo (7)
- # off-topic (13)
- # om (63)
- # parinfer (66)
- # planck (1)
- # re-frame (22)
- # reagent (2)
- # ring-swagger (53)
- # rum (3)
- # sql (13)
- # test-check (2)
- # unrepl (48)
- # vim (8)
- # yada (33)
for rendering text on gpu, the issue I ran into is not texture coordinates but thints lik3e signed distance fields, multi channel signed distance fields, and trying to render bezier curves in shader
I'm going to just pipe everythign to cljs, which will render via reagent + svg ... I think this is the slowest possible choice 🙂
right, but this is bitmap drawing
yeah, why would a bitmap need a bezier
because bitmap text, in my experience, has all types of problems unless rendered in very very very specific conditions
that article doesn't mention bitmaps, if you aren't rendering bitmap that's cool, but then you aren't rendering bitmaps iykwim
oh, you never mentioned bitmaps yourself, OK - though "blit" might not be the right word here?
With spec, how can I spec the form of the a key in a map? Like I want to specify that keys on a map must be int? for example {1 "" 3""} is valid, {:1 "" 3 ""} would not?
@didibus https://stackoverflow.com/questions/43453776/clojure-spec-for-a-map-with-non-keyword-keys
@didibus It seems you’ll have to find another way of formatting your data in order for spec to be on board with it. It’s an interesting case, I’m so used to using keywords that I didn’t consider that this might be a limitation in spec.
Is it possible to call get-method
without knowing what the dispatch-fn in use is? It seems I have to call it on anything I use.
@dominicm Take everything I say with a grain of salt (I am a clojure noob) but I just took a quick look. Apparently you can get the dispatch function like this: (.dispatchFn foo)
, and so you could do this:
(get-method foo ((.dispatchFn foo) [1 2 3]))
c.f. https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/MultiFn.java#L19
@bronsa equivalent to implements?
for a multi method I guess. Want to use tree-seq with a multimethod that returns sequences for various inputs that relies on the hierarchy.
@hmaurer thanks, didn't think to check java. Covers my case, wouldn't work if I needed cljs though.
usually rather than doing (if (multi-implements x y) (x y) (default y))
we just do (defmulti x :default [y] (default y))
@bronsa Probably is for my use-case :thinking_face:, as I control the multi-method. But was somewhat writing code under the assumption of no knowledge about the multi method. It wouldn't work if I cared about distinguishing nil/false as a value from the default though (`contains?` vs get
I guess)
hmm, that implies writing HOF code that assumes f
is a multimethod, sounds like a code smell to me?
That's a good point. If the implements
is then provided by the caller, they can have knowledge of the dispatch-fn used by the multi-method, so no information leak there. Although there is a little code duplication.
Is it possible to add defmethod
for a value that is resolved at runtime? I'm looking for a way to have a lib of reusable integrant multimethods supporting more than one instance of each kind.
@yonatanel yep. I am not exactly sure what you mean but derive can be used to support more than one instance of a kind
I tried out a few tools for profiling & co (tufte & criterium for example) but it looks quite hard to get some simple metrics
I would just like to find out for example given a function call, how long it took in all the different sub calls
and ideally how much memory each of them used
any suggestions about how to do that?
the ideal thing would be to actually be able to plot a tree like this tool does https://github.com/jrfonseca/gprof2dot
which apparently supports Java Hprof format
@andrea.crotti have a look at visualVM. There is a snapshot button that creates a tree of function calls with timings.
ok thanks I'll try @reborg
it's a pity there isn't something simpler to use in the REPL directly
but visualVM is pretty awesome
actually on that project where I need it visualvm fails with error 67 sadly
if I go through the million lines of errors maybe I'll find out why exactly
I'll have a look at yourkit as well thanks
(symbol? +) ;;=> false
(symbol? '+) ;;=> true
which predicate would return true
in the 1st case?
Need to coerce x
to "executable", e.g. if it is symbol?
, I'd do (resolve x)
on it next; if it is keyword, I'd
(resolve (symbol (str (namespace x) (name x))))
(fn? +)
@pesterhazy thanks
ifn?
may be more appropriate, depnding on the context
no, ifn? would true
on keyword, which does not work for me, unless I will not mess up the predicates cond
clauses order
Are there any arguments for/against using keywords/symbols in map destructuring?
{:keys [:foo] :as state}
;; vs
{:keys [foo] :as state}
one "pro" :foo argument would be: IDE (cursive in my case) would show destructuring site in usages, which might help you prevent post-refactoring bugs.
{:keys [:foo] ...}
would be less familiar to readers of your code, although with fully-qualified keywords becoming more common, we are likely to see more {:keys [::my-kw] ...
but i find {:keys [:foo] ...}
to be a bit harder to read, as you won’t be using :foo
later, but foo
— and i wouldn’t choose a relatively obscure IDE use case over that, but ymmv
yup, :keys [foo]
is more idiomatic
@joshjones you can ::keys [:foo]
btw, and ::keys [foo]
respectively
neat shortcut — though to do different namespaces you’d still have to do {:keys {:ns1/foo :ns2/bar} ...}
Does anyone else have issues with Intellij/Cursive butchering cljc conditionals with its reformat code option?
Hmm, alright. Thanks, didn't know that channel existed.
I'm currently trying to use clojure.java.jdbc
to pull data from a very big table to ultimately dump out to CSV, but I'm getting an OutOfMemory GC overhead limit exceeded
error. I've got the following, but not 100% sure about the arrangement of the options :cursors
and {:fetch-size 10000}
. Please can someone help me fix this?
(j/query ora-uri (j/prepare-statement my-conn "select * from my_schema.very_big_table" [:cursors {:fetch-size 10000}]))
is there any way to update the multimethod dispatch fn after a namespace :reload ?
ok 2) different database drivers have different necessary parameters to turn on query streaming https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-implementation-notes.html MySQL for example needs fetch-size set to Integer/MIN_VALUE
Interesting. I'll have a look at that, cheers. It's an Oracle database, but this gives me more to go on.
I'm also curious as to whether the :fetch-size
option needs to be used in conjunction with a result set somehow.
I've just found that so will investigate when I get into the office tomorrow. Thanks for the pointers @ghadi 🙂
(fn? #'clojure.core/+)
;=> false
(#'clojure.core/+ 1 2)
;=> 3
(var? #'clojure.core/+)
;=> true
(ifn? #'clojure.core/+)
;=> true
(fn? (resolve 'clojure.core/+))
;=> false
@mischa on the other hand (fn? @#‘clojure.core/+) => true
when you call vars, they look up the thing they hold and call it
@noisesmith my initial intention is to accept FSM description from user as a bunch of maps and vector, where handlers/behaviors are either symbols, keywords or (it turned out) vars. And during "compilation" step I want to actually resolve and call those.
So far I end up with a cond
resulting in eventual resolve
, which returns var.
right, and if you deref var you get the actual thing in it
@(resolve ‘+) is identical to @#‘clojure.core/+
will resolve work in cljs?
if so I would expect so
my figwheel repl says it works (but that could be an artifact of figwheel’s internals and not “real”)
so what you are saying is: I can deref var to see whether it points to function or something else?
deref on a var gets you the precise thing in the var
there’s also var-get
but deref has that fancy @ shorthand
I recall vars aren't real in cljs. I don't need vars there, I just need to be able to call fn by it's keywordized name. var
is just a transition step for me
well, resolve seems to return a thing you can deref…
How do I write a macro that expands to a defmacro? I'm having trouble getting nested syntax-quotes to work the way I want
another challenge I have is passing -# style variables to an inner expansion function; they only seem valid as long as you're still inside the syntax-quote-space
Is it possible to have a multimethod which doesn't take its key as an argument. So I'd call the multimethod with its first argument being a key to dispatch on, but I don't want each defmethod to have to ignore that first key argument with an _.
@ghopper multimethods are more general than just dispatching on the first key; they dispatch on some function of the entire argument list. So there isn't a built-in assumption that the first argument is the dispatch value and should thus be ignored. If you really want to ignore it, you could make an alternate defmethod macro that wraps the handler in a function that only passes the rest of the arguments through
@shader Yeah, I know the dispatch could be some complex method on all arguments. I was hoping someone would have an alternative to multimethods that would do what I want. I'd rather not jump to macros for something like this. Dispatching on the first key and ignoring it is fine for me.
@shader - Could be helpful (especially tip 9: use multiple functions to build up the s-expressions): http://blog.altometrics.com/index.php/2016/04/29/a-few-tips-for-writing-macros-in-clojure/
And yeah, a single -# style binding is only valid within the context of a single syntax quote.
@jeff.terrell thanks for the reference
Is there a “proxy map” concept in clojure? I am wondering if I can “wrap” a map-like object with another map. Key lookups would first hit the outer map, and if the key is not present it would hit the inner map
the interfaces are all open
proxy might also work
also there's zack's stuff in potemkin where you can easily make your own type maplike
I wasn’t really expecting it to work, but that’s the “dumb” approach for what I want to do
@tbaldridge can I do this is a simple way?
Other, unrelated question: is there a “strict” version of clojure.core/get
which would throw an error if a key is not found instead of returning nil
?
There's not a out-of-the-box way to do it, but it's fairly simple to use reify + several interfaces to do this. For example, ILookup looking up values in a object.
@tbaldridge ok, thanks! I think I see how I could do it with reify & co; I was hoping there would be a core lib function for it. I’ll try to roll my own
is there a library to convert clojure.spec/explain-data to something friendly to respond in a json api?
@mrkaspa have a look at https://github.com/bhb/expound
@misha it just print it good, but I want to return like validation errors in json format
Hi fam. Is there a way to connect a core.async
channel to a java.nio.channels.SocketChannel
? I was looking through ztellman.streams and poking at manifold and nothing came to mind
it’s simple to connect a manifold stream to a core.async channel, in either direction
Thanks -- I don't see any reference to sockets in manifold after grepping the codebase. Am I missing something?
oh - you want aleph for that, which uses manifold, sorry
(from the same author, manifold was written as a helper for aleph)
and manifold connects sockets to streams
When using ->
with single-argument forms, will people usually put parentheses around the forms? e.g. (-> :foo name)
versus (-> :foo (name))
I prefer the paren version, but clearly it’s optional
on the flip side, sometimes I use keywords in the thread like (-> foo :somekey (first))
and I don't surround the keyword with parens even though I'm using it as a fn
this reminds me of a sort-of related pet peeve: people using (-> foo :bar :baz :quux)
instead of (get-in foo [:bar :baz :quux])
what makes you think that?
wow, criterium agrees
peregrine.circle=> (def m {:a {:b {:c 0}}})
#'peregrine.circle/m
peregrine.circle=> (crit/bench (get-in m [:a :b :c]))
Evaluation count : 597888540 in 60 samples of 9964809 calls.
Execution time mean : 99.999514 ns
Execution time std-deviation : 2.744883 ns
Execution time lower quantile : 95.756712 ns ( 2.5%)
Execution time upper quantile : 105.967403 ns (97.5%)
Overhead used : 2.428401 ns
nil
peregrine.circle=> (crit/bench (-> m :a :b :c))
WARNING: Final GC required 1.123286362523048 % of runtime
Evaluation count : 1776268680 in 60 samples of 29604478 calls.
Execution time mean : 30.583876 ns
Execution time std-deviation : 0.768462 ns
Execution time lower quantile : 29.469073 ns ( 2.5%)
Execution time upper quantile : 32.219808 ns (97.5%)
Overhead used : 2.428401 ns
Found 1 outliers in 60 samples (1.6667 %)
low-severe 1 (1.6667 %)
Variance from outliers : 12.6000 % Variance is moderately inflated by outliers
nil
peregrine.circle=> (crit/bench (-> m (get :a) (get :b) (get :c)))
Evaluation count : 1854297360 in 60 samples of 30904956 calls.
Execution time mean : 31.168778 ns
Execution time std-deviation : 0.875598 ns
Execution time lower quantile : 29.696016 ns ( 2.5%)
Execution time upper quantile : 32.973022 ns (97.5%)
Overhead used : 2.428401 ns
nil
updated with proper bench, and with another case
surprising
even by eyeballing get-in
s source and macroexpanded ->
I get a feeling it is slower
which is: (:c (:b (:a {:a {:b {:c 0}}})))
what's a '[]' among friends? i generly prefer ->
on aesthetic grounds. get-in
as the name for what it does is just, well, wrong, somehow.
updated with proper bench, and with another case