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)
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
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
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
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
@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?
(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)
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...
@sam694 ^ cc
@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.
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.
Are you somewhere in the western US, based on how late (from my perspective) you've been on here?
Bay Area, California, but originally from the UK. I tend to forget that Canada extends east by two more timezones than the US!
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>")
We rarely make it to midnight ourselves these days -- not because of kids (we don't have any) but because we're OLD ๐
We're here now. Happy New Year.
...and happy Old Year, all. It's the 31st here now.
Cool. Where are you based then @factorhengineering?
(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!)
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...
(telling me that it is none of my business is an acceptable answer ๐ )
@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
these look great! thanks!!
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?I'd guess in core.cljc you have a macro call that calls a sb#
that's not defined.
happens when you change any code?
yup, when i change any code!
i don't have a function called sb either, but thanks, that's a good place to start!
found this! https://github.com/bhauman/figwheel-core/blob/master/src/figwheel/core.cljc#L536 there's an sb here
but this sb isn't a function
What is a good way to learn web development in clojure ?
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
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.
Add a dependency on cheshire, which gives you a generator and parser going from and to json clojure (edn) data structures.
oke, im was more thinking first on back-end but I also need a front-end
I was thinking about a gallery where the pictures come from a external api
will look at re-frame and some tutorials, thanks
lets generalised the return value, it could be list map be set or map.. But I want to mock it
I use with-redefs for that.
(with-redefs [function1 (fn [_] mock-json)]
(testing ....
that could help, I will try it
Thanks @eamonn.sullivan
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...
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
@roelof this may help getting started https://practicalli.github.io/clojure-webapps/
@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! ๐
@jr0cket thanks, looks good and it seems to be a book that you are writing , right ?
Yes, its one of several books I have been working on...
busy person
can I better use the book or the videos for example the banking app
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.
oke
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
he, your also a mentor on the clojure exercism track. Really a busy person
Plenty of content to add all around
I wish I know more so I could help you but im a beginner since 2 weeks to learn clojure
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)
I can image
think that will begin at the first chapters
Have 2 projects in mind for the future but want to learn the basics first
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? ๐
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"
clearly it's a change in java.util.UUID/fromString and not a clojure or clojure library issue
I think I will folllow the crux tutorials today and tomorrow. Looks interresting
โฏ 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
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
if it's the same server, you are doing something else different and don't realize it
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
yap itโs a bug https://bugs.openjdk.java.net/browse/JDK-8216407
back to good old regex
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
as I read it, @slack.jcpsantiago wants this to be rejected and was surprised it was accepted
oh i see. i had it backwards
my only confusion is how any environment was rejecting it, as it's a longstanding and open bug
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 ๐
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]
there's clojure.data.json
that doesn't come with core though https://github.com/clojure/data.json
some people like cheshire too, but it adds deps which frequently break things (jackson)
the (subs 1 4)
is extremely fragile
(eg. what if you got a two digit number?)
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.
I find the idea that it would give you back a string confusing
json is already a string
Let me see if I can get an example of what Iโm seeing (thanks for the help btw!)
data.json read / read-str turns js arrays into vectors
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]
so your json had unparsed json inside it
I mean, I've dealt with input that's weirder than that I guess :D
itโs a strange world ๐ thanks for the help
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
@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.
Can you give an example for this?
@christiaaan the arms of an if
and cond
are the most common place you'll need do
ah, I think I can follow
thank you
(if test
(do (log "something")
expr1)
expr2)
most everywhere else is what's called an "implicit do"
Okay, because if needs to know where the then ends and the else starts
in my defn example it doesnt matter because everything is evaluated until it ends?
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
The main issue with the nested defn is it's creating a top-level var in the namespace.
So outside that funciton you'll still be able to call subfunction, which is probably not what you intend.
@christiaaan It is anti-recommended to use def
or any similar forms inside of a top level def
/ defn
/etc. form
Every such form creates a globally visible name in that namespace.
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.
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.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 ?
Happy New Year all from a cold Netherlands
i mean i wouldn't want Rich to come up behind me in a dark alley, he looks pretty tough
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
i use atoms instead of def's if need persistence (whether i use perl or clojure or lisp, all my code looks like C)
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?
There's also <http://clojuredesign.club|clojuredesign.club>
and <http://clojurescriptpodcast.com|clojurescriptpodcast.com>
... probably others ...
(it's still 2020 here for another 8 1/2 hours ๐ )
It's not a registered trademark as far as I can see in the TESS lookup.
not registered ? oh my don't let the lawyers know, they will trademark it and sue everyone
Iโm sure a friendly email after the holiday describing your plan to rich would be a polite way to proceed.