I've added a sentence to the docs pointing out the use of write-special and a silly example at the end too.<div><br></div><div>I tried to make a silly example using 'plot', something like this, but it isn't that great. If others have suggestions, I think it would be nice to show plot here ...</div>
<div><br></div><div><div>#lang racket</div><div>(require redex 2htdp/image</div><div> (only-in plot plot </div><div> function</div><div> parametric))</div><div><br></div><div>(define/contract (unpair z)</div>
<div> (-> exact-nonnegative-integer? </div><div> (list/c exact-nonnegative-integer? exact-nonnegative-integer?))</div><div> (define i (integer-sqrt z))</div><div> (define i2 (* i i))</div><div> (cond</div><div>
[(< (- z i2) i)</div><div> (list (- z i2) i)]</div><div> [else </div><div> (list i (- z i2 i))]))</div><div><br></div><div>(define/contract (pair x y)</div><div> (-> exact-nonnegative-integer? exact-nonnegative-integer?</div>
<div> exact-nonnegative-integer?)</div><div> (if (= x (max x y))</div><div> (+ (* x x) x y)</div><div> (+ (* y y) x)))</div><div><br></div><div>(define-language L (n ::= natural))</div><div>(define red</div>
<div> (reduction-relation</div><div> L</div><div> (--> (n_1 n_2)</div><div> ,(unpair (+ 1 (pair (term n_1) </div><div> (term n_2)))))))</div><div>(traces red (term (0 0)))</div><div>
<br></div><div>(define (plot-as-poly term)</div><div> (plot</div><div> (function (λ (x) (+ (expt x (list-ref term 0))</div><div> (expt x (list-ref term 1)))))</div><div> #:x-min -10</div><div> #:x-max 10</div>
<div> #:y-min -100</div><div> #:y-max 100))</div><div><br></div><div>(define (plot-parametric-thingy term)</div><div> (plot (parametric (λ (t) (vector (expt (cos t) (+ (list-ref term 0) 1))</div><div> (expt (sin t) (+ (list-ref term 0) 1))))</div>
<div> 0 (* 2 pi))</div><div> #:x-min -2 #:x-max 2</div><div> #:y-min -2 #:y-max 2))</div><div> </div><div><br></div><div>(traces red </div><div> (term (0 0))</div><div> #:pp</div>
<div> (λ (term port w txt)</div><div> (write-special </div><div> (plot-as-poly term)</div><div> port)))</div><div><br></div><div>(traces red </div><div> (term (0 0))</div><div> #:pp</div>
<div> (λ (term port w txt)</div><div> (write-special </div><div> (plot-parametric-thingy term)</div><div> port)))</div><div><br></div></div><div><br></div><div>Robby<br><div><br>On Tuesday, May 7, 2013, Robby Findler wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Yes, sure:<div><br></div><div><div>#lang racket</div><div>(require redex 2htdp/image)</div><div>(define-language L </div>
<div> (t ::= RED YELLOW GREEN))</div><div><br></div><div>(define RED (circle 14 "solid" "red"))</div>
<div>(define YELLOW (circle 14 "solid" "yellow"))</div><div>(define GREEN (circle 14 "solid" "green"))</div><div><br></div><div>(define R</div><div> (reduction-relation</div><div>
L</div><div> (--> RED GREEN)</div><div> (--> YELLOW RED)</div><div> (--> GREEN YELLOW)))</div><div><br></div><div>(traces R (term RED)</div><div> #:pp</div><div> (λ (term port w txt)</div>
<div>
(write-special</div><div> (case term</div><div> [(RED) RED]</div><div> [(GREEN) GREEN]</div><div> [(YELLOW) YELLOW])</div><div> port)))</div></div><div><br>
</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 7, 2013 at 12:25 AM, David Van Horn <span dir="ltr"><<a href="javascript:_e({}, 'cvml', 'dvanhorn@ccs.neu.edu');" target="_blank">dvanhorn@ccs.neu.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Is it possible to render snips in redex traces?<br>
<br>
For example, here's something I'd like to write and have it result in a pretty traces window:<br>
<br>
#lang racket<br>
;; Traffic lights as redex model<br>
(require redex 2htdp/image)<br>
(define-language L)<br>
<br>
(define RED (circle 14 "solid" "red"))<br>
(define YELLOW (circle 14 "solid" "yellow"))<br>
(define GREEN (circle 14 "solid" "green"))<br>
<br>
(define R<br>
(reduction-relation<br>
L<br>
(--> (side-condition any_l (equal? (term any_l) RED)) ,GREEN)<br>
(--> (side-condition any_l (equal? (term any_l) YELLOW)) ,RED)<br>
(--> (side-condition any_l (equal? (term any_l) GREEN)) ,YELLOW)))<br>
<br>
(traces R (term ,RED))<br>
<br>
I'd also be happy if I could write a Term -> Snip function to supply as a pretty printer.<br>
<br>
David<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/<u></u>users</a><br>
</blockquote></div><br></div>
</blockquote></div></div>