[racket] does render-term or term->pict work in a metafunction?

From: Stephen Chang (stchang at ccs.neu.edu)
Date: Wed Mar 14 18:22:06 EDT 2012

> What you have written suggests that
> you're writing a metafunction that returns a pict, which would mean
> that the terms in your language are being represented as Racket-level
> picts (instead of the usual Racket-level sexpressions).

Yes, that's what I'm trying to do. I want to convert an arbitrary term
to a pict, to use in slideshow.


> Anyways, if you want to render a term, you have to use lw->pict and
> to-lw. It is more complex than it needs to be.

I don't think this would work either, since to-lw is still a macro.

Something like:

(define-metafunction L
  [(x->pict x) ,(lw->pict (language-nts L) (to-lw x))])

still gives a pict of x for (term (x->pict y)).


To get what I want, I figured out I can do:

(define-metafunction L
  [(x->pict x) ,(text (symbol->string (term x)))])




> Also, if no one has pointed you there yet, the git head has a redex
> tutorial now that includes some typesetting. (You'll find more in the
> SEwPR book, which Matthias may have a copy to lend you.)
>
> Robby
>
> 2012/3/14 Stephen Chang <stchang at ccs.neu.edu>:
>> Is there a way in redex to convert an arbitrary term to a pict?
>>
>>
>> I have this language:
>>
>> #lang racket
>> (require redex)
>>
>> (define-language L
>>  (e (λ x e) (e e) x)
>>  (x variable-not-otherwise-mentioned))
>>
>> (define-metafunction L
>>  [(x->pict x) ,(render-term L x #f)])
>>
>>
>> and (term (x->pict x)) and (term (x->pict y)) both return a pict of x
>> because render-term is a macro so x is treated as syntax and not as a
>> pattern variable. Is there a way in redex to do what what I want?
>>
>> ____________________
>>  Racket Users list:
>>  http://lists.racket-lang.org/users


Posted on the users mailing list.