Weaving Perl


In my copious spare time™ one of my passions is weaving. Last week a notice appeared on one of the weaving lists, posting a url of:

http://www.cs.arizona.edu/patterns/weaving





to announce that "Additions and updates for August 2004 now are complete" in reference to the On-Line Archive of Documents on Weaving and Related Topics. While this site is always of interest to weavers, I noticed while reading the web page that clearly this site had become of interest to programmers as well. (Note: the above reference to 2004 is quite out of date— I've changed the link to the overall site and you should be able to search on the title.

In particular was an article entitled "The Painter Weaving Language" by Ralph Griswold. Here is a link to the file: The Painter Weaving Language.pdf Professor Griswold mentions the user document from Corel, in the bibliography Weaving.pdf it also is a useful read. Ralph was (he died on October 4, 2006) the keeper of the site and the inventor of Icon and Snobol as well as being an expert weaver. At any rate, the article rang a bell as I remembered that I had stumbled across this feature sometime before and had intended to write an expression evaluator for same in Perl, but had gotten distracted by the real world™!

Armed with Ralph's article and the original document I went ahead and created weave.pl. While this particular program produces results that are at best only of esoteric interest to most Perl programmers, the code that is used is easily converted to handle expressions from any small language.

The steps are:
  1. Use lex to translate the initial expression into one with uniform keywords.
  2. Convert the result to an expression list with expression2list.
  3. Parenthesize the expression list with parenthesize.
  4. Convert back to a string with list2expression.
  5. Convert the inner most parenthetical expression with innermost.
  6. Repeat step 5. until no more parenthetical expressions remain.

To generalize this code, the precedence table found in expression2list would have to either be passed or become global to the function and lex would have to be rewritten to handle the details of the given implementation's keywords.

For compiler junkies, the routine called parenthesize is in implementation of John A. N. Lee's chapter 6, 'Source Text Manipulation', section on 'Parenthesizing Expressions', page 267 of The Anatomy of a Compiler, second edition.

And for you string (the computer kind, not the weaver's kind) junkies out there, Ralph has also written articles on creating weaving patterns using both L-Systems and Cellular Automata! Enjoy!!

For anyone curious about what such software can produce, here are some images created by some of the included scripts:

   

As anyone familar with weaving drawdowns (basically a schematic grid representation of both the information needed to weave as well as the resulting pattern), it is moderately trivial to produce complex weaving imagery with small effort. Beyond that I have to admit that I'm not sure of what to make of or what use this effort might be, other than to say that the exercise was both a challenge and great fun. As all programming should be!


 Page last touched:
Send e-mail to: hsmyers@gmail.com 


Validated by W3C