This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-01
Channels
- # announcements (2)
- # babashka (93)
- # beginners (57)
- # biff (3)
- # cider (7)
- # clerk (5)
- # clj-kondo (9)
- # clojure (26)
- # clojure-austin (1)
- # clojure-bay-area (5)
- # clojure-europe (13)
- # clojure-norway (88)
- # clojure-uk (7)
- # clojurescript (3)
- # cursive (4)
- # datahike (2)
- # datalevin (10)
- # datomic (1)
- # events (4)
- # hyperfiddle (5)
- # jobs (3)
- # lsp (1)
- # malli (4)
- # missionary (3)
- # nrepl (1)
- # off-topic (45)
- # overtone (4)
- # pedestal (4)
- # polylith (13)
- # reitit (15)
- # releases (2)
- # shadow-cljs (30)
- # squint (1)
- # vim (1)
- # xtdb (6)
Hello everyone, I'm currently exploring libgdx
with Clojure, and I've encountered a peculiar issue.
(let [batch (SpritBatch.)
atlas (TextureAtlas. (-> Gdx/files
(.internal "skin.atlas")))
logo (Texture. (-> Gdx/files
(.internal "logo.png")))
player (.findRegion atlas "player")]
(doto batch
(.setProjectionMatrix (.combined camera))
(.begin)
(.draw logo 0 0)
(.end)))
It's causing a bug: No matching method draw found taking 3 args for class com.badlogic.gdx.graphics.g2d.SpriteBatch.
The only correct way to call it is:
(.draw logo 0 0
300 300
400 600
0.5 0.5
90)
(.draw player 0 0
300 600
100 100
0.5 0.5)
Here's the Java documentation:
void draw (TextureRegion region, float x, float y)
void draw (TextureRegion region, float x, float y, float width, float height)
void draw (TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation)
void draw (TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, boolean clockwise)
void draw (TextureRegion region, float width, float height, Affine2 transform)
void draw (Texture texture, float [] spriteVertices, int offset, int count)
void draw (Texture texture, float x, float y)
void draw (Texture texture, float x, float y, float width, float height)
void draw (Texture texture, float x, float y, float width, float height, float u, float v, float u2, float v2)
void draw (Texture texture, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY)
void draw (Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY)
void draw (Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight)
Why isn't polymorphism working, what i missed?Looks like the fix could be this:
(.draw logo (float 0) (float 0))
the method that takes two arguments expects to see floats and getting longs instead. And you see exception like "No matching method" because there is no variant taking longs.Hello everyone, my code is working but I don't sure is it nice attempt or not. If needed can you advice me a better attempt please.
(def my-vector [[:customer/supplier] [:customer/client]])
(defn client-permisson-check [company-type-vec]
(if (= :customer/client (some #{:customer/client} (first (filter #(= (first %) :customer/client) company-type-vec))))
true
false
)
)
(client-permisson-check my-vector)
;=> true
No idea what this is for so that makes it a bit more difficult to improve this code (for example, must you have the my-vec format the way you are showing it here? A simple improvement would be to get rid of the if and the = functions and just return the result of some. If it is nil it is false, if it isn't nil it is true. This code could probably be simplified further if you would change the format of my-vec
I think that client-permission-check
could be shorter
(let [my-vector [[:customer/supplier] [:customer/client]]
client-permisson-check (fn [copmany-type-vec]
(boolean (some #{:customer/client} (mapcat identity my-vector))))]
(client-permisson-check my-vector))
but often people don't worry about casting things to booleans so you could just do something like
(defn client-permisson-check [copmany-type-vec]
(some #{:customer/client} (mapcat identity my-vector)))
? (which changes the return type, but would work the same if it was used in an if
for example)and what does the query return? ... is only the first thing in each vector a permission? or are all the elements of each vector in my-vector
permissions?
so (mapcat identity my-vector)
will flatten the list into [:customer/supplier :customer/client]
> (mapcat identity my-vector) > => (:customer/supplier :customer/client) sorry, yes ... it will be a seq rather than a vector
:customer/client
is a truthy value so if you use that in a conditional context, it will evaluate as true
I'm trying to terminate TCP connections with the following code and I'm not sure why it isn't working https://tildegit.org/michael/irc-bot/src/commit/44e6f7836fc1da85c2af86beb0e275b2259406b5/src/irc_bot/core.clj#L54-L60
user=> (doc doseq)
-------------------------
clojure.core/doseq
([seq-exprs & body])
Macro
Repeatedly executes body (presumably for side-effects) with
bindings and filtering as provided by "for". Does not retain
the head of the sequence. Returns nil.
nil
but look what doseq
returnsI am running into an error that I have never seen before with this code
(defn connect [server]
(let [socket (if (true? (:tls server))
(SSLSocket. (:name server) (:port server))
(Socket. (:name server) (:port server)))
in (BufferedReader. (InputStreamReader. (.getInputStream socket)))
out (PrintWriter. (.getOutputStream socket))
conn (atom {:in in :out out :socket socket})]
(doto (Thread. #(try (conn-handler conn)
(catch SocketException se
(println (str "Caught exception: " (.getMessage se))))))
(.start))
conn))
--------
Syntax error (IllegalArgumentException) compiling new at (src/irc_bot/core.clj:17:18).
No matching ctor found for class javax.net.ssl.SSLSocket
what are the values of (:name server) and (:port server)?
My guess is that that the arguments are unexpected types
(def servers [{:name "testnet.ergo.chat" :port 6667 :tls false}
{:name "irc.tilde.chat" :port 6697 :tls true}
{:name "irc.libera.chat" :port 6667 :tls false}])
The constructors for SSLSockets are protected.
OH? I don’t know any Java and this is my first programming language, does that mean I should use SSLSocketFactory isntead?
I'm not super familiar with SSLSockets. Here's a stackoverflow link, https://stackoverflow.com/a/6787029
One trick I use for java interop is to search on http://grep.app to see what's out there: https://grep.app/search?q=SSLSocket&filter[lang][0]=Clojure
👍 java interop is definitely an area that provides a lot of value to the Clojure ecosystem, but it does add to the amount of stuff it requires to get started.
(.createSocket (SSLSocketFactory/getDefault) (new Socket "irc.tilde.chat" 6667) "irc.tilde.chat" 6697 true)
If you look at the javadocs, it gives a reason: > This constructor can be used when tunneling SSL through a proxy or when negotiating the use of SSL over an existing socket. The host and port refer to the logical peer destination.
It seems like the host and port might differ when proxying.
Any critique is welcomed https://tildegit.org/fn/irc-bot/src/branch/main/src/irc_bot/core.clj
you can also try #C053PTJE6