Fork me on GitHub
#beginners
<
2022-02-14
>
Mno00:02:18

If no one answers here maybe you can try in #calva?

quan xing03:02:06

Is there a Clojure Library that provides scheduled tasks?

emccue20:02:03

depending on your requirements Quartz (and perhaps the wrapper lib quartzite) might be the thing

sova-soars-the-sora15:02:58

and uses Java threaded worker pool thingy

quan xing10:02:10

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

flowthing11:02:15

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.

flowthing11:02:49

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.

quan xing12:02:13

ok. thank you very much

Benjamin10:02:54

I remember Rich mentioning that files implement seq? Maybe I misunderstood what he meant (seq (io/file ".")) like this is an err found core.file-seq

Godwin Ko15:02:50

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:

victor ruotolo16:02:22

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 ?

practicalli-johnny17:02:46

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)

💯 4
quoll17:02:35

I suggest asking @UMA337M3P, though she isn’t always on Slack

Matej Šarlija19:02:28

depends on your background, it is certainly possible, resources are abundant and the community is welcoming

Matej Šarlija19:02:19

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

Matej Šarlija19:02:24

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#

Matej Šarlija19:02:04

I'm also a self-learner so it's useful to learn languages like Tarzan, grasping concepts one at a time, climbing ever higher

Matej Šarlija19:02:22

each language provides easier way to some domain, and makes others harder

lambduhhh19:02:31

responded to @U01FK0L87DJ via PM

👍 1
Eric20:02:37

"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.

duckie 1
victor ruotolo22:02:46

Thanks for the answers everyone 🙂

1
bschup20:02:04

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.)

JohnJ20:02:23

is the plot jar clojure or java?

bschup20:02:11

simple java class at this point,

(:import Plot.Plot) ;; works
(Plot.) ;; gives ClassNotFoundException
Not sure I have the class path setup properly.

noisesmith20:02:38

so the package is Plot, with an upper case?

noisesmith20:02:12

I have no idea what that means, I don't use your ide

bschup20:02:13

Yeah sorry just trying to give you an idea of how the java in the jar file is structured. So yes java eclipse IDE.

noisesmith20:02:49

what happens in a repl if you try (Plot.Plot.) ?

JohnJ20:02:00

dish the require and do (:import Plot Plot)

noisesmith20:02:03

also, require is not appropriate here as there's no clojure ns to find and load

noisesmith20:02:40

@U01KZDMJ411 I think you mean (:import Plot.Plot) or (:import [Plot Plot])

👌 1
JohnJ20:02:36

yes, correct

noisesmith20:02:33

@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.

👍 1
bschup20:02:57

Doing

(:import [Plot Plot])
seems to work as if the constructor is being called. Now getting an internal error.

noisesmith20:02:18

the import will invoke any static code on the class

noisesmith20:02:12

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

noisesmith20:02:19

I mean you can write a class to look at namespaces and such, but that's not what you'll see outside clojure code

bschup20:02:46

OK, sounds like require is not needed in this case.

noisesmith20:02:38

right - it's only needed if you need clojure to compile clojure code

noisesmith20:02:24

what I mean about import being sugar:

org.noisesmith.mp3=> (import ( ByteArrayInputStream))
java.io.ByteArrayInputStream
org.noisesmith.mp3=> (= ByteArrayInputStream java.io.ByteArrayInputStream)
true

bschup21:02:37

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/use

noisesmith20:02:27

import doesn't use scope introduced by require

noisesmith20:02:00

(:import Plot) only makes sense if Plot is a top level Class with no package, which is something you shouldn't be using

Sergio Sinuco21:02:58

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.

Lennart Buit21:02:19

You need to nest the or:

(let [{test :test,
       {page :page, limit :limit
        :or {page 1 limit 8}} :params} req]
  (println limit))

1