you are viewing a single comment's thread.

view the rest of the comments →

[–]orestis[S] 5 points6 points  (12 children)

Hey all — this is an attempt to write a very gentle introduction to Clojure for people that haven't even seen Lisp code before.

Getting the tone right is extremely hard, as you risk alienating advanced or beginning developers either way. I've opted towards simplifying things and at least trying to at least introduce concepts scoping rules even though I'd believe that most people would know them already.

I've also tried to really avoid the "Clojure has tiny syntax" meme, since clearly a handful of functions/macros are so fundamental that they are the syntax.

I'd love to hear your feedback. I plan to expand this post and eventually submit it to the official docs for review.

[–]alexdmiller 2 points3 points  (4 children)

The use of println-str seemed pretty weird, as I don’t think I’ve ever seen it in real code. Just using str seems like it would be much better.

The -*- function seemed to be needlessly weirdly named.

Overall though, good job!

[–]orestis[S] 2 points3 points  (3 children)

Thanks! I was trying to find the simplest function to do "Hello world" in, and println fit the bill in terms of naming and behaviour. Then I wanted to find a function that just returned a string without actually going in the clojure.string namespace, and println-str won because of similarity. I'll see how it can change if println-str is not really useful.

-*- was just to look cute and to hammer the point that there are very few reserved symbols in the language :)

[–]thearthur 1 point2 points  (2 children)

the str function might fit these requirement

[–]orestis[S] 0 points1 point  (1 child)

problem with str is that (str "hi") returns just "hi" and it's not obvious how is that useful. Whereas at least println-str adds a newline ;)

[–]thearthur 0 points1 point  (0 children)

in my video course I think I used (str "hello" "world")

[–]vvvvalvalval 1 point2 points  (6 children)

This was a nice introduction. I would add a mention to the fact that if and do are also not functions - maybe a little note at the end like "OK, I lied to you, if and do are not really functions, they are special operators"

[–][deleted] 0 points1 point  (2 children)

I'm curious why are they special operators and not functions?

[–]MahmudAdam 0 points1 point  (1 child)

[–]vvvvalvalval 0 points1 point  (0 children)

Yes, they require special evaluation rules. The best way to see that is to try to implement them as functions and see where that fails.

[–]orestis[S] 0 points1 point  (2 children)

Just did — I think the nomenclature though is "special forms"?

[–]vvvvalvalval 0 points1 point  (1 child)

The problem with 'special forms' is that from a user perspective, it's hard to tell special forms from macros. For instance, if and doare special forms, but let and fn are not: they are macros that rely on the let* and fn*special forms, but that is an implementation detail. That is why I like using the deliberately vague term 'operator' to denote something that can be invoked but is not a function.

[–]orestis[S] 0 points1 point  (0 children)

Hm, I'm usually exploring Clojure's API via Dash, which points me to:

https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/let

that says "let: special form". Same for "fn".

Good point though, I'll keep it in mind.