These days I have took Peter Norvig’s Udacity course CS212: DESIGN OF COMPUTER PROGRAMS.
Unfortunately, the course is all in Python so, for the sake of learning, I wrote the equivalent code in Racket for regex compiler given in unit 3 of that course.
You can see my code here: http://codepad.org/8x0rMXOi
Now, what’s bothering me is that Mr. Norvig’s original code in Python is somewhat shorter than mine. 🙁 But ok, I’m just beginner in Racket, and that is expected. But I wonder if some Racket expert can shorten my code, so that Racket code become shorter than original Norvig’s Python code?
Here are a few tips.
The ormap-expression in:
can be written as
The if-epression in
can be written as
However your function are small and to the point, so I wouldn’t change much.
A more convenient syntax for manipulating strings would make
it easier to read and write string manipulation programs. Some years ago I made an attempt and wrote a concat macro.
I used it to implement Norvig’s spelling checker (his original article might interest you). The resulting spelling checker and the concat macro is explained here
http://blog.scheme.dk/2007/04/writing-spelling-corrector-in-plt.html
Update: I have written an updated version of the spell checker.
The concat macro is makes simple string manipulation shorter.
https://github.com/soegaard/this-and-that/blob/master/spell-checker.rkt