Clojure’s instaparse TI-style math interpreter

There aren’t too many examples of Clojure’s instaparse use out there, so if you’re working on parsing a little language of your own, I hope this might come in handy.

I’ve been working on a little interpreter for some internal stuff part of the Front Row stack, mainly for validating student answers in the more complex middle school math domains. The interpreting the answer becomes pretty much mandatory for validating things like equivalence of two polynomials. This is what came out from the early efforts.

The EBNF grammar itself can be found here, the implementation of the parser is here (still blows my mind it’s under 50 lines), and the tests are all here. Wouldn’t have touched this with a ten foot pole without testing every single incremental addition.

A couple of resources I found useful, in addition to instaparse’s official docs:

The author of instaparse himself was also generous with a few tips on the library’s Google Groups.

Clojure’s instaparse TI-style math interpreter

Link

Computer Networks on Coursera

Can’t recommend this course highly enough if you’re a web dev of are doing work beyond one device.

It’s a very bittersweet course, as I continuously run into concepts that make me go:“I really should already know this like the back of my hand”, but oh well, it’s never too late.

David Wetherall is a very pleasant instructor and does a superb job.

I have to say I have a much better understanding of networking internals now and this is a good ramp for diving into meatier material such as http://www.amazon.com/TCP-Illustrated-Volume-Addison-Wesley-Professional/dp/0321336313

Computer Networks on Coursera

Link

nREPL

Want to be able to connect to your clojure Ring-based web-app as it’s running and read/edit its code in real time? No problemo.

Add the clojure.tools.nrepl dependency, and defonce the server somewhere in your handler with a port of your choice. Now you can just ssh into the web app’s box and use your repl of choice (I use Leiningen for simplicity) to play around with things. Really convenient for debugging, since with Clojure you almost never attach a traditional step-through debugger to running applications.

For bonus points you can use cemerick’s Drawbridge to enable logging into your app through the existing HTTP(S) routes. No need to expose additional ports and figure out how to secure that properly (since default nREPL is passwordless, as far as I can tell. That will only work until the first nmap). What’s neat is that you can in fact keep using the same auth mechanisms you already have in place, except this time for administrative REPL access.

nREPL

Link