beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
Baibhav Bista 2020-12-31T03:43:23.158Z

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)

๐Ÿ‘€ 2
Christian 2020-12-31T10:33:41.176900Z

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

๐Ÿ™ 1
nnichols 2020-12-31T13:33:52.188700Z

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

๐Ÿ™ 1
Baibhav Bista 2020-12-31T03:51:35.160Z

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

practicalli-john 2020-12-31T15:01:21.196Z

https://practicalli.github.io/

๐Ÿ™ 1
Sam Stowers 2020-12-31T03:55:10.162800Z

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

๐Ÿ‘ 1
seancorfield 2020-12-31T04:20:05.164100Z

@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?

seancorfield 2020-12-31T04:28:58.165200Z

(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)

seancorfield 2020-12-31T04:30:12.166500Z

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...

๐Ÿ‘ 1
๐Ÿ™ 1
seancorfield 2020-12-31T04:30:47.166700Z

https://www.jacekschae.com/

seancorfield 2020-12-31T04:30:55.166900Z

@sam694 ^ cc

๐Ÿ‘ 1
FHE 2020-12-31T04:55:03.170Z

@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.

FHE 2020-12-31T14:50:57.191400Z

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.

FHE 2020-12-31T14:52:02.191600Z

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

seancorfield 2020-12-31T17:57:41.205800Z

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

FHE 2021-01-01T01:26:34.251100Z

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>")

seancorfield 2021-01-01T01:51:04.255100Z

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

FHE 2021-01-01T14:36:01.271400Z

We're here now. Happy New Year.

FHE 2020-12-31T04:55:27.170600Z

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

seancorfield 2020-12-31T04:56:06.170900Z

Cool. Where are you based then @factorhengineering?

seancorfield 2020-12-31T04:57:40.171100Z

(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!)

seancorfield 2020-12-31T05:04:24.171300Z

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...

seancorfield 2020-12-31T05:05:14.171600Z

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

Baibhav Bista 2020-12-31T05:09:01.174200Z

@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

๐Ÿ‘ 2
Baibhav Bista 2020-12-31T05:34:13.174400Z

these look great! thanks!!

ackerleytng 2020-12-31T06:54:36.175600Z

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?

clyfe 2020-12-31T08:18:14.175900Z

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

afleck 2020-12-31T15:18:00.196300Z

happens when you change any code?

ackerleytng 2021-01-02T21:10:22.349100Z

yup, when i change any code!

ackerleytng 2021-01-02T21:11:03.349700Z

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

ackerleytng 2021-01-02T21:13:33.352600Z

found this! https://github.com/bhauman/figwheel-core/blob/master/src/figwheel/core.cljc#L536 there's an sb here

ackerleytng 2021-01-02T21:17:12.357Z

but this sb isn't a function

roelof 2020-12-31T10:24:50.176800Z

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

popeye 2020-12-31T11:52:52.181200Z

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

2020-12-31T12:15:42.184300Z

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.

2020-12-31T12:17:41.186700Z

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

roelof 2020-12-31T12:34:54.186900Z

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

roelof 2020-12-31T12:35:16.187100Z

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

roelof 2020-12-31T12:35:44.187300Z

will look at re-frame and some tutorials, thanks

popeye 2020-12-31T12:50:19.187500Z

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

Eamonn Sullivan 2020-12-31T13:08:31.187700Z

I use with-redefs for that.

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

popeye 2020-12-31T13:13:13.187900Z

that could help, I will try it

popeye 2020-12-31T13:13:24.188100Z

Thanks @eamonn.sullivan

2020-12-31T13:14:14.188300Z

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...

2020-12-31T13:15:50.188500Z

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

practicalli-john 2020-12-31T14:57:16.195500Z

@roelof this may help getting started https://practicalli.github.io/clojure-webapps/

FHE 2020-12-31T14:57:25.195900Z

@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! ๐Ÿ˜‰

roelof 2020-12-31T16:21:39.196500Z

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

practicalli-john 2020-12-31T17:11:31.196700Z

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

roelof 2020-12-31T17:12:19.196900Z

busy person

roelof 2020-12-31T17:12:49.197100Z

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

roelof 2020-12-31T17:17:08.197300Z

@jr0cket

practicalli-john 2020-12-31T17:20:00.197500Z

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.

roelof 2020-12-31T17:21:13.197700Z

oke

roelof 2020-12-31T17:22:26.197900Z

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 ? @jr0cket

roelof 2020-12-31T17:23:26.198100Z

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

practicalli-john 2020-12-31T17:24:52.198300Z

Plenty of content to add all around

roelof 2020-12-31T17:26:45.198500Z

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

practicalli-john 2020-12-31T17:35:45.198700Z

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)

roelof 2020-12-31T17:36:57.198900Z

I can image

roelof 2020-12-31T17:37:19.199100Z

think that will begin at the first chapters

