Fork me on GitHub
Ivan Koz11:04:10

@gseyffert see, transient wants implementation of IEditableCollection interface as its input, only few collections implement that interface

Ivan Koz11:04:03

anyway i found the answer in Emerick's book

Graham Seyffert11:04:55

Yeah, you’re right. I’ve gotten in the bad habit of just referring to anything I can call seq on as a seq, which is incorrect

Graham Seyffert11:04:13

But my original answer is correct I believe

Ivan Koz11:04:39

answer to my question was, 'yes'

Graham Seyffert11:04:45

If you pass a collection to transient, you can still safely use the original reference

Graham Seyffert11:04:33

That would be terrible if you couldn’t!

Ivan Koz11:04:49

yeah, transients is a bit tricky to understand at first

Ivan Koz11:04:30

but thanks to awesome clojure design it's all uniform


People of Clojure, I have a question. I read somewhere that it's possible to connect Clojure REPL to java app in debug mode. Did Anybody try that? Could you please share your experience/links here ? I saw one repo in GitHub, but it's more than 5 years old. It would be nice to have a modern way of doing that.


Is there a way to force use-context-classloader false for an Uberjar?


axiom-dom.jar won't load because it expects to classload /META-INFO/axiom.xml


is there a way to get the "next" item of an item in a sorted map?

Ivan Koz14:04:48

@roti what kind of items do you store in the sorted map?


a record type


but I have found another way to implement what I want


essentially I need to keep an index which will allow traversing the collection one at a time


and I just found out .indexOf is implemented for vectors, therefore I can use a vector instead of a sorted map and just play with the index

Ivan Koz14:04:03

@roti drop over seq of map doesn't work for you?


the use case is following: the keys are strings (the filename), the values are record types, and I need to iterate over the sortedmap (either by keeping the index, but this does not exist in a map, or by keeping the key)

Ivan Koz14:04:31

i'm not an expert, i think we can split sequence by take-while \\ drop-while so effectively next item will be the first element of drop-while sequence


I wonder if it's possible to implement the functions "loeb" and "moeb" in Clojure?


just out of curiosity, I tried playing around with lazy-seq and memoization but couldn't get it to behave lazy enough to actually evaluate


here's a (non-working) translation of the Haskell code

