开发者

Learning Clojure by reading core.clj

开发者 https://www.devze.com 2023-01-24 06:16 出处:网络
I came across the tweet today: Start each day by reading the implementation of a function or macro in Clojure\'s core.clj.

I came across the tweet today:

Start each day by reading the implementation of a function or macro in Clojure's core.clj.

My Clojure knowledg开发者_JAVA百科e is really basic, I can hardly read other's Clojure (or Lisp) code.

Can I do well with core.clj, especially I have the feeling it is full of complicated macros?


I think a better place to start is by doing a project; anything that interests you and seems manageable is good.

core.clj is not readable right now; perhaps the latter half is, but the first half isn't something I'd wish on anyone as an introduction to the language. The truth is, even if you read it very carefully, you'd not have a solid idea of what was going on without also reading a lot of Java code, too.

  • Make an asynchronous text-based game (technomancy—Phil Hagelburg—has a nice one to look through on his Github, though it's a little dated by now)
  • Scrape websites using the Enlive library.
  • Maybe just solve some math problems, and/or
  • Graph things using Incanter.

Build first. Once you acquaint yourself with the tools you are using, start reading them. The libraries mentioned here are well written (you can't go wrong with anything by Christophe Grand, for instance), and once you start using them, you'll understand what they do, which makes it much simpler to figure out the why and how later.


That tweet is probably a great idea once you have enough experience to be able to read Clojure code well enough to understand what is going on.

Before that point, I'd recommend gaining a strong familiarity with the language by writing a lot of small mini-programs. It's best to learn by doing, after all.

I personally found Project Euler very useful while I was learning Clojure.


You might also take a look at the Clojure Koans, though they may be a bit beginner-oriented for you, depending on how much Clojure you already know.


As a good starting point, I would recommend 4Clojure. It looks similar to Project Euler and Code Katas, but has more forgiving learning curve.


There's a lot I don't understand in it, but there's also a lot I do, and it's fascinating looking at the language getting bootstrapped from its minimal initial implementation.


Another place to look for little projects to get you going would be any of the Kata repos. My personal favorite at this point is Coding Kata.org, but there's also Coding Dojo, Ruby Koans (with a little translation effort), and of course Google.

Try to do one of those a day and you'll quickly pick up the language.


Try reading the Clojure contrib libraries or look at some Clojure projects on github to get a better feel for idiomatic Clojure code.


The advice above is good. Another fine example of learning-by-doing is well illustrated here by the creator of Ruby on Rails: How Do I Learn to Program? I hope you have an app that you care about that you could just go for in Clojure.


I find the clojure.core a good way to find ideas of how things are implemented, as more of a reference guide. As noted earlier, the early parts or neither pretty nor exemplary. However, the later parts can be a good example especially when needing to write a function that is close to core function but different.

0

精彩评论

暂无评论...
验证码 换一张
取 消