roelof 2020-12-31T17:42:20.199300Z

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

Santiago 2020-12-31T17:44:44.201400Z

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-&gt;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? ๐Ÿ˜…

2020-12-31T17:46:41.201700Z

jvm version?

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

2020-12-31T17:47:19.202200Z

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

roelof 2020-12-31T17:51:12.202400Z

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

Santiago 2020-12-31T17:53:39.203300Z

โฏ 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

2020-12-31T17:55:42.204300Z

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

2020-12-31T17:56:04.204700Z

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

Santiago 2020-12-31T17:57:04.205700Z

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

Santiago 2020-12-31T17:59:55.206100Z

yap itโ€™s a bug https://bugs.openjdk.java.net/browse/JDK-8216407

Santiago 2020-12-31T18:00:10.206400Z

back to good old regex

dpsutton 2020-12-31T18:11:30.207800Z

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

2020-12-31T18:12:17.208400Z

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

dpsutton 2020-12-31T18:12:48.208700Z

oh i see. i had it backwards

2020-12-31T18:13:01.209Z

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

Santiago 2020-12-31T18:30:08.210200Z

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 ๐Ÿ˜…

2020-12-31T18:41:57.214600Z

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] 
  (-&gt; s
      (subs 1 4)
      (str/split #",")))

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

2020-12-31T18:42:45.214800Z

there's clojure.data.json

2020-12-31T18:43:17.215200Z

that doesn't come with core though https://github.com/clojure/data.json

2020-12-31T18:43:40.215800Z

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

2020-12-31T18:45:18.217Z

the (subs 1 4) is extremely fragile

2020-12-31T18:45:31.217500Z

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

2020-12-31T18:45:32.217600Z

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.

2020-12-31T18:46:35.218100Z

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

2020-12-31T18:46:40.218300Z

json is already a string

2020-12-31T18:47:05.218700Z

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

2020-12-31T18:47:11.219Z

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

2020-12-31T18:59:02.221800Z

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) ; =&gt; { "move" "[0,0]" }

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

2020-12-31T19:00:00.222100Z

so your json had unparsed json inside it

2020-12-31T19:00:29.222500Z

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

2020-12-31T19:00:52.222800Z

itโ€™s a strange world ๐Ÿ˜› thanks for the help

Christian 2020-12-31T20:04:16.223600Z

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) =&gt; 4

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

(example-fn2 1 3) =&gt; 4

ajoberstar 2020-12-31T20:14:06.226100Z

@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 &amp; body parameter at the end, you shouldn't need it.

Christian 2020-12-31T20:21:26.226700Z

Can you give an example for this?

ghadi 2020-12-31T20:21:48.227100Z

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

๐Ÿ‘ 1
Christian 2020-12-31T20:22:22.228300Z

ah, I think I can follow

Christian 2020-12-31T20:22:23.228500Z

thank you

ghadi 2020-12-31T20:22:24.228600Z

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

ghadi 2020-12-31T20:23:13.229100Z

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

Christian 2020-12-31T20:24:25.230Z

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

Christian 2020-12-31T20:24:54.230600Z

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

Christian 2020-12-31T20:29:38.231600Z

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) =&gt; 16

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

ajoberstar 2020-12-31T20:30:14.232200Z

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

ajoberstar 2020-12-31T20:30:31.232800Z

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

โœ… 1
2020-12-31T20:30:37.233Z

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

2020-12-31T20:30:47.233300Z

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

2020-12-31T20:31:50.234400Z

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.

๐Ÿ‘€ 1
2020-12-31T21:11:00.235400Z

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.

Harley Waagmeester 2020-12-31T23:23:03.237900Z

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 ?

roelof 2020-12-31T23:23:28.238500Z

Happy New Year all from a cold Netherlands

๐ŸŽ‰ 3
Harley Waagmeester 2020-12-31T23:24:42.238600Z

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

Harley Waagmeester 2020-12-31T23:28:33.240700Z

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 Waagmeester 2020-12-31T23:31:54.242900Z

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

seancorfield 2020-12-31T23:32:27.243500Z

I don't know what the situation is with using clojure in a domain name. There's <http://clojuredocs.org|clojuredocs.org> and <http://clojure-doc.org|clojure-doc.org>. 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?

seancorfield 2020-12-31T23:33:27.244Z

There's also <http://clojuredesign.club|clojuredesign.club> and <http://clojurescriptpodcast.com|clojurescriptpodcast.com> ... probably others ...

seancorfield 2020-12-31T23:34:02.244800Z

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

๐Ÿ˜Ž 1
Michael W 2020-12-31T23:34:18.245400Z

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

Michael W 2020-12-31T23:34:37.245900Z

https://www.uspto.gov/trademark

Harley Waagmeester 2020-12-31T23:35:29.246800Z

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

dpsutton 2020-12-31T23:40:20.248100Z

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