(defn loeb [fs]
    (map (fn [f]
           (f (loeb fs)))

  [(constantly 1)
   #(inc (second %))
   #(inc (first %))])
;; should=> (1 3 2)

Ivan Koz15:04:13


(def my-map (sorted-map "e" 5 "d" 4 "c" 3 "b" 2 "a" 1))

(defn create-iterator
  (let [state (atom (seq coll))
        update-state (fn [state] (swap! state rest))]
    (fn []
      (let [item (first @state)]
        (update-state state)

(def my-iterator (create-iterator my-map))

;;=> #'junk.core/my-map
;;=> #'junk.core/create-iterator
;;=> #'junk.core/my-iterator
;;=> ["a" 1]
;;=> ["b" 2]
;;=> ["c" 3]
;;=> ["d" 4]
;;=> ["e" 5]
;;=> nil

Ivan Koz15:04:44

must be thread safe


Hi, does anyone have good solution to a fast reset-able timeout. I'm already using core.async, but I'm thinking about a classical problem of making a action foo depending on the last time action bar was called, but action bar could be called dozen or hundred times a second and so performance matters a bit.


are you saying you only want the reaction to be run once every x interval, even if the trigger is fired n number of times within the interval?


@lilactown think of it a bit like idle counter, last time there was an interaction then fire the action once (screen saver for example)


I'm thinking now of timeout in an atom and close! it every time there's an action (and replace it with a new timeout)


I can't tell if you're saying no, my interpretation is wrong, or yes, my interpretation is right


I think you're talking about debouncing


🙂 that could be


in which case there's this simple CLJS example:

🎉 4

there's probably a simpler way, without core.async


thanks, exactly what I need!


How can I "subclass" a lazy sequence to extend a custom protocol?


similar to defrecord for maps


ie. I don't want all clojure.lang.Sequential or such to support the protocol, but only a custom type which should still remain compatible with all library functions


you could perhaps extend a particular sequence to your custom protocols via metadata


Oh! I didn't know you could extend protocols using metadata, looks like a new thing in 1.10


@nxtk thanks, but I need to go both ways, forward and backward (it's essentially scrolling though a file list). it needs to be fast. i started with a sorted map, because I wanted to also have fast access by filename. i am now using a vector instead, which works, but does not have fast access by filename


There is although I haven't tried it. I would probably maintain both a vector and a hash map, if both types of access must be extremely fast and the list is largish. Another approach is to just use a vector in name order, and do a binary search within the vector when doing a name lookup.

Ivan Koz20:04:28

@UBRMX7MT7 just checked it, doesnt allow for previous\next node navigation


A vector seems like the best choice, if binary search is fast enough for you.


If you're using Clojure on the JVM you can use Java's binary search:

(java.util.Collections/binarySearch ["a" "b" "c"] "b")
=> 1


a combination of sorted-map with vector would probably work, I was just trying to use only sorted-map, but I guess I need something like LinkedHashMap


i'm trying to calculate a per-frame movement factor for a cursor i'm drawing For example I have

(defn next-pointer
  "Moves the pointer, taking to account speed"
  [{:keys [x y direction speed active] :as pointer} frame fps]
  (let [[dx dy] direction
        norm-time (mod frame fps)
        d-pixels (if (zero? norm-time)
    (assoc pointer
           :x (+ x (* dx d-pixels))
           :y (+ y (* dy d-pixels)))))
In this example, there's a speed of the format pixels/second. I want to determine at each frame by what factor I should increase x. My first approach was to determine the position of x at an origin, but due to adding to the x, it became more of an acceleration. In this case, I kind of lazily just get the next speed only when I'm at a "second" which is hardly smooth. The missing piece is the other part of that if. I've tried making norm-time (/ (rem frame fps) fps) to see if that would help, but it gives me kind of a stepping movement. I'm always bad at factoring time in my drawing apps, is there a missing link I'm not seeing


direction is simply a unit vector so it's either 0 1 or -1 for any element in the vector


I guess I need to keep track of dt


that seemd to be it, I just had to pass in dt, and keep it updated each frame

(defn next-pointer
  "Moves the pointer, taking to account speed"
  [{:keys [x y direction speed active] :as pointer} dt]
  (let [[dx dy] direction
        d-pixels (* speed dt)
        next-x (+ x (* dx d-pixels))
        next-y (+ y (* dy d-pixels))]
    (assoc pointer
           :x next-x
           :y next-y)))

Eric Ervin03:04:59

Thanks got posting this. I was dozing off in front of an Elixir tutorial when I saw this and it woke me up. Downloaded your experiments and went through them, getting acquainted with clojure2d. I'll certainly have to show 07_dedication.clj to a cat (actual feline) I know. It seems like some complexity with this speed thing can be removed. In my doodles, I typically express the speed in the number of pixels x/y it will change each frame. Then the distance it will travel each second is dependent on the frame rate, which is actually an effect I'd want as if I was changing the speed of a projector.

Eric Ervin03:04:55

Ya. I have speed and direction combined.


Haha, dedication is actually something I found in a tweet for pico8, I wanted to disect it and replicate it in clojure2d, to little success. Need to find the tweet to show it.


I try to translate as much to something "relatable" so I don't have to do guesswork or adding magic numbers to get movevement down. But most of it I'm trying to work my way into understanding without looking at formal graphics programming info.

Eric Ervin18:04:29

Sounds good. I might translate some of your experiments into Quil


feel free, many of them are unfinished, or simply ideas that I took to a point that I was satisfied with, but may not make much sense now. It's my sketchpad really.