May 2018
Beginner to intermediate
290 pages
6h 43m
English
Let’s start with that simple hit-counter application. Here is a basic Ring web application that counts the number of visitors to the site and congratulates every 100th visitor:
| | (def counter 0) |
| | (defn greeting-message [req] |
| | (if (zero? (mod counter 100)) |
| | (str "Congrats! You are the " counter " visitor!") |
| | (str "Welcome to Blotts Books!"))) |
| | ;; ect |
Except that it doesn’t. The trouble is that counter stays firmly bound to zero and it’s not clear how we can fix that. And as we’ve discussed any number of times, we cannot yield to the temptation of slipping (def counter (inc counter)) in greeting-message: vars are there to hold relatively stable values and a hit counter is anything but stable. ...
Read now
Unlock full access