Fork me on GitHub
#clojurescript
<
2019-08-30
>
chepprey00:08:14

I use Cordova as part of my day job, which incidentally does not involve clojure. Did you have specific questions?

Christian Johansen05:08:43

I'm looking into extending protocols with metadata. Is it possible to provide an implementation of a protocol for maps in general, and override the implementation for specific maps? I seem to always get the general map behavior

Christian Johansen05:08:38

(defprotocol ExtMetaProtocol
  :extend-via-metadata true
  (ext-meta-protocol [x]))

(ext-meta-protocol (with-meta {} {`ext-meta-protocol (fn [_] 1)})) ;;=> 1

(extend-type cljs.core/PersistentArrayMap
  ExtMetaProtocol
  (ext-meta-protocol [m]
    2))

(ext-meta-protocol {}) ;;=> 2
(ext-meta-protocol (with-meta {} {`ext-meta-protocol2 (fn [_] 1)})) ;;=> 2, wanted 1

thheller08:08:24

there is a typo in the

{`ext-meta-protocol2 ...

thheller08:08:01

but this is probably not working due to the implementation in CLJS. it directly dispatches on the type and doesn't check the meta

thheller08:08:13

if CLJ actually picks the metadata before the type then this is a bug in CLJS

Christian Johansen10:08:42

ah, the typo was just a copy-paste error on my end 🙂

Christian Johansen10:08:51

didn't check how clojure behaves, will do

Christian Johansen10:08:01

yep, looks like a bug in cljs

Christian Johansen10:08:14

it behaves like I expected in Clojure

thheller10:08:15

yeah that'll require some changes to the analyzer/compiler then

Christian Johansen10:08:02

I tried to report it, but I can't log into Jira anymore it looks like

Christian Johansen10:08:18

it now redirects to http://id.atlassian.com where my old account does not work

Christian Johansen10:08:21

the clojurescript website links to jira, but does not explain how I gain access so I can report issues

thheller11:08:44

hmm not sure. I got an email some weeks ago to migrate my account IIRC

Christian Johansen05:08:58

is there perhaps a different way I can specify the base behavior?

Christian Johansen05:08:45

I seem to get the same behavior even if I define the protocol for a more generic type - e.g. object

Nazral07:08:19

Hi I'm struggling with using a content editable p. I am using this p because I want to style the text as I write it. I must take care of where the caret is, but at the moment for some reason the last space keeps getting erased and I'm starting to be lost

Nazral07:08:01

https://pastebin.com/Cu4SVibs this is the code I am using to move the caret around

Nazral07:08:05

(I removed irrelevant code)

Nazral07:08:55

I can type a and when I'll press a new key, it will write ab and erase the space

Nazral07:08:24

but if I move the cursor between a and b, I can type normally

Nazral07:08:06

Ok I think it's the keyup/keypress/keydown event messing things up nevermind I don't get it

Nazral07:08:41

Also it only happens with spaces, nothing else...

Nazral07:08:27

I solved it by adding a non breaking space at the end :man-shrugging:

markw22:08:26

Hi All - I have a question about the implementation of LazySeq, actually several questions, but I'll stick with the main one first: Since the lazy-seq macro expands into a LazySeq deftype (which wraps the body in a thunk) at macro-expand time, it is not until runtime afaict when first or rest is called on the LazySeq that the the body is evaluated. However, when it is evaluated, the recursive nature of the body results in another call to lazy-seq, but this is after compile / macro-expansion time, right? How does that work?

andy.fingerhut22:08:51

I do not know the answer, but just an FYI that #cljs-dev may reach an audience with more people who know the answer.

markw23:08:22

thanks - i'll try my luck there as well

roti10:08:37

this is an interesting question. my understanding is that macro expansion can occur at runtime as well, but in order for this to happen you need to have the compiler available at runtime. so, for example if you do AOT compilation, I'm pretty sure you can't "call" macros at runtime, so you need to have everything expanded. a macro is actually not very different from a function. the only difference is that it is applied to the data structure representing its body, instead of the arguments (which need to be evaluated before).

roti10:08:07

so when evaluating a function call (which is a list), clojure looks at the first element. if its a macro it calls it on the rest of the elements (without evaluating them) to obtain another data structure. if this other data structure is also a list it repeats the process, until the first element is not a macro anymore, in which case it must be a function, so it does the function call, which means it evaluates all other elements first, then calls the function. if the evaluation of one of the other elements is a macro expansion it does it, and so on.

roti11:08:34

you can play around with macroexpand and see how it works

roti11:08:24

on the other side, you don't need macros to implement lazy-seq, they just make the API prettier

andy.fingerhut19:08:51

You don't need macros to do anything in Clojure or ClojureScript. You can write the macroexpanded version yourself if you prefer. But the macros are often very nice for writing shorter cleaner-looking code.

andy.fingerhut19:08:48

In Clojure/Java, I suppose you could cause macroexpansion to happen at runtime using eval, but I do not believe that is possible in ClojureScript, i.e. neither possible to cause macros to be invoked at runtime, nor to call eval at runtime.

markw22:08:07

I understand lazy sequences generally (recursion + thunk, delay/force etc.) but am interested specifically in how they are implemented in the CLJS deftype