# [CM] rewrite output in CM

**Drew Krause
**
drkrause@mindspring.com

*Tue, 26 Oct 2004 22:24:03 -0400*

I just answered my own question, in a somewhat convoluted way... here it
is, for anyone interested:
;; MTRULES -- morse-thue rules
(define mtrules '((0 -> (0 1))
(1 -> (1 0))))
;; RW-NEXT -- returns next complete generation of rewrite
;; rwthing = rules; alist = input string
;; example: (rw-next mtrules '(1 0)) = (1 0 0 1)
(defun rw-next (rwthing alist)
(let* ((this-rw (new rewrite of (append rwthing '((rw-end -> rw-end)))
:initially (append alist (list 'rw-end))))
(sink (next this-rw (+ (length alist) 1))))
(loop for x = (next this-rw) until (eql x 'rw-end) collect x)))
;; RWGEN -- returns arbitrary generation of rewrite
;; (rwgen mtrules '(1 0) 2) = (1 0 0 1 0 1 1 0)
(defun rwgen (rwrules initgen gennbr)
(case gennbr
(0 initgen)
(1 (rw-next rwrules initgen))
(t (rw-next rwrules (rwgen rwrules initgen (- gennbr 1))))))
Drew
Drew Krause wrote:
>* I need help with output options for the "rewrite" pattern. As an
*>* example, suppose I create a morse-thue sequence:
*>*
*>* (define mt (new rewrite of '((0 -> (0 1))
*>* (1 -> (1 0)))
*>* :initially '(1 0)))
*>*
*>* How can I get a new complete L-to-R generation on each call, a la:
*>*
*>* (1 0) ; {we can skip this step if we have to}
*>* (1 0 0 1)
*>* (1 0 0 1 0 1 1 0)
*>* &c.
*>*
*>* All help much appreciated!
*>*
*>* Drew
*>*
*>* _______________________________________________
*>* Cmdist mailing list
*>* Cmdist@ccrma.stanford.edu
*>* http://ccrma-mail.stanford.edu/mailman/listinfo/cmdist
*>*
*