KnitML update

Meg has suggested that, even though my active knitting project isn't actually a knitted object, I should blog about my progress.

KnitML 0.1 was released in February, and the project has since received 82 downloads! The basic sock pattern I wrote as a starting point now validates and renders successfully.

To give you an idea of what I've been doing, here's how you express knitting the cuff with 1x1 ribbing:
<instruction id="cuff-round">
<row type="round">
<repeat until="end">
<knit>1</knit>
<purl>1</purl>
</repeat>
</row>
</instruction>
<repeat-instruction idref="cuff-round">
<until-measures unit="in">1.5</until-measures>
</repeat-instruction>
The KnitML is essentially "test knit" by the computer before the pattern is printed. So, for instance, if there were an odd number of stitches on the needles when the computer got to this point, it would indicate that there is a problem with the pattern. An added bonus is that the computer puts in the row numbers as it goes along.

So the pattern ends up looking something like this:
Round 1: Purl
Round 2: *k1, p1, repeat from * to end
Repeat round 2 until piece measures 1.5 in.
Now if English isn't your first language, you can just as easily have the pattern render in Spanish. You set an option on the software and you get this instead:
Vuelta 1: Todo del reves
Vuelta 2: *1 p der, 1 p rev, repite desde * hasta el final
Repite vuelta 2 hasta que la pieza mida 1.5 in.
Many thanks to Cristina, by the way, for the Spanish translation files.

Now let's say that you want to create a KnitML pattern, but the thought of writing out all of those angled brackets makes you want to puke. I'm working on something called a domain-specific language (DSL) for knitting patterns. It looks much more like an actual knitting pattern. It's still important to have the XML representation underneath, but in order to get there, it's nice to have a shorthand like this to make your life easier:
round { repeatToEnd { p 1; k 2; p 1 } }
round { knitToEnd() }
The above expression actually produces KnitML that looks like this:
<row type="round">
<repeat until="end">
<purl>1</purl>
<knit>2</knit>
<purl>1</purl>
</repeat>
</row>
<row type="round">
<repeat until="end">
<knit />
</repeat>
</row>
This is currently implemented using a language called Groovy. It's quite a fun language to work with, and Meg could tell you that I've been rather obsessed with it of late.

So that's what I've been working on. I hope that it's at least a little bit interesting to non-geeks at this point.

Comments

JustApril said…
cool! =)
Anonymous said…
yup, it is interesting. 137 or so years ago I was a semi-geek. Discovered that programming was not. my. thing. But it still piques my interest. Thanks for the demo. (lopsided grin here)
an said…
zomg! that is the coolest thing EVER!!!

Popular Posts