Yesterday a couple people asked me, “How and why do you use macros in a Lisp like Racket or Clojure?”.
I gave answers like:
Although all true, I wasn’t sure I was getting the full idea across.
So I’ve fallen behind on the blogging, for a few reasons. Time to catch up.
I’m calling this “day 5” as a useful fiction. It’s a distillation of what is closer to days 5–7, or something like that.
As I mentioned before, this series of blog posts is going more directly from brain to web. Reflection and editing? Not so much.
- Spent time with Clojure Cookbook.
- Started a cheat sheet for Racket ↔ Clojure.
- Looked at
- Started a port of wffi from Racket to Clojure.
- Confusion: Aggregates and generics.
Please see the usual disclaimers from my previous posts.
As I mentioned yesterday, my next toy project is to write wrappers libraries for the new Hacker News API. This seems like a good exercise because the REST API is very simple, and I have experience doing this sort of thing in Racket. In fact, I’ll do the same thing in both Racket and Clojure.
The result is clacker-news and racker-news. Trademark registration application is in-process.1
As with yesterday’s post, important disclaimers:
I’ve used Racket heavily but not Clojure.
Opinions expressed herein are not those of my employer, were I to have one.
If indignation lasts more than four hours, please seek medical attention.
Day 2 with Clojure was much more fun! I didn’t hit speed bumps with tooling and workflow, so frequently. I was able to focus mostly on the code itself, which was wonderful.
For a slightly more realistic task, I decided to make a really simple function that, given a URL, would make a
GET request and return the value of the
Server response header (if any), and a list of URLs found on the page that are for other servers. The idea being, you could crawl from some starting point and accumulate some data about web server technology.
Until now, Clojure has been an “armchair” language for me. I’ve read a lot about it, and I’ve read a fair amount of code written in it. But aside from typing a few things into an online REPL like Try Clojure, I’ve not really used it hands-on.
A couple days ago I started my 12-week batch at Hacker School. First on my list is to get some real experience with Clojure.
And I’m going to blog about the experience.
This is an overview of things I’ve created using Racket. Two motivations for writing this now:
Over the last week I was at three conferences (whew!) where, when meeting or catching up with someone, I had to explain what I’ve been doing. I mentioned my current projects or projects I guessed they’d relate to. But that’s not necessarily representative of all that I’ve been able to do with Racket. I wish I’d been able to give a better overview. I have quite a few repos on GitHub, but that’s just a big list with no structure.
In about a week I start my batch at Hacker School. I’ll likely spend less time with Racket, because the whole point is to learn new things. Now is a good time to take inventory. And I’ll be better prepared to talk about Racket there.
As a result, here’s an inventory, grouped into categories.
Let’s say you need to destructure a list with
match, using a pattern that specifies a “rest” or “more” element. Be careful. You probably want to use
Most of my Racket projects don’t use a makefile. Why would they?
raco setup suffices.
But a makefile can consistently define some common project tasks. And it can really help when you want to generate HTML documentation from Scribble sources, and publish it to GitHub Pages using the automagical
Many languages have a variable (or preprocessor macro) called
__file__ whose value is the pathname of the current source file. Likewise
__LINE__ for the the source line number.
You probably need this less in Racket than you imagine. For example:
We wouldn’t test that
__FILE__ ends in
main.rkt; instead we’d use a
(module+ main <your code here>).
To get a data file
foo.dat located in the same directory as a source file we’d use
(define-runtime-path foo.dat "foo.dat"). If we’re a package or executable this works regardless of where our files happen to get installed.
But if you really did need a
__FILE__ in Racket, how would you do it?