Fork me on GitHub
#beginners
<
2022-07-19
>
quan xing10:07:50

What's means about (map->Interceptor t) , is map->Interceptor a fixed notation?

Alex Miller (Clojure team)11:07:17

No, it's just a function name

Alex Miller (Clojure team)11:07:57

It is a little special in that defrecord creates two constructor functions with well known names, map->TheRecord (takes a map, returns an instance of the record), and ->TheRecord which take record fields positionally and returns an instance of the record

Alex Miller (Clojure team)11:07:25

(doc defrecord) for more detail

quan xing11:07:16

sorry. I got it. I didn't notice that It is a defrecord. It's a function factory. I forgot how to use it. Thanks.

quan xing11:07:43

This code is from pedestal. I want to know how it works. But I I found my skills a little lame. I might be used to reading Java code, but when I read Clojure code, the full contents of a function's parameters are unknown and I have to work my way from the top to the bottom, which is a bit of a struggle to understand

simongray07:07:08

Don't worry about it. That particular part of Clojure isn't very discoverable. I think everyone is confused when they first run into it. It's a bit of an oddity.

quan xing10:07:53

Ok. I need to be patient to learn. Thanks.

raghu16:07:52

I found this book Poetry of Programming https://egri-nagy.github.io/popbook/. It's aimed towards "non-programmers, in particular for Liberal Arts students with some college/high school algebra background," As a novice programmer I found this more gentle than other resources that are commonly listed here. I will continue with the Brave Clojure after completing this.

👍 4
🎉 1
1
Bart Kleijngeld16:07:42

Looks interesting, thanks for sharing!

respatialized18:07:13

How to Design Programs is written from a similar perspective, aiming to be an intro CS text that imagines programming as part of a liberal arts college curriculum: https://htdp.org/2022-6-7/Book/index.html You may find it useful as well.

❤️ 1
popeye18:07:16

How to do assoc in variable of type clojure.lang.PersistentArrayMap ?

dpsutton18:07:46

field-values=> (assoc (array-map) :a 1)
{:a 1}
field-values=> (type *1)
clojure.lang.PersistentArrayMap

ghadi18:07:24

best not to rely on concrete types

dpsutton18:07:50

field-values=> (type {:key :value})
clojure.lang.PersistentArrayMap
field-values=> (assoc {:key :value} :extra :info)
{:key :value, :extra :info}
you’ve been using them this whole time. That’s the beautify of the language

popeye18:07:14

I am trying it with filter , which is not happening

dpsutton18:07:06

can you show what you are trying?

popeye18:07:43

something like

(println (filter (fn [data]
                   (println "----s--" (type data))
                   (when (= "Actual" (get data "sectionTitle"))
                     (assoc data "Date" (str "P-- " (get data "Date"))))) title)
         )

popeye18:07:01

but it is not updating Date key

dpsutton18:07:31

right. Because filter doesn’t return the value of the function, it keeps or discards the original based on if the predicate is truthy

dpsutton18:07:51

field-values=> (map inc [1 2 3])
(2 3 4)
field-values=> (filter inc [1 2 3])
(1 2 3)

ghadi18:07:52

there should be no need to wrap your forms in println

ghadi18:07:01

just type into your repl

ghadi18:07:08

it will print the answers automatically

popeye18:07:17

i am trying in intellj

ghadi18:07:43

intellij has a keystroke to evaluate a form and print it in the REPL (I don't know what it is)

dpsutton18:07:03

there’s also a repl input window so you can just type there at the very least

popeye18:07:49

@U11BV7MTK, I did not get you, does that mean it wont update the map?

dpsutton18:07:21

field-values=> (doc filter)
-------------------------
clojure.core/filter
([pred] [pred coll])
  Returns a lazy sequence of the items in coll for which
  (pred item) returns logical true. pred must be free of side-effects.
  Returns a transducer when no collection is provided.

dpsutton19:07:03

it returns the items in the coll for which (pred item) returns logical true. It doesn’t return arbitrary stuff. Its just a way of selecting items from a collection

popeye19:07:24

@U11BV7MTK Got it Thanks 🙂

Chris G19:07:29

if im understanding correctly assoc will do what your asking

Chris G19:07:38

cljs.user=> (assoc {} :a {:something "else"})
{:a {:something "else"}}

michaelteter18:07:11

Hi folks. Can someone direct me to a good starting place for learning about modern string timestamp conversion? I need to convert strings like "2022-07-11T10:42:30.707+02:00" and "2022-07-11T08:43:28.6901659Z" to timestamps which postgresql jdbc will accept for timestampz or timestamp with time zone columns. I'm not actually sure which I should be using, but anything that works is a start at this point 🙂. (I'm consuming an API which unfortunately has a mix of timestamp representations, but the time part is not especially critical to my needs anyway.)

souenzzo19:07:40

As a first step, you can use one of these parsers (java.time.ZonedDateTime/parse "2022-07-11T08:43:28.6901659Z") (java.time.Instant/parse "2022-07-11T08:43:28.6901659Z") (clojure.instant/read-instant-date "2022-07-11T08:43:28.6901659Z") It will give to you an ZonedDateTime, an Instant or an java.util.Date Once you have these date objects, you can take a look at https://cljdoc.org/d/seancorfield/next.jdbc/1.2.659/doc/getting-started/tips-tricks#working-with-date-and-time

michaelteter19:07:23

Awesome, thank you very much

seancorfield19:07:30

@U9RGZJC4C That section of the docs has recently been updated on GH (but not yet published) to provide advice from a PostgreSQL user who says to avoid the timezone column stuff in PG and use plain timestamp and try to do everything in UTC and only convert TZs at the edges (on input and for display).

👌 1
seancorfield04:07:31

Yeah, that blog post comes up every time UTC is discussed for databases...

seancorfield04:07:09

As that article says, there are some situations where you need additional information but for most situations, "UTC everywhere" is simple and workable.

seancorfield04:07:45

We store member TZ as well as "everything in UTC", for example.