This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-14
Channels
- # announcements (11)
- # babashka (82)
- # beginners (51)
- # calva (11)
- # cider (3)
- # clj-kondo (62)
- # cljdoc (10)
- # cljs-dev (22)
- # clojure (75)
- # clojure-boston (1)
- # clojure-brasil (3)
- # clojure-czech (4)
- # clojure-europe (49)
- # clojure-france (10)
- # clojure-italy (16)
- # clojure-nl (5)
- # clojure-uk (9)
- # clojurescript (69)
- # community-development (33)
- # conjure (12)
- # core-async (6)
- # cursive (2)
- # datalevin (7)
- # datomic (6)
- # graalvm (13)
- # gratitude (2)
- # honeysql (3)
- # introduce-yourself (1)
- # lsp (37)
- # nextjournal (62)
- # off-topic (29)
- # pathom (1)
- # quil (2)
- # reitit (4)
- # releases (2)
- # sci (1)
- # shadow-cljs (28)
- # spacemacs (10)
- # sql (1)
- # tools-build (3)
- # vim (3)
https://github.com/troy-west/cronut if you use integrant
You may also want to consider https://github.com/crinklywrappr/gooff
depending on your requirements Quartz (and perhaps the wrapper lib quartzite) might be the thing
chime is cool
and uses Java threaded worker pool thingy
I write a convert date to string function, but It's result is error . why?
(defn date-str
[date-time]
(case (class date-time)
; if date-time is LocalDateTime
java.time.LocalDateTime (.format
(java.time.format.DateTimeFormatter/ofPattern "yyyy-MM-dd HH:mm:ss")
date-time)
; if date-time is Date
java.util.Date (.format
(java.text.SimpleDateFormat. "yyyy-MM-dd HH:mm:ss")
date-time)
(throw (IllegalArgumentException. "error type"))
)
)
(= java.time.LocalDateTime (class (java.time.LocalDateTime/now)))
;; => true
(date-str (java.time.LocalDateTime/now))
;; => Execution error (IllegalArgumentException) at runtask.core/date-str (REPL:62).
;; error type
You can only use case
with compile-time literals. Java classes are not compile-time literals.
I would avoid using java.util.Date
at all if possible. If not, I would maybe look into converting java.util.Date
into a LocalDateTime
so that you can always just use DateTimeFormatter
to format the date.
If that's not an option for some reason, you might want to look into protocols (https://clojure.org/reference/protocols). That's what you'd generally use when you need to dispatch on the type of a thing.
Just to illustrate how case
works:
(let [x 'java.time.LocalDateTime]
(case x
java.time.LocalDateTime "I'm a LocalDateTime"
"I'm nothing."))
;;=> "I'm a LocalDateTime"
That is, since case does not evaluate java.time.LocalDateTime
, you're checking whether the value x
is equivalent to the Clojure symbol java.time.LocalDateTime
, not the java.lang.Class
instance java.time.LocalDateTime
.I remember Rich mentioning that files implement seq? Maybe I misunderstood what he meant
found core.file-seq(seq (io/file "."))
like this is an err
Can I extend ReadableColumn
protocol for postgres bytea column in next.jdbc? I did try to extend the type java.sql.Blob
similar to the Clob as mentioned in the sample doc, but it has no effect at all, the binary field in the returned resultset is just binary byte array :thinking_face:
hi everyone, I wanted to ask if anyone here learned programming using Clojure ? If so, any advice for someone trying to get into codding, and also learning Clojure at the same time ?
There have been a few people attend ClojureBridge London events that helped start there career in software development, usually with little or no background in coding. Some went on to get Clojure roles, some continued Clojure as a side interest. My advice is to spend a part of your time understanding how you best learn something. What are the effective ways of retaining the things you are learning? There are many tools to help you learn Clojure (http://Exercism.org, http://Practical.li and many https://clojure.org/community/resources), so its a question of which help the most. There is more to learn than any one person can learn in a lifetime, so set small and obtainable goals. Identify some overall objectives you want to achieve (get a job doing x, or building a project to do x) and figure out things that get you closer to that. I dont beat yourself up if you get stuck or confused or projects fail. That's just part of life. If you get stuck, step away from the code and have a think. If you are still stuck, form a meaningful question and post it to the community (forming the question often helps answer your own question)
I suggest asking @UMA337M3P, though she isn’t always on Slack
depends on your background, it is certainly possible, resources are abundant and the community is welcoming
you have the upside of less preconceived ideas, languges like python or java or javascript may seem easier, but all languages are equally complicated in the end
I have to say I personally "fell into a ditch" last year when trying to learn clojure, and are now coming back to it after learning some of the other functional style languages, like F#
I'm also a self-learner so it's useful to learn languages like Tarzan, grasping concepts one at a time, climbing ever higher
each language provides easier way to some domain, and makes others harder
"forming the question often helps answer your own question" Universal step 1 for learning to code in any language: Buy a rubber duck or print a picture of one so you can talk to it.

Trying to figure out how to require/import an external/local jar file, have added the following to my deps.edn file
:deps {org.clojure/clojure {:mvn/version "1.10.1"}
Plot/Plot {:local/root "/path_to_clojure_project/test/plot.jar"}}
Have tried the following in my .clj file
(ns hello.test
(:require [Plot/Plot :as Plot])
(:import Plot)) ;; clojure.lang.ExceptionInfo: "Call to clojure.core/ns did not conform to spec."
(Plot.)
simple java class at this point,
(:import Plot.Plot) ;; works
(Plot.) ;; gives ClassNotFoundException
Not sure I have the class path setup properly.so the package is Plot, with an upper case?
I have no idea what that means, I don't use your ide
Yeah sorry just trying to give you an idea of how the java in the jar file is structured. So yes java eclipse IDE.
what happens in a repl if you try (Plot.Plot.)
?
also, require is not appropriate here as there's no clojure ns to find and load
@U65G9MPCK for future reference, using normal conventions helps us understand what's going on / what's being attempted. Usually the package name isn't capitalized - only classes or things that are backed very straightforwardly by a class like records.
Doing
(:import [Plot Plot])
seems to work as if the constructor is being called. Now getting an internal error.the import will invoke any static code on the class
for future reference, require
tells the clojure compiler to find and load clojure code (which usually incidentally loads and/or defines classes), import
tells Clojure that a class should be available by a shorter name in the current ns, import
does not see aliases or mappings created by require, those exist in the world of clojure's compiler and its namespaces, which is parallel to and invisible to the world of classes
I mean you can write a class to look at namespaces and such, but that's not what you'll see outside clojure code
right - it's only needed if you need clojure to compile clojure code
what I mean about import being sugar:
org.noisesmith.mp3=> (import ( ByteArrayInputStream))
java.io.ByteArrayInputStream
org.noisesmith.mp3=> (= ByteArrayInputStream java.io.ByteArrayInputStream)
true
OK so I managed to get something working with the following:
(:import [package_name ClassName])
(ClassName.) ;; instantiate ClassName in package_name
(.class_method (ClassName.)) ;; call class method
@U051SS2EU thanks for the help, was obviously confused about some aspects of require/import/useimport doesn't use scope introduced by require
(:import Plot)
only makes sense if Plot is a top level Class with no package, which is something you shouldn't be using
Hello! Is it possible to have a default value for a nested destructuring? For example, given
(def req {:params {:page 1})
Then I want a default value to limit which is not present in :params
(let [
{test :test,
{page :page, limit :limit} :params,
:or {page 1 limit 8}} req]
(println limit))
But it prints nil
The default value for limit doesn't work.You need to nest the or:
(let [{test :test,
{page :page, limit :limit
:or {page 1 limit 8}} :params} req]
(println limit))
Thank you!