This past week I’ve been in Brighton working on the MIMIC Project at the EMUTE Lab with the Sema development team, Thor and Francisco and Chris. Part of the project is about creating livecoding languages for machine learning, and we’ve spent a few days getting deep into their hackable livecoding language and software, called SEMA.
Machine learning aside, I’ve used the time to learn the ins and outs of NearleyJS for creating grammars and I’m actually liking it. This week, I wrote a minilanguage grammar for my LivePrinter project, something I’ve been trying to do for quite awhile.
This is my 3rd attempt to write a grammar over the past 2 years. (Check out the failed PEGjs version or the unfinished GCode grammar). It’s been on my to do list for awhile because livecoding is all about typing, brevity and contextual information and general programming languages are more about structured syntax for a wide variety of programmers and situations.
When I’m sitting in front of an audience and trying to think of things to type, I need short snippets or routines and not larger, more complex code structures. One-liners are great. Also, sticking in some contextual information helps thinking. With 3D printing, we’re thinking about physical objects and real-world movements. Units shouldn’t just be numbers, they should be dimensions like millimeters, inches, feet, etc.
With a grammar, I write a very short sentence in code like:
# lp.move x:22mm | turn 90deg | extrude x:10mm y:10mm
…which translates to, in English: “Tell the printer to move 22mm in the x direction (perpendicular to the person sitting in front of it), then turn 90 degrees and extrude a line whilst moving 10mm across and 10mm away”. With a grammar, I could even make that more explicit so Tell the printer compiled to lp (which is the LivePrinter object, in code terms) and in the x direction compiled to the function argument x: . It’s a way of making code more like language, more readable.
Unfortunately, more verbose code takes longer to type. It also has more words to mess up when you’re typing under pressure in front of people. Hopefully this minilanguage will find the balance between the two. There’s an example in the system that you can read through.