Fork me on GitHub
#beginners
<
2022-08-25
>
popeye11:08:35

I have a map as below , and if I want to update key :w and :p to true from the value of aj, How can i achieve it ?

(def aj [[:w false]
         [:p false]])

(def input-var {:a :b :c [[:p true]
                                  ]})

after applying aj to input result will be as below 

(def result {:a :b :c [[:p true]
                    [:w true]
                    [:p true]]})

tomd12:08:48

I assumed you would want to actually use the vals from aj so you'd use something like this:

(update input-var :c #(apply conj % aj))
;; => {:a :b, :c [[:p true] [:w false] [:p false]]}
but if you really want all vals to be true, you could do this:
(update input-var :c (fn [c] (reduce-kv (fn [acc _ [k _]] (conj acc [k true])) c aj)))
;; => {:a :b, :c [[:p true] [:w true] [:p true]]}

popeye12:08:47

hmmm similar I wanted , but how to update as true

tomd12:08:46

what do you mean by "update as true"?

popeye12:08:23

[:w true]
[:p true]
instead of false

tomd12:08:13

doesn't my second suggestion do that?

popeye12:08:36

oh yeah! one more question

šŸ‘ 1
popeye12:08:16

if we have inpu variables as

(def input-var {:a :b :c [[:p true]
                          [:w false]
                          [:p false]]})

popeye12:08:37

how can I update in specific vector index /

tomd12:08:35

you mean like this:

(assoc-in input-var [:c 1 1] true)
;; => {:a :b, :c [[:p true] [:w true] [:p false]]}
? I think this is the same question you asked on Monday, no?

popeye12:08:00

yeah, but I have a collection now a input

popeye12:08:16

ok got that šŸ™‚ (assoc m t [k true])

šŸ‘ 1
sheluchin13:08:01

Are there any tools for viewing very large EDN files?

rickheere13:08:54

vscode lets me expand/collapse forms

sheluchin13:08:23

Yes, but it will probably choke if you give it an EDN file that's 5 - 10mb.

rickheere14:08:17

Ah alright. I've opened huge xml files in vim

agile_geek08:08:26

You can open that size file in Emacs but it eats memory like crazy and TBH I’d rarely do it and only in fundamental mode not Clojure mode.

teodorlu16:08:44

I'd try to tap> the EDN into #portal

rickheere13:08:42

In clojurescript I call a function of a library and the function complains that the this is not there. What should I do? Uncaught TypeError: Cannot read properties of null (reading '_addListener') Code of the called function:

Ticker.prototype.add = function (fn, context, priority) {
        if (priority === void 0) { priority = UPDATE_PRIORITY.NORMAL; }
        return this._addListener(new TickerListener(fn, context, priority));
    };
The cljs that calls the function:
(game.ticker.add (fn
                       [delta]
                       (swap! elapsed #(+ % delta))
                       (set! (.-x sprite) (+ 100 (js/Math.cos (/ @elapsed 50.0)) 100))))

rickheere13:08:02

All the code:

(defn init
  []
  (let [game (js/PIXI.Application. (clj->js {:width 640, :height 360}))
        sprite (js/PIXI.Sprite.from "a.jpg")
        elapsed (atom 0.0)]
    (reset! app game) 
    (js/document.body.appendChild game.view)

    (game.ticker.add (fn
                       [delta]
                       (swap! elapsed #(+ % delta))
                       (set! (.-x sprite) (+ 100 (js/Math.cos (/ @elapsed 50.0)) 100))))))

rickheere13:08:34

Working example from the docs:

<script>
      // Create the application helper and add its render target to the page
      let app = new PIXI.Application({ width: 640, height: 360 });
      document.body.appendChild(app.view);

      // Create the sprite and add it to the stage
      let sprite = PIXI.Sprite.from('sample.png');
      app.stage.addChild(sprite);

      // Add a ticker callback to move the sprite back and forth
      let elapsed = 0.0;
      app.ticker.add((delta) => {
        elapsed += delta;
        sprite.x = 100.0 + Math.cos(elapsed/50.0) * 100.0;
      });
    </script>

rickheere14:08:01

Alright, I made it work by putting .add in front

(.add game.ticker
          (fn
            [delta]
            (js/console.log delta)
            (swap! elapsed #(+ % delta))
            (set! (.-x sprite) (+ 100 (js/Math.cos (/ @elapsed 50.0)) 100))))))

Muhammad Hamza Chippa15:08:33

I am getting the vector of maps from the re-frame and editing it using event although it is being changed on dispatching the event but the component is re-rendering. How can I solve this bug ?

(map (fn [model]
               [model-card-component ^{:key (:__Id__ model)} model]) @models)

vikas chinchansur23:08:55

Hello All šŸ‘‹, I am new to this Clojure Forum/community, an experienced Java programmer. At my work we are planning to use Clojure as backend programming language for one of our projects. It would be great if anyone can help with finding good online tutorials/courses to learn Clojure basics, which includes web development project as well. Thanks in advance. Cheers, Vikas

lsenjov23:08:11

Should have everything you need and a bit more, and welcome to the repl life

vikas chinchansur00:08:04

Thank you šŸ™‚ looks like it has everything in the links provided, if not will surely get back to the clojure slack channels