Fork me on GitHub

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


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


(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
  (ext-meta-protocol [m]

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


there is a typo in the

{`ext-meta-protocol2 ...


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


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


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


didn't check how clojure behaves, will do


yep, looks like a bug in cljs


it behaves like I expected in Clojure


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


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


it now redirects to where my old account does not work


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


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


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


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


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 this is the code I am using to move the caret around


(I removed irrelevant code)


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


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


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


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


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


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?


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


thanks - i'll try my luck there as well


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


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.


you can play around with macroexpand and see how it works


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


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.


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.


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