Clojurians
#cljs-dev
<
2016-04-12
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

viebel03:04:43

A question related to extend-type for IFn protocol Why the transpiled code contains implementation for call, apply and also cljs$core$IFn$_invoke$arity$1? Look here: http://app.klipse.tech/?cljs_in=(ns%20my.regexp)%0A%0A(extend-type%20js%2FRegExp%0A%20%20IFn%0A%20%20(-invoke%20%0A%20%20%20%20(%5Bmatch%20s%5D%20(re-find%20match%20s))))%0A%0A(%23%22clojure%22%20%22clojurescript%22)%0A&amp;js_only=1 In my understanding, the code for cljs$core$IFn$_invoke$arity$1 is not required

thheller08:04:12

@viebel if you compile with :static-fns true the call will be /clojure/.cljs$core$IFn$_invoke$arity$1(null,"clojurescript");

thheller08:04:11

which is an optimization to improve dispatch

thheller08:04:25

more apparent if you use a function with multiple arities

thheller08:04:39

and google closure can optimize it better

thheller08:04:24

I would advise to stay away from extending protocols on native types

thheller08:04:35

some browsers behave very strangely when doing that

thheller08:04:02

although the main villian of IE9- is gone

viebel11:04:43

@thheller even with :static-fns true, the function call occurs with /clojure/.call()

dnolen11:04:02

@viebel: optimized calls will get emitted that’s why

dnolen11:04:56

as to why you aren’t seeing that - I have no idea - but only interested in hearing about potential problems through ClojureScript only

viebel11:04:50

Maybe unused code is emitted is my specific use case?

viebel11:04:14

What do u mean by " optimized calls will get emitted that’s why"?

dnolen11:04:22

that’s what I mean

dnolen11:04:49

again if you want to verify what I said I recommend reading the compiler

dnolen11:04:03

look at the :invoke case of emit in the compiler.cljc

dnolen12:04:32

if the compiler cannot determine that fn arity is statically knowable but :static-fns true it will emit a conditional

dnolen12:04:45

that checks it has the arity and invokes, and uses call otherwise.

viebel12:04:30

in what cases fn arity is not statically knowable?

dnolen12:04:38

@viebel: read the source

dnolen12:04:50

you keep asking questions and I keep pointing out the source

viebel12:04:55

it’s a bit cryptic. sorry

dnolen12:04:58

you have to have some respect for my time here

dnolen12:04:43

and no I don’t expect that you will understand precisely how :invoke works without spending a day or two on it

dnolen12:04:53

but if you’re really interested that’s just what you’ll have to do

viebel12:04:14

I understand