Realm of Racket: Lean to Program, One Game at a Time!

GoodReads Summary: Racket is a descendant of Lisp, a programming language renowned for its elegance, power, and challenging learning curve. But while Racket retains the functional goodness of Lisp, it was designed with beginning programmers in mind. Realm of Racket is your introduction to the Racket language.


This is a weird book. Not because its content, or the topic at hand, but the path chosen to explain things. For example, even after reading the whole book, I don't have any idea why I should pick Racket over any other Lisp variant.

So, laundry list of things that put me off:

So... yeah, I think I learn a bit of Racket, but I still don't know why I should pick it over anything else. Is it just the game building library? Should one pick a language exclusively because of some built in library? Doesn't anything else affects this decision? (All questions are rhetorical, it is obvious that you shouldn't pick a language just because one library).



"Let me write a very contrived example, just to make my favourite language look better compared to this one."

(sqrt (+ (sqr 3) (sqr 4)))

This is nowhere near the example in C++. If you want to compare languages, at least write the same thing.

If you’re on a *nix box, you are already a hero and don’t need instructions.

What a load of bull. It sounds more like you don't have an idea on how to do it in Linux.

(the compiler) DrRacket reads this expression, evaluates it, prints the result, and then displays its prompt again.

You just described an interpreter, not a compiler. For all purposes and intents, sure, it compiles the code to make sure it is not invalid, but the concept of "compiler" is used mostly for things that take a source and produce a stand-alone executable. Otherwise, even Python have a compiler.

the function uses a set! expression to change the value of a variable.

Why set!? Why not just set? What the ! means? Nothing? Is it just a convention?

Racket has three kinds of comments

And absolutely no example of those kinds.

(/ 4 6)

This is one cool thing: Racket keeps the values in their fractional format.

(struct student (name id# dorm))
(student-name freshman1)
(student-id# freshman1)

Creating structs and extracting values from them.

(define x 7)
  (cond [(= x 7) 5]
        [(odd? x) 'odd-number]
        [else 'even-number])

Multiple tests. Also, there is this use of brackets ("[") and parenthesis ("(") which is never properly explained, though.

(when (and file-modified (ask-user-about-saving)) (save-file))

Because and and or return the value if it's not the boolean false (#f), you can use tests to simplify the code.

(define filename "my-first-program.rkt")
(unless (ask-user-whether-to-keep-file filename) (delete-file filename))

unless is a form of if that performs an action only if the value is #f (false).

(struct orc monster (club))
(struct hydra monster ())
(struct slime monster (sliminess))
(struct brigand monster ())

Examples of deriving structs from other structs.

In summary, mutators make programming complex

Just a few paragraphs better, you used a mutator saying that this would make the code better.

raco exe -l hello-world.rkt

Generating a standalone executable from Racket source code.

(define snake%
  (class object%
    (init-field dir head tail)
    (define/public (slither)
      (set! tail (cons head (all-but-last tail)))
      (set! head (next-head)))

Classes in Racket.