<br><br><div class="gmail_quote">On Dec 6, 2007 9:38 PM, Robby Findler <<a href="mailto:robby@cs.uchicago.edu">robby@cs.uchicago.edu</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c">On Dec 6, 2007 3:59 AM, <<a href="mailto:yug@ios.ac.cn">yug@ios.ac.cn</a>> wrote:<br>> Hi, all:<br>><br>> some issues around the redex<br>><br>> the code snippet:
<br>><br>> (module test mzscheme<br>> (require (planet "reduction-semantics.ss" ("robby" "redex.plt" 3)))<br>> (define basic-grammar<br>> (language<br>> (e x (e e) ("lam" x e))
<br>> (x variable-not-otherwise-mentioned)<br>> ))<br>><br>> (define ext-grammar<br>> (extend-language<br>> basic-grammar<br>> (C number string )<br>> (e .... C)<br>
> ))<br>><br>> (define-metafunction sub<br>> basic-grammar<br>> [(((x_1) ... x_2 x_3 ...) (x_4 ... x_2 x_5 ...))<br>> (sub (((x_1) ... x_3 ...) (x_4 ... x_2 x_5 ...)))]<br>> [(((x_1) ... x_2 x_3 ...) (x_4 ... ))
<br>> (sub (((x_1) ... (x_2) x_3 ...) (x_4 ...)))]<br>> [(((x_1) ...) (x_4 ... ))<br>> (x_1 ...)])<br>><br>> (define-metafunction fv<br>> basic-grammar<br>> [x_1 (x_1)]<br>> [(e_1 e_2) ,(append (term (fv e_1)) (term (fv e_2)))]
<br>> [("lam" x_1 e_1) (sub ((fv e_1) (x_1)))]<br>> )<br>><br>> ;;?<br>> (define-metafunction/extension fv1<br>> ext-grammar<br>> fv<br>> [C_1 ()]<br>> )<br>
><br>> (define ext2-grammar<br>> (extend-language<br>> ext-grammar<br>> (prim + - * /)<br>> (C .... prim)<br>> (e .... prim)<br>> )<br>> )<br>><br>> #;(define test (term (fv1 ("lam" y ("lam" x (+ x y))))))
<br>><br>> #;(define test2 (test-match ext2-grammar e_1 '(+ ("lam" x (+ 1)))))<br>><br>> )<br>><br>> 1. how can I use "define-metafunction/extension"?<br>><br>> firstly, it is inconvenient to rename fv to fv1
<br><br></div></div>You've got two functions, however, that do different things. They<br>can't both have the same name, right?<br><div class="Ih2E3d"><br>> second, how can I reuse the definitions in fv?<br><br>
</div>When you write an extended metafunction (like fv1), the cases from the<br>original metafunction (in this case fv) are automatically copied into<br>the new one. Is that what you're asking?</blockquote><div><br>let's do some tests:
<br> > (term (fv ("lam" y ("lam" x (z (x y))))))<br>(z)<br>> (term (fv ("lam" y ("lam" x (z (x 1))))))<br>fv: no clauses matched for (("lam" y ("lam" x (z (x 1)))))
<br>> (term (fv1 ("lam" y ("lam" x (z (x 1))))))<br>fv1: no clauses matched for (("lam" y ("lam" x (z (x 1)))))<br><br>So, what I want is the "fv" function for grammar ext-grammar
<br><br>I just want a show case on the usage for define-metafunctions/extension, of course, no need to <br><br>rename will be better, thanks<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><div class="Ih2E3d"><br>> btw, is there also a demo show on "define-multi-arg-metafunction"?<br><br></div>Not yet, I'm sorry to say, but the definition of a multi-arg<br>metafunction looks just like a regular one (except for any recursive
<br>calls). It is the calls that change. Instead of (F (x y z)), you write<br>(F x y z).<br><div class="Ih2E3d"><br>> 2. a little suggestion: we see that ext2-grammar is something wrong which<br>> makes e and C all terminate on
<br>> prim. however, redex just accept it. so , test2 make multiple matches. For<br>> someone experienced to redex,<br>> there is a quickly respond to the grammar. But, for the freshes, it takes<br>> time to handle. So, I suggest redex
<br>> do a static check on this case and report a warning<br><br></div>Unfortunately, Redex cannot tell, just by looking at the grammar,<br>which non-terminals you intend to be contexts and which ones you<br>don't, so I'm not sure that there is a simple check one could do here.
<br>In other words, why would the static check say that "C" is bad, but<br>that "e" is good?<br></blockquote><div><br>I just think a process on scanning the non-terminals, and report something warnning:
<br><br>just like:<br><br>e ----C ----prim<br>e -----------prim<br><br>there is a converge on prim for e matching, i.e a prim will make a two e matches, I think redex can do this <br>statically, and report that<br><br>thanks
<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>Robby<br>_________________________________________________<br> For list-related administrative tasks:
<br> <a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme" target="_blank">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br></blockquote></div><br><br clear="all"><br>-- <br>Gang