Fork me on GitHub
#beginners
<
2020-12-31
>
baibhavbista03:12:23

Hello everyone, I had a question about progressing beyond just the fundamentals I am currently going through the Getting Clojure book and doing 4clojure problems (halfway through the book, 50 questions in 4clojure) and think i have a good base What would you guys suggest I do next, to really sink my teeth into Clojure? (alongside completing the book and semi-regularly doing 4clojure problems)

πŸ‘€ 6
Sam Stowers03:12:10

I'm also interested in thoughts here - just finished Clojure for the Brave and True. My current plan is to build some projects to act as a capstone. Would be fun to build & document things that take 1 hour, 1 day, 1 week, and 1 month respectively

πŸ‘ 3
Christian10:12:41

I read the first two chapters of "Programming Clojure (3rd edition)" by Alex Miller and Stuart Halloway and Aaron Bedra. And then startet on the advent of code problems. It's going well and I learned a lot about clojure. Loops, recurs, maps, regex are all helpful

πŸ™ 3
nnichols13:12:52

I usually recommend building a small app that you have done in another language just to compare and contrast, plus it's a good way to start getting familiar with the broader ecosystem + frameworks

πŸ™ 3
baibhavbista03:12:35

I would like book recommendations to go through after getting clojure. However, I have a tendency of procrastinating on actually doing something, so, more practical things would be appreciated as well

seancorfield04:12:05

@baibhavbista Perhaps look at The Clojure Cookbook and build things using the code "recipes" there. Maybe read Clojure Applied for practical, real world design advice?

baibhavbista05:12:13

these look great! thanks!!

seancorfield04:12:58

(I'll be interested to hear what others recommend -- I think there's a quite a big gap in the "market" insofar as intermediate learning resources are concerned)

seancorfield04:12:12

Oh, and if you don't mind paying for a monthly subscription ($49/month): http://PurelyFunctional.tv has some great courses. And if you're interested in ClojureScript, @jacek.schae has some great courses on his site...

πŸ™ 3
πŸ‘ 3
FHE04:12:03

@euccastro @seancorfield Today was early New Year busy-ness, but I will definitely try both of your examples, right after I figure out how to install the Clojure CLI tools (do .net installation or figure out WSL). Will update here when I do.

seancorfield04:12:06

Cool. Where are you based then @factorhengineering?

seancorfield04:12:40

(and, re: your choices, I strongly recommend figuring out WSL -- even if you figure out the .NET / Powershell stuff and get the CLI running on Windows, you'll continue to run into weird issues with libraries and problems with tooling that doesn't quite support Windows... WSL2 will help you avoid all of that!)

seancorfield05:12:24

Are you associated with https://factor-h.org/our-team ? I see your posts show up in Zulip as @factorhengineering and your TZ would match Venezuela, Western Brazil, Bolivia, Paraguay, or Chile...

seancorfield05:12:14

(telling me that it is none of my business is an acceptable answer πŸ™‚ )

FHE14:12:57

Pretty good investigative work. Ha ha. I'm not in South America though. in very eastern Canada. I also haven't heard of the company you mentioned.

FHE14:12:02

Are you somewhere in the western US, based on how late (from my perspective) you've been on here?

seancorfield17:12:41

Bay Area, California, but originally from the UK. I tend to forget that Canada extends east by two more timezones than the US!

FHE01:01:34

I just reacquainted myself with the time zones around the world because of having kids too young to make it to midnight. ("If we celebrate at <time x> we'll be celebrating along with <country y> and <country z>")

seancorfield01:01:04

We rarely make it to midnight ourselves these days -- not because of kids (we don't have any) but because we're OLD πŸ™‚

FHE14:01:01

We're here now. Happy New Year.

FHE04:12:27

...and happy Old Year, all. It's the 31st here now.

baibhavbista05:12:01

@factorhengineering Some time ago, I made a Clojure Calva WSL2 intro targeted at clojure beginners. It uses Leiningen, not clojure CLI, but it could still help: https://www.notion.so/baibhavbista/Beginner-Clojure-Environment-Setup-Windows-36f70c16b9a7420da3cd797a3eb712fa

πŸ‘ 6
ackerleytng06:12:36

I'm trying to use figwheel-main with cider. when i change my code and refresh, I get this error in the browser

Uncaught ReferenceError: sb__3188__auto__ is not defined
    at Function.cljs$core$IFn$_invoke$arity$variadic (core.cljc?rel=1609393676355:257)
    at figwheel$core$call_hooks (core.cljc?rel=1609393676355:251)
    at after_reload_fn_48684 (core.cljc?rel=1609393676355:292)
    at callbackEntry.onFulfilled (promise.js:834)
    at Function.goog.Promise.invokeCallback_ (promise.js:1173)
    at goog.Promise.executeCallback_ (promise.js:1147)
    at goog.Promise.executeCallbacks_ (promise.js:1118)
    at goog.async.run.processWorkQueue (run.js:132)
and nothing seems to change. How should i start debugging?

clyfe08:12:14

I'd guess in core.cljc you have a macro call that calls a sb# that's not defined.

afleck15:12:00

happens when you change any code?

ackerleytng21:01:22

yup, when i change any code!

ackerleytng21:01:03

i don't have a function called sb either, but thanks, that's a good place to start!

ackerleytng21:01:12

but this sb isn't a function

roelof10:12:50

What is a good way to learn web development in clojure ?

mathias_dw12:12:42

Depends a lot on what aspect of web development... if you’re talking about frontend work, I would recommend reading the re-frame docs. Even if you don’t want to use re-frame, they’re really well written and fun.

roelof12:12:54

oke, im was more thinking first on back-end but I also need a front-end

roelof12:12:16

I was thinking about a gallery where the pictures come from a external api

roelof12:12:44

will look at re-frame and some tutorials, thanks

mathias_dw13:12:14

for the backend, I don't really know: there's https://luminusweb.com/ that makes choices for full-stack, but I think most people pick and choose their own setup by combining different libraries. For http, ring is the most popular, for routing probably compojure, there's a rich choice in actual servers (I keep using http-kit because I liked it best a few years ago, and it has served my needs fine). For html generation, I think hiccup is by far the most popular, but again there's plenty of choice...

mathias_dw13:12:50

it may seem a bit daunting if you're used to something like rails or django, but in fact it's really nice to be able to pick and choose

roelof16:12:39

@U05254DQM thanks, looks good and it seems to be a book that you are writing , right ?

practicalli-johnny17:12:31

Yes, its one of several books I have been working on...

roelof17:12:19

busy person

roelof17:12:49

can I better use the book or the videos for example the banking app

practicalli-johnny17:12:00

the video and the books have been created at approximately the same time. For the banking app I usually wrote the content for the books during the week and a video of new content at the weekend. There is more content in the book than the videos. There is probably a bit more learning experience in the videos but lots of overlap.

roelof17:12:26

but a quick skim I saw that the book is talking about a todo app but if I look well no todo's . Just a goodbye and some more methods. That needs to be updated ? @U05254DQM

roelof17:12:26

he, your also a mentor on the clojure exercism track. Really a busy person

practicalli-johnny17:12:52

Plenty of content to add all around

roelof17:12:45

I wish I know more so I could help you but im a beginner since 2 weeks to learn clojure

practicalli-johnny17:12:45

feel free to ask me questions about the content, especially if something is not clear or seems missing. There is a #practicalli channel for feedback and discussions on any of the Practicalli content (beginners channel is very busy)

roelof17:12:57

I can image

roelof17:12:19

think that will begin at the first chapters

roelof17:12:20

Have 2 projects in mind for the future but want to learn the basics first

roelof17:12:12

I think I will folllow the crux tutorials today and tomorrow. Looks interresting

popeye11:12:52

I am writing a testcases in clojure, and I have a function1 call inside another function2, where function 1 returns json data, How can i mock result of function 1 in testcases ( assigning dummy json data to function1)

(function2 [args]
   (let x[function1 x   ]) ;; This returns json data

mathias_dw12:12:41

Add a dependency on cheshire, which gives you a generator and parser going from and to json clojure (edn) data structures.

popeye12:12:19

lets generalised the return value, it could be list map be set or map.. But I want to mock it

Eamonn Sullivan13:12:31

I use with-redefs for that.

(with-redefs [function1 (fn [_] mock-json)]
  (testing ....

popeye13:12:13

that could help, I will try it

FHE14:12:25

@baibhavbista Thanks for the tip. I am finding myself forced to learn WSL in order to install the Clojure CLI tools, since I've heard it would be good for me to move to them ever continuing with Leiningen. I haven't gotten into looking for how to use WSL (not even how to set it up to begin with yet), but I'll check out your video. ...hopefully sometime this year! πŸ˜‰

Santiago17:12:44

In the REPL the following fn produces nil when fed an invalid uuid as a string e.g. 4231b771-d4f1-41d6-9281-9

(defn string->uuid 
  "Convert a string to java.util.UUID safely"
  [s]
  (try
   (java.util.UUID/fromString s)
   (catch Exception _ nil)))
but when my application is running (http-kit, compojure) this same function is producing 4231b771-d4f1-41d6-9281-000000000009 from the input above. What gives? πŸ˜…

noisesmith17:12:41

jvm version?

(ins)user=> (java.util.UUID/fromString "4231b771-d4f1-41d6-9281-000000000009")
#uuid "4231b771-d4f1-41d6-9281-000000000009"
(cmd)user=> (java.util.UUID/fromString "4231b771-d4f1-41d6-9281-9")
#uuid "4231b771-d4f1-41d6-9281-000000000009"

noisesmith17:12:19

clearly it's a change in java.util.UUID/fromString and not a clojure or clojure library issue

Santiago17:12:39

❯ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.8+10, mixed mode)
but how can it be that in the REPL it’s fine? :thinking_face: starting a REPL with clojure -M:repl/rebel-nrepl and my app with clojure -M -m my.app.core

noisesmith17:12:42

clojure and nrepl version will make zero difference here, the only possible source of different behavior is a difference between your jvm and the one onthe server

noisesmith17:12:04

if it's the same server, you are doing something else different and don't realize it

Santiago17:12:04

hum makes sense.. I’ll investigate further.. this behavior is super bad πŸ˜• I’m trying to use uuid? and this makes it pretty much useless

Santiago18:12:10

back to good old regex

dpsutton18:12:30

do you know where you're getting this informal uuid from? i think there's a decent argument that it should be rejected. and if you do want it accepted, can you run your production app on a jvm that you know works the way you want? For instance, whatever you're running your repl in seems to match up with your expectations

noisesmith18:12:17

as I read it, @slack.jcpsantiago wants this to be rejected and was surprised it was accepted

dpsutton18:12:48

oh i see. i had it backwards

noisesmith18:12:01

my only confusion is how any environment was rejecting it, as it's a longstanding and open bug

Santiago18:12:08

to be clear I want it rejected. I don’t know, I restarted my REPL and it’s showing the bug behavior. I can’t reproduce whatever I did before πŸ˜…

afry18:12:57

Hey everybody, happy NYE! I’m getting in some initial practice with working with JSON, and I’m wondering if there’s a standardized way for transforming a JSON array wrapped in a string into a vector. The strings in question are all tuples with 1 digit each:

"[1, 0]", "[4, 6]", etc.
This is what I’ve got for a home-rolled solution so far, but is there a library or something in the core library which can do this?
(defn str-to-vec [s] 
  (-> s
      (subs 1 4)
      (str/split #",")))

(str-to-vec "[0,0]") ; => [0 0]
(str-to-vec "[4,5]") ; => [4 5]

noisesmith18:12:45

there's clojure.data.json

noisesmith18:12:40

some people like cheshire too, but it adds deps which frequently break things (jackson)

noisesmith18:12:18

the (subs 1 4) is extremely fragile

noisesmith18:12:31

(eg. what if you got a two digit number?)

afry18:12:32

I was attempting to use json/read-str at first (http://clojure.github.io/data.json/#clojure.data.json/read-str) And while that will give me back JSON parsed into a string, I don’t think it’s going to parse an array into a vector, unless I’m missing something in the API docs.

noisesmith18:12:35

I find the idea that it would give you back a string confusing

noisesmith18:12:40

json is already a string

afry18:12:05

Let me see if I can get an example of what I’m seeing (thanks for the help btw!)

noisesmith18:12:11

data.json read / read-str turns js arrays into vectors

afry18:12:02

What I was missing was a second call to read-str . The first call gave me back a map of strings as keys/values, but calling it again with the string that I’m trying to convert into a vector did it for me:

(def json-example "{
  \"move\": \"[0,0]\"
}")

; my initial code:
(json/read-str json-example) ; => { "move" "[0,0]" }

; one more read-str to parse the needed value:
(json/read-str 
 (get (json/read-str json-example) "move")) ; => [0 0]

noisesmith19:12:00

so your json had unparsed json inside it

noisesmith19:12:29

I mean, I've dealt with input that's weirder than that I guess :D

afry19:12:52

it’s a strange world πŸ˜› thanks for the help

Christian20:12:16

When do I need do, and when can I skip it?

(defn example-fn1 [x y]
  (do (print (str x " + " y " = "))
      (+ x y)
      ))

(example-fn1 1 3) => 4

(defn example-fn2 [x y]
  (print (str x " + " y " = "))
  (+ x y)
  )

(example-fn2 1 3) => 4

ajoberstar20:12:06

@christiaaan You need do anytime you need multiple expressions where the function/macro only accepts one. Typically that would be for "side-effecting" things like your print examples. If the macro you call accepts a & body parameter at the end, you shouldn't need it.

Christian20:12:26

Can you give an example for this?

ghadi20:12:48

@christiaaan the arms of an if and cond are the most common place you'll need do

πŸ‘ 3
Christian20:12:22

ah, I think I can follow

ghadi20:12:24

(if test
  (do (log "something")
    expr1)
  expr2)

ghadi20:12:13

most everywhere else is what's called an "implicit do"

Christian20:12:25

Okay, because if needs to know where the then ends and the else starts

Christian20:12:54

in my defn example it doesnt matter because everything is evaluated until it ends?

Christian20:12:38

Slightly related: Can I do the first one? it feels easier to read:

(defn example-fn3 [x y]
  (defn subfunction [x] (* x 3))
  (+ (subfunction x) y)
  )

(example-fn3 5 1) => 16

(defn example-fn4 [x y]
  (letfn [(subfunction [x] (* x 3))]
    (+ (subfunction x) y)))
  
(example-fn4 5 1) => 16

didibus21:12:00

You can, but it's not clean code. You should do the latter or declare a proper function for it.

(defn subfunction [x] (* x 3))
(defn example-fn3 [x y] (+ (subfunction x) y))
Or what you did with letfn.

ajoberstar20:12:14

The main issue with the nested defn is it's creating a top-level var in the namespace.

ajoberstar20:12:31

So outside that funciton you'll still be able to call subfunction, which is probably not what you intend.

βœ… 3
andy.fingerhut20:12:37

@christiaaan It is anti-recommended to use def or any similar forms inside of a top level def / defn /etc. form

andy.fingerhut20:12:47

Every such form creates a globally visible name in that namespace.

andy.fingerhut20:12:50

Some people do such things as a method of debugging, e.g. to make intermediate values visible in a REPL session, but that isn't the only way to do so, and people who use it typically try to get rid of all such occurrences when finished with using them for debugging.

πŸ‘€ 3
Harley Waagmeester23:12:03

if i were to register and use a domain name including the word clojure in it, or just clojure alone as the domain name, would i be in violation of using a trademark ?

roelof23:12:28

Happy New Year all from a cold Netherlands

πŸŽ‰ 9
Harley Waagmeester23:12:42

i mean i wouldn't want Rich to come up behind me in a dark alley, he looks pretty tough

Harley Waagmeester23:12:33

hi roelof, my great grandfather came to the USA from Netherland in 1865 it was i think, he lived in a sod hut in Iowa, his sons became wealthy

Harley Waagmeester23:12:54

i use atoms instead of def's if need persistence (whether i use perl or clojure or lisp, all my code looks like C)

seancorfield23:12:27

I don't know what the situation is with using clojure in a domain name. There's and . I think there are more restrictions on the logo but I think with a domain name it might depend on what the site is going to be?

seancorfield23:12:27

There's also and ... probably others ...

seancorfield23:12:02

(it's still 2020 here for another 8 1/2 hours πŸ™‚ )

😎 3
Michael W23:12:18

It's not a registered trademark as far as I can see in the TESS lookup.

Harley Waagmeester23:12:29

not registered ? oh my don't let the lawyers know, they will trademark it and sue everyone

dpsutton23:12:20

I’m sure a friendly email after the holiday describing your plan to rich would be a polite way to proceed.