Fork me on GitHub
#clojure
<
2019-05-22
>
todo06:05:32

[(let [x 20] '`~x) (let [x 20] `'~x) (let [x 20] `~x) ]

todo06:05:41

results in [x 20 20] ;; I am confused why the first two differ

ejelome07:05:10

the first one is a literal, and is not evaluated; that's what the single quote is for --- it's like saying (quote `~x)

ejelome07:05:32

man ... cant escape this backtick

😂 4
💯 4
todo09:05:46

Can you walk me step by step through how (quote (quasiquote (unquote x)) and (quasiquote (quote (unquote x)) eval to different things ?

borkdude11:05:20

has anyone done any benchmarking on moving from regular maps to defrecords? I know they’re theoretically faster, but I’d like to have some numbers and performance characteristics

Alex Miller (Clojure team)12:05:49

They’re not necessarily faster. They are faster in certain ways, so it really depends on your use case.

Alex Miller (Clojure team)12:05:10

For instance, records don’t do structural sharing. Depending on your mutation pattern, this could mean using a lot more memory and affecting gc. It’s hard to test that in a micro benchmark.

Alex Miller (Clojure team)12:05:57

Construction and access is usually faster. Mutation creates a new object, which may be slower, I really don’t know. Probably depends on number of fields.

Alex Miller (Clojure team)12:05:33

Well, access of known fields is probably faster. Access of extra fields is probably slower (since it’s really map access plus a field lookup).

Alex Miller (Clojure team)12:05:31

If you really want to know how it affects your particular app, you probably just have to try it.

borkdude12:05:27

yeah, but that takes a lot of work, since you have to refactor all the places where you access the known keys, so I wondered if there’s already some research done on this. until I know more, I’ll probably won’t change anything

mpenet12:05:38

I guess using (map->Foo ...) can be an anti-pattern too if you're micro-optimizing

Alex Miller (Clojure team)12:05:55

well like I said, it's entirely dependent on what you're doing, so there can't be any research that applies to /your app/

borkdude12:05:16

I know, but there can be research that describes certain scenarios and heuristics. if the win is only a few nano-seconds I won’t bother

Alex Miller (Clojure team)12:05:36

well, that doesn't exist

Alex Miller (Clojure team)12:05:50

I've microbenchmarked various things in the past, but that doesn't tell you gc effects etc

borkdude13:05:12

for example rewrite-clj has a lot of defrecords, but when you replace the children of a node, it creates an entirely new object. that hadn’t occurred to me. so the benefit isn’t clear at all here

pyr15:05:55

While running lein release from Jenkins the vcs push part does not work, git considers the repo to be in a detached HEAD state

pyr15:05:57

I think I got it

prnc16:05:23

@todo my understanding is 1. tilde is a syntax-unquote, backtick is a syntax-quote, apostrophe is short for quote special form 2. first check for `~ those cancel each other out (syntax- quote/unquote) 3. ` stops evaluation and namespaces 4. ' stops evaluation

markx16:05:15

When I connect to a closed socket, it throws a connection exception, but with a syntax error. Why does this happen?

Syntax error (ConnectException) compiling at (/private/var/folders/_m/m545vvvx28j2x50v81pjs3bh00l3wz/T/form-init4854649086981149918.clj:1:125).
Connection refused (Connection refused)

noisesmith17:05:45

anything that happens while loading forms (top level of source, top level of repl) will often be reported as a syntax error

noisesmith17:05:25

eg. (def foo (/ 1 0)) is a syntax error because the divide by zero happens while compiling foo

noisesmith17:05:56

user=> (def foo (/ 1 0))
Syntax error (ArithmeticException) compiling at (REPL:1:10).
Divide by zero

noisesmith17:05:47

form-int*.clj usually means lein was doing something at the top level of a namespace, you probably shouldn't be doing anything with sockets inside def or the top level of a namespace

fabrao18:05:09

Hello all, I´m trying to use clj-time to print local time, but it always get UTC time, I tried use (f/unparse (f/formatter "yyyyMMddHHmmss") (l/local-now)) and (f/unparse (f/formatter "yyyyMMddHHmmss") (t/now))but no success. How does it work?

Alan Thompson18:05:54

Use the new cljc.java-time from Clojure/North: https://youtu.be/UFuL-ZDoB2U

Alan Thompson18:05:29

Can also do (zdt/now (ZoneId/of "US/Hawaii"))

seancorfield19:05:27

Or clojure.java-time that has existed for quite some time

(! 504)-> clj -Sdeps '{:deps {clojure.java-time {:mvn/version "RELEASE"}}}'
Clojure 1.10.0
user=> (require '[java-time :as jt])
nil
user=> (jt/zoned-date-time)
#object[java.time.ZonedDateTime 0x6d67f5eb "2019-05-22T12:14:41.190-07:00[America/Los_Angeles]"]
user=> (str *1)
"2019-05-22T12:14:41.190-07:00[America/Los_Angeles]"
user=> 

seancorfield19:05:36

Either way, I'd highly recommend using a Java Time based solution, like either of those or just raw Java Time with interop, instead of clj-time (and I'm one of the clj-time maintainers -- that library, and Joda Time, has been superseded by Java Time).

👍 4
fabrao19:05:21

I tried this (.toString (org.joda.time.DateTime/now) "yyyyMMddHHmmss") and works, it´s better using java-time?

ghadi19:05:43

Yeah Joda is deprecated

ghadi19:05:53

If you have the flexibility/choice, switch

ghadi19:05:07

If it ain't broke, don't break it :)

seancorfield20:05:34

And just to be clear @fabrao you don't need a Clojure library at all for this:

user=> (java.time.ZonedDateTime/now)
#object[java.time.ZonedDateTime 0x2a448449 "2019-05-22T13:23:03.927-07:00[America/Los_Angeles]"]
user=> (str *1)
"2019-05-22T13:23:03.927-07:00[America/Los_Angeles]"
user=> 

fabrao20:05:10

@seancorfield Thanks for information

seancorfield20:05:18

That's baked into Java from Java 8 onward. Which is a big part of why Joda Time is considered deprecated -- Java Time was the "next gen" of Joda Time, designed by the same folks.

seancorfield20:05:03

And here's the formatting in full, if you need it:

user=> (.format (java.time.ZonedDateTime/now) (java.time.format.DateTimeFormatter/ofPattern "yyyyMMddHHmmss"))
"20190522132639"
user=> 

seancorfield20:05:39

(and you can use :import to clean that up, rather than typing out the package names each time)

ghadi20:05:58

the name clojure.java-time for a library is admittedly confusing and misleading

seancorfield20:05:26

Yeah, and the use of a single-segment namespace java-time is awful too.

ghadi20:05:26

but like @seancorfield says, everything you need is already at hand

ghadi20:05:35

oof, really?

ghadi20:05:52

what's with all these clojure projects that do that?

ghadi20:05:25

Did you know the Java Module System will reject module jars with single segment names?

seancorfield20:05:08

I suspect it's "pushback" against the everything.core convention that Leiningen accidentally gave us all those years ago? 🙂

ghadi20:05:13

clj-tuple is an offender I've found

Noah Bogart20:05:35

what's a "single-segment namespace"?

ghadi20:05:51

meh I don't know what it comes from, the namespacing advice/suggestion has been there for 10 years

ghadi20:05:02

@nbtheduke when you have a namespace named foo

ghadi20:05:08

rather than noah.foo

seancorfield20:05:30

date-clj is another one you can hate on 🙂

ghadi20:05:57

you don't have to go "full Java" by doing com.noah.whatever.foo but namespacing is there for a reason

seancorfield20:05:17

And date-clj's coord is date-clj/date-clj 🙂

ghadi20:05:17

lots of projects have config as a namespace, yuuuck

👍 4
Alex Miller (Clojure team)20:05:36

what could possibly go wrong

ghadi20:05:37

you can't mix that with another project with the same defect

ghadi20:05:47

yeah no biggie

ghadi20:05:58

(personal opinion: lots of projects that do this aren't worth using for other reasons.)

👍 4
ghadi20:05:55

but to do clojure.java-time is especially bad because it implies endorsement of sorts

ghadi20:05:12

same with clojure.jdbc or whatever that one is called

seancorfield20:05:15

Yeah, don't get me started on that one...

seancorfield20:05:11

But it's not really surprising people put clojure or clj or cljc or cljs into namespaces and/or artifact names given that they have a single concept in mind and it's for Clojure 🙂

seancorfield20:05:14

I called next.jdbc that because it's the "next generation" of org.clojure/java.jdbc / clojure.java.jdbc but I didn't want to imply "authority" via clojure unless it ends up in Contrib and that's looking less and less likely at this point (I have CircleCI and cljdoc in place so most of the benefits of Contrib are accounted for).

Alan Thompson22:05:45

I agree that thin wrappers have limited value, but you may wish to check out the video for cljc.java-time. It is a cross-platform clj/cljs implementation that avoids the js/Date problems. The clj part is auto-generated wrappers of java.time, so that is simple & convenient. The cljs part is a re-implementation of most java.time classes, and does not use js/Date at all. See Clojure/North video for details: https://youtu.be/UFuL-ZDoB2U

akjetma22:05:55

hey, does the clj repl support tab completion for namespace members? i know the lein repl does, but it doesnt seem to work when i use clj -r

noisesmith22:05:32

no, the clj tab completion is very rudimentary

akjetma22:05:47

lol hey justin. damn, okay

akjetma22:05:16

chillin 😎

dpsutton22:05:32

you can check out rebel-readline for a minimal terminal style thing https://github.com/bhauman/rebel-readline

❤️ 8
👍 8
pizzaspin 8
🙌 4
akjetma22:05:48

ahh cool, tyty