Fork me on GitHub
#beginners
<
2022-03-21
>
aratare01:03:34

Hi there. I have a silly question: can you rebind a destructured key from a map? For example, if I have a small piece of code like this

(fn [{:user/keys [username password] :as user}] ...)
Is there currently any way to rebind username to something else, say, like user-name? Of course a common way would be to use something like
(fn [{user-name :user/username}] ...)
I'm just curious if there's another way to work with keys instead. Thanks in advance 🙂

dpsutton01:03:22

:keys destructuring is a shorthand. (let [{foo :some-key} {:some-key 3}] foo)

dpsutton01:03:07

user=> (let [{:user/keys [password] user-name :user/username} {:user/password "pass"
                                                               :user/username "user"}]
         [password user-name])
["pass" "user"]
user=> 

aratare02:03:01

I see. So it's not possible with keys then. Thanks a lot 😄

Baye08:03:44

Hi I m relatively new to programming (learnt basics of programming but no production experience) . Any suggestion for a good clojure book for beginners like me? Is there a good structure course for beginners, paid or otherwise? I am asking because all the resources I have seen so far are aimed at experience d programmers (those proficient in at least one programming language).

V08:03:34

Clojure for the brave and true is free -https://www.braveclojure.com/clojure-for-the-brave-and-true/ I started with the video courses of http://purelyfunctional.tv - > courses has since been moved to https://ericnormand.me/.

Baye08:03:06

Thank you.

clj.max08:03:37

I recommend just flooding yourself with Clojure material a little. Read Brave & True, it's great. Watch random videos that sound interesting, like Eric's mentioned above. Don't worry about remembering everything, you'll get the hang of things. Make little scripts or games or other stuff that sounds interesting. Then return to the books and videos.

flowthing08:03:16

I haven't read it myself, but I've heard many recommendations for Getting Clojure.

V08:03:43

Also another recommendation for after you know the syntax of clojure- FredOverflows videos on Advent of code 2020 really helped me in solving problems in clojure - https://youtu.be/Vp8RbO7l6eg - They get harder very quickly, but try to solve them first yourself and then see how fred does. His explainations are very good,

dgb2309:03:40

https://www.maria.cloud/ check this out! its playful and well made

Baye10:03:01

Thank you for the suggestions. Hope this one is also not too advanced to go through https://pragprog.com/titles/dswdcloj3/web-development-with-clojure-third-edition/

Baye10:03:01

as building a tutoring type app is one of my medium term goal

dgb2311:03:24

this is a friendly/good book but there is a gap between “programming basics” and “full-stack web development”. On the other hand there is no shame in just trying for a while and then continuing after filling in some gaps. That has been my approach with some books and topics too.

☝️ 1
Baye12:03:20

I see. Then I will go through the fundamentals with True and Brave (or Getting Clojure, Programming Clojure), then do Koans (or exercism), and then the web dev book. Let me know if you think this is reasonable. Thanks

pavlosmelissinos13:03:45

Clojure for the Brave and True assumes you're working in emacs. If you prefer a different editor/IDE, keep using that, ignore the emacs parts of the book and focus on learning Clojure. If you haven't decided on an editor/IDE, I think VSCode w/ Calva is the most beginner-friendly nowadays. > Let me know if you think this is reasonable. Sounds good to me!

👍 2
Baye06:03:10

Thank! Btw, I am using Cursive.

👍 1
seminioni19:03:48

The Clojure Workshop. Surprised that no one didn’t mention it

clj.max20:03:51

About what @U01EFUL1A8M said: there's definitely both "programming itself" vs. "using all the frameworks that people use e.g. for web development" and in my experience you need both. So nothing wrong with learning both at the same time, as long as you realize they're different but related topics 🙂 When I was doing Ruby on Rails, tons of people only knew Rails (the web framework) but barely any Ruby (the language). Avoid that 😉

Roee Mazor09:03:32

Hi hi, What should be my goto solution when needing to compress and uncompress some json / map?

Ferdinand Beyer09:03:31

Not sure if there is a “pretty” clojure lib out there (I guess there is). I would start looking into what the Java standard library offers, namely GZIPInputStream / GZIPOutputStream: https://docs.oracle.com/javase/7/docs/api/java/util/zip/GZIPOutputStream.html

Roee Mazor09:03:29

yeah, I saw this example: https://gist.github.com/rcampbell/966238 was afraid thats the best solution 🙂

Roee Mazor09:03:02

Ill try that lib, thx!

Ferdinand Beyer09:03:41

> was afraid thats the best solution Don’t be afraid of some Java interop 🙂

Roee Mazor13:03:34

haha, maybe after this I won’t 🙂 thanks a lot!

👍 1
Ben Sless14:03:07

Interop with gzip input stream isn't terrible. All serialization libraries can probably handle input streams so you just need to wrap the zipped stream with a gzipinputstream and pass it along to the deserializer. If this is in a web server, best do it in a middleware

Danilo Oliveira14:03:04

What is the most "clojuronic" way of handling errors on user inputs/actions? java.lang.RuntimeException? I did some research and did not found too much stuff about monadic errors (like Scala/Rust) and usage of tuples (Like Go). Should I just throw errors in such cases?

Ferdinand Beyer14:03:58

I think exceptions are actually most common. Clojure does not tend to define its own types thow, but you will often see (ex-info) exceptions to be thrown, carrying data in a map. There are libraries to all kinds of styles out there, e.g. failjure, exposing a monadic style

agile_geek09:03:43

In my current client we have gone back and forth on exceptions vs more monadic error handling several times. We've found trying to handle monadic error values to be 'swimming upstream' and are now refactoring to remove these various experiments in favour of throwing exceptions. Using anything else just rubs up against friction with other libraries in the Clojure space or imposes an excessive overhead in having to cope with error values all the way up the function stack on return.

Cora (she/her)14:03:02

I've definitely used tuples

Cora (she/her)14:03:33

but what to use probably depends on the interface and what I want to display to the user

Kevin17:03:41

Is there a (easy) way to convert Bigints to hex string? This doesn't work:

(format "%x" 1N)
java.util.IllegalFormatConversionException: x != clojure.lang.BigInt [at <repl>:10:1]

(format "%x" 0xffffffff92492493)
java.util.IllegalFormatConversionException: x != clojure.lang.BigInt [at <repl>:10:1]

hiredman17:03:25

user=> (.toString (biginteger Integer/MAX_VALUE) 16)
"7fffffff"
user=>

👍 1