Fork me on GitHub
Muhammad Hamza Chippa20:01:59

{"user_account" [{"user_account_id" 1, "user_type" 0}]} I have this type of data in the clojurescript file, I wanted to convert string into keyword how can I do that is not working in the clojurescript file ?


Would be more suitable for #beginners.


(it got answered in #beginners just in case anyone else checks this thread)


I'm trying to implement cache in my application for a bunch of key value pairs which would keep only the latest X number of pairs (perhaps a few thousand or so). The older ones would be discarded as the new ones are being added. Currently I'm using a map inside an atom but since maps do not keep the insertion order I don't know how to discard the older entries. I'm reading about array maps but those are only for smaller arrays because of performance reasons. One solution I can think of is to keep a vector of keys parallel to the map which would keep the insertion order but it doesn't seem very elegant solution to me. Any ideas how to go around this problem?

Alex Miller (Clojure team)21:01:44

well you could just use a core.cache with LRU


Does this work for Clojurescript as well? (Sorry I'm pretty new to this)

Alex Miller (Clojure team)21:01:55

no, sorry, didn't realize we were in cljs channel :)


@alexmiller It's ok, thanks anyways 🙂


@nedim searching on the web for "lru cache javascript" comes up with a couple of helpful things for implementing your own or as a JS library


So I am doing that trick with x.cljs requiring macros from x.clj, specifically :

(ns mxreact.mxreact
  (:require-macros [mxreact.mxreact])
... and I am getting apparently warnings such as WARNING: map already refers to: #'clojure.core/map in namespace: mxreact.mxreact, being replaced by: #'mxreact.mxreact/map The problem is that I am indeed generating macro map and a couple others because I am generating wrappers for all known HTML tags, and map is an HTML tag, so in it goes. Looking at, I see a promising:
    [lib.ns :refer []
            :rename {}
            :as alias]
... but I want all tags other than map to be accessible without using the alias. Hmm, I recall :refer :all being a non-starter for CLJS. Has that changed? I see other variants of require that look promising, but was told to use :require-macros and I always do what I am told. The ugly (easy) way out would be NOT to generate the conflicting macros and code those up manually with names like html-map, but it would be neat to leverage some cljs ns flexibility to do that. I thought I would drop in here for guidance before turning my thousand monkeys loose at the their keyboards trying various incantations. Suggestions welcome! 🙏


You can get rid fo the warning by doing :refer-clojure :exclude [map]


Thx! But I might need these other tags, so I want to rename them. Well, maybe I can :exclude [map] and then add an :alias mxweb and let the rare usage do (mxweb/map ...)?


the warnings you get are from the CLJ namespace and :require-macros is not the right place to do what you want to do. :require-macros is not producing this warning. see how fulcro has done it


consumers can do (:require [mxreact.mxreact :as mx]) (mx/map ...) just fine without any aliasing or whatever


I also have an older impl setting up the dom elements as macro/fn combo, also note the :exclude


I'm trying to match a multi-line string wit a regex, but when I compile I get: ERROR: JSC_LANGUAGE_FEATURE. This language feature is only supported for ECMASCRIPT_2018 mode or better: RegExp flag 's'.


Is there anything I can do for that, or do I need to just refactor my code to not use re-find?

Cora (she/her)23:01:37

so I don't have a solution for you but I was curious and I searched for ECMASCRIPT_2018 here in slack and a lot of stuff popped up. it seems like you can change the js version target and it'll be fixed?


Ya, that makes sense.


I'm just weary of doing that since I don't know what other effects it will have.


But anyway, I was able to get rid of the regex and just wrote out the code I needed by hand. Oh well. 😞


Thanks anyway btw.


s flag makes . behave like (?:.|\n) (anything or newline in non-capturing group) replacing dots with with that might be feasible for you. it uglyfies reg ex a bit, but it is an option:


(throw an \r there too, I guess)


@borkdude thanks, js solution would be a bit easier since Maps in js keep the insertion order so I guess I could do some interop, but also searching for lru cache clojurescript I came upon CLJS port of clojure/core.cache though it hasn't been updated in a while (perhaps it doesn't need to). I'll look into it, thanks!


well, one way is to just make a ring buffer


{:i    0
 :keys (vec (repeat 2000 nil))
 :data {}}


to insert you just check your current place in the :keys vector


(defn insert [{:keys [i keys data]} k v]
  (if-let [existing (nth keys i)]
      {:i    (mod (inc i) 2000)
       :keys (assoc keys i k)
       :data (-> data
                 (dissoc existing)
                 (assoc k v))}
      {:i    (mod (inc i) 2000)
       :keys (assoc keys i k)
       :data (assoc data k v)})


something like that. What i wrote wont work but thats the general direction i would go


@U3JH98J4R Thanks, I'll give it a try!