Fork me on GitHub
#clojure
<
2017-08-08
>
qqq00:08:18

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

qqq00:08:42

I'm going to just pipe everythign to cljs, which will render via reagent + svg ... I think this is the slowest possible choice 🙂

tbaldridge00:08:45

right, but this is bitmap drawing

noisesmith00:08:55

yeah, why would a bitmap need a bezier

qqq00:08:03

because bitmap text, in my experience, has all types of problems unless rendered in very very very specific conditions

noisesmith00:08:42

that article doesn't mention bitmaps, if you aren't rendering bitmap that's cool, but then you aren't rendering bitmaps iykwim

noisesmith00:08:48

oh, you never mentioned bitmaps yourself, OK - though "blit" might not be the right word here?

qqq00:08:14

ah, I see, maybe 'render' would have been better

ayidi00:08:32

Would love to hear your thoughts...

didibus02:08:32

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?

didibus02:08:44

map-of, nevermind

henrik05:08:15

@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.

dominicm09:08:19

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.

dominicm09:08:03

e.g. for (defmulti foo type) I have to do (get-method foo (type [1 2 3]))

hmaurer09:08:25

@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]))

bronsa09:08:56

why would you need to do that tho?

bronsa09:08:08

backing up a particular defmulti impl?

dominicm09:08:53

@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.

dominicm09:08:27

@hmaurer thanks, didn't think to check java. Covers my case, wouldn't work if I needed cljs though.

bronsa09:08:47

@dominicm is :default not ok?

bronsa09:08:40

usually rather than doing (if (multi-implements x y) (x y) (default y)) we just do (defmulti x :default [y] (default y))

bronsa09:08:58

(not that multi-implements is a thing)

dominicm09:08:30

@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)

bronsa09:08:57

hmm, that implies writing HOF code that assumes f is a multimethod, sounds like a code smell to me?

bronsa09:08:16

unless I'm misunderstanding

dominicm09:08:13

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.

yonatanel10:08:54

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.

bronsa10:08:01

call .addMethod on the multimethod, not public api tho

yonatanel10:08:45

Actually now I see it can be done with derive or composite keys.

hmaurer11:08:45

@yonatanel yep. I am not exactly sure what you mean but derive can be used to support more than one instance of a kind

andrea.crotti11:08:30

I tried out a few tools for profiling & co (tufte & criterium for example) but it looks quite hard to get some simple metrics

andrea.crotti11:08:01

I would just like to find out for example given a function call, how long it took in all the different sub calls

andrea.crotti11:08:08

and ideally how much memory each of them used

andrea.crotti11:08:26

any suggestions about how to do that?

andrea.crotti11:08:36

the ideal thing would be to actually be able to plot a tree like this tool does https://github.com/jrfonseca/gprof2dot

andrea.crotti11:08:04

which apparently supports Java Hprof format

reborg11:08:04

@andrea.crotti have a look at visualVM. There is a snapshot button that creates a tree of function calls with timings.

andrea.crotti11:08:24

ok thanks I'll try @reborg

andrea.crotti12:08:53

it's a pity there isn't something simpler to use in the REPL directly

andrea.crotti12:08:02

but visualVM is pretty awesome

bronsa12:08:02

yourkit is much, much better than visualvm, if you can afford it

bronsa12:08:09

they give out open source licenses too

andrea.crotti12:08:13

actually on that project where I need it visualvm fails with error 67 sadly

andrea.crotti12:08:32

if I go through the million lines of errors maybe I'll find out why exactly

andrea.crotti12:08:47

I'll have a look at yourkit as well thanks

misha13:08:54

(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))))

pesterhazy13:08:26

ifn? may be more appropriate, depnding on the context

misha13:08:27

need a break obviously

misha13:08:24

no, ifn? would true on keyword, which does not work for me, unless I will not mess up the predicates cond clauses order

misha13:08:10

Are there any arguments for/against using keywords/symbols in map destructuring?

{:keys [:foo] :as state}
;; vs 
{:keys [foo] :as state}

misha13:08:02

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.

misha13:08:11

afaik, "rename" does not do destructurings, might be wrong though

joshjones13:08:54

{: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] ...

joshjones13:08:05

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

pesterhazy13:08:09

yup, :keys [foo] is more idiomatic

misha13:08:10

@joshjones you can ::keys [:foo] btw, and ::keys [foo] respectively

joshjones13:08:01

neat shortcut — though to do different namespaces you’d still have to do {:keys {:ns1/foo :ns2/bar} ...}

misha13:08:24

that's true, in that case {:keys [ns1/foo ns2/bar] ...} works too

misha13:08:12

so one can consistently avoid keywords there

Garrett Hopper13:08:55

Does anyone else have issues with Intellij/Cursive butchering cljc conditionals with its reformat code option?

misha13:08:20

@ghopper me, did nothing about that. you can ask around in #cursive

Garrett Hopper13:08:13

Hmm, alright. Thanks, didn't know that channel existed.

danp15:08:50

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}]))

ghadi15:08:25

@danp 1) are you realizing the results of the query into memory?

octahedrion15:08:28

is there any way to update the multimethod dispatch fn after a namespace :reload ?

danp15:08:26

@ghadi I don't think so, I've tried wrapping in take and still get the issue.

ghadi15:08:42

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

danp16:08:04

Interesting. I'll have a look at that, cheers. It's an Oracle database, but this gives me more to go on.

danp16:08:20

I'm also curious as to whether the :fetch-size option needs to be used in conjunction with a result set somehow.

danp16:08:46

I've just found that so will investigate when I get into the office tomorrow. Thanks for the pointers @ghadi 🙂

misha16:08:34

@pesterhazy harold

(fn? #'clojure.core/+)
;=> false
(#'clojure.core/+ 1 2)
;=> 3
(var? #'clojure.core/+)
;=> true
(ifn? #'clojure.core/+)
;=> true
(fn? (resolve 'clojure.core/+))
;=> false

ghadi16:08:46

basically don't use fn?, use ifn?

noisesmith16:08:38

@mischa on the other hand (fn? @#‘clojure.core/+) => true

noisesmith16:08:51

when you call vars, they look up the thing they hold and call it

misha17:08:45

@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.

noisesmith17:08:23

right, and if you deref var you get the actual thing in it

misha17:08:12

will it be var in cljs too?

noisesmith17:08:14

@(resolve ‘+) is identical to @#‘clojure.core/+

noisesmith17:08:24

will resolve work in cljs?

noisesmith17:08:27

if so I would expect so

noisesmith17:08:09

my figwheel repl says it works (but that could be an artifact of figwheel’s internals and not “real”)

misha17:08:34

so what you are saying is: I can deref var to see whether it points to function or something else?

noisesmith17:08:47

deref on a var gets you the precise thing in the var

noisesmith17:08:29

there’s also var-get but deref has that fancy @ shorthand

misha17:08:52

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

noisesmith17:08:27

well, resolve seems to return a thing you can deref…

misha17:08:31

since it is not a client code - shorthand is not that critical :)

misha17:08:19

I stumbled upon fn? false while conforming to spec, fwiw

misha17:08:08

anyway, thank you, deref bit is useful

shader18:08:58

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

shader18:08:58

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

Garrett Hopper18:08:26

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 _.

shader19:08:34

@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

Garrett Hopper19:08:04

@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.

jeff.terrell19:08:11

@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/

jeff.terrell19:08:06

And yeah, a single -# style binding is only valid within the context of a single syntax quote.

shader19:08:47

@jeff.terrell thanks for the reference

hmaurer19:08:30

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

hmaurer19:08:18

Basically a lazy merge

hmaurer19:08:08

Actually, merge might do the job? I am not sure, I should try it

bfabry19:08:20

yeah sounds like merge

hmaurer19:08:01

My use-case is with Datomic’s “entity” API, which behaves like a lazy map

hmaurer19:08:08

I want to decorate an entity with some extra attributes

tbaldridge19:08:17

the interfaces are all open

tbaldridge19:08:47

proxy might also work

dpsutton19:08:01

also there's zack's stuff in potemkin where you can easily make your own type maplike

hmaurer19:08:08

Mmh, apparently I can’t merge a Datomic entity with a map:

hmaurer19:08:11

java.lang.AbstractMethodError:

hmaurer19:08:27

When trying this:

=> (merge (d/entity (d/db conn) 17592186045516) {:foo "hello"})

hmaurer19:08:45

I wasn’t really expecting it to work, but that’s the “dumb” approach for what I want to do

hmaurer19:08:25

@tbaldridge can I do this is a simple way?

hmaurer19:08:45

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?

tbaldridge19:08:27

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.

hmaurer19:08:27

@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

mrkaspa20:08:16

is there a library to convert clojure.spec/explain-data to something friendly to respond in a json api?

mrkaspa21:08:26

@misha thank I’ll check it

mrkaspa21:08:43

@misha it just print it good, but I want to return like validation errors in json format

misha21:08:58

ask around in #clojure-spec

mrkaspa22:08:14

cool thanks

bradford22:08:04

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

noisesmith22:08:40

it’s simple to connect a manifold stream to a core.async channel, in either direction

bradford22:08:34

Thanks -- I don't see any reference to sockets in manifold after grepping the codebase. Am I missing something?

noisesmith22:08:15

oh - you want aleph for that, which uses manifold, sorry

noisesmith22:08:28

(from the same author, manifold was written as a helper for aleph)

noisesmith22:08:48

and manifold connects sockets to streams

hmaurer22:08:49

When using -> with single-argument forms, will people usually put parentheses around the forms? e.g. (-> :foo name) versus (-> :foo (name))

noisesmith22:08:06

I prefer the paren version, but clearly it’s optional

mattly22:08:36

I've come to prefer the paren version too, but I know others who don't

mattly22:08:35

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

noisesmith22:08:57

this reminds me of a sort-of related pet peeve: people using (-> foo :bar :baz :quux) instead of (get-in foo [:bar :baz :quux])

bfabry22:08:35

I don't use a paren because one of my main uses of -> is (-> (Java.) .train .wrecks)

misha22:08:20

-> is faster than get-in opieop

noisesmith22:08:34

what makes you think that?

misha22:08:08

I measured that with time dotimes a year ago for giggles

noisesmith22:08:04

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

noisesmith23:08:06

updated with proper bench, and with another case

souenzzo20:08:16

try with (com.rpl.specter/select [:a :b :c] m). Should be even faster

misha22:08:29

even by eyeballing get-ins source and macroexpanded -> I get a feeling it is slower

which is: (:c (:b (:a {:a {:b {:c 0}}})))

ghadi22:08:35

one is stack calls only; the other needs seq manipulation

misha22:08:45

but get-in might be more convenient if you have any ints or symbols in path

mobileink23:08:41

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.

mobileink23:08:29

call it get* and i might come around. ;)

misha23:08:11

update* and assoc* too? :)