This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-19
Channels
- # announcements (4)
- # aws (9)
- # babashka (1)
- # beginners (41)
- # cider (13)
- # clojure (45)
- # clojure-europe (16)
- # clojure-hungary (3)
- # clojure-norway (6)
- # clojure-uk (6)
- # clojurescript (14)
- # clr (3)
- # css (1)
- # datalevin (2)
- # datomic (2)
- # fulcro (8)
- # introduce-yourself (6)
- # jobs (3)
- # malli (2)
- # nbb (49)
- # off-topic (3)
- # reitit (23)
- # shadow-cljs (36)
- # tools-deps (2)
No, it's just a function name
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
(doc defrecord) for more detail
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.
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
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.
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.
Looks interesting, thanks for sharing!
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.
field-values=> (assoc (array-map) :a 1)
{:a 1}
field-values=> (type *1)
clojure.lang.PersistentArrayMap
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 languagesomething like
(println (filter (fn [data]
(println "----s--" (type data))
(when (= "Actual" (get data "sectionTitle"))
(assoc data "Date" (str "P-- " (get data "Date"))))) title)
)
right. Because filter doesn’t return the value of the function, it keeps or discards the original based on if the predicate is truthy
field-values=> (map inc [1 2 3])
(2 3 4)
field-values=> (filter inc [1 2 3])
(1 2 3)
intellij has a keystroke to evaluate a form and print it in the REPL (I don't know what it is)
@U11BV7MTK, I did not get you, does that mean it wont update the map?
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.
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
@U11BV7MTK Got it Thanks 🙂
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.)
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
Awesome, thank you very much
@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).
Yeah, that blog post comes up every time UTC is discussed for databases...
As that article says, there are some situations where you need additional information but for most situations, "UTC everywhere" is simple and workable.
We store member TZ as well as "everything in UTC", for example.