<br><br><div class="gmail_quote">On Dec 6, 2007 9:38 PM, Robby Findler &lt;<a href="mailto:robby@cs.uchicago.edu">robby@cs.uchicago.edu</a>&gt; 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, &nbsp;&lt;<a href="mailto:yug@ios.ac.cn">yug@ios.ac.cn</a>&gt; wrote:<br>&gt; Hi, all:<br>&gt;<br>&gt; &nbsp; &nbsp;some issues around the redex<br>&gt;<br>&gt; the code snippet:
<br>&gt;<br>&gt; (module test mzscheme<br>&gt; &nbsp; (require (planet &quot;reduction-semantics.ss&quot; (&quot;robby&quot; &quot;redex.plt&quot; 3)))<br>&gt; &nbsp; (define basic-grammar<br>&gt; &nbsp; &nbsp; (language<br>&gt; &nbsp; &nbsp; &nbsp;(e x (e e) (&quot;lam&quot; x e))
<br>&gt; &nbsp; &nbsp; &nbsp;(x variable-not-otherwise-mentioned)<br>&gt; &nbsp; &nbsp; &nbsp;))<br>&gt;<br>&gt; &nbsp; (define ext-grammar<br>&gt; &nbsp; &nbsp; (extend-language<br>&gt; &nbsp; &nbsp; &nbsp;basic-grammar<br>&gt; &nbsp; &nbsp; &nbsp;(C number string )<br>&gt; &nbsp; &nbsp; &nbsp; (e .... C)<br>
&gt; &nbsp; &nbsp; &nbsp;))<br>&gt;<br>&gt; &nbsp; (define-metafunction sub<br>&gt; &nbsp; &nbsp; basic-grammar<br>&gt; &nbsp; &nbsp; [(((x_1) ... x_2 x_3 ...) (x_4 ... x_2 x_5 ...))<br>&gt; &nbsp; &nbsp; &nbsp;(sub (((x_1) ... x_3 ...) (x_4 ... x_2 x_5 ...)))]<br>&gt; &nbsp; &nbsp; [(((x_1) ... x_2 x_3 ...) (x_4 ... ))
<br>&gt; &nbsp; &nbsp; &nbsp;(sub (((x_1) ... (x_2) x_3 ...) (x_4 ...)))]<br>&gt; &nbsp; &nbsp; [(((x_1) ...) (x_4 ... ))<br>&gt; &nbsp; &nbsp; &nbsp;(x_1 ...)])<br>&gt;<br>&gt; &nbsp; (define-metafunction fv<br>&gt; &nbsp; &nbsp; basic-grammar<br>&gt; &nbsp; &nbsp; [x_1 (x_1)]<br>&gt; &nbsp; &nbsp; [(e_1 e_2) ,(append (term (fv e_1)) (term (fv e_2)))]
<br>&gt; &nbsp; &nbsp; [(&quot;lam&quot; x_1 e_1) (sub ((fv e_1) (x_1)))]<br>&gt; &nbsp; &nbsp; )<br>&gt;<br>&gt; &nbsp; ;;?<br>&gt; &nbsp; (define-metafunction/extension fv1<br>&gt; &nbsp; &nbsp; ext-grammar<br>&gt; &nbsp; &nbsp; fv<br>&gt; &nbsp; &nbsp; [C_1 ()]<br>&gt; &nbsp; &nbsp; )<br>
&gt;<br>&gt; &nbsp; (define ext2-grammar<br>&gt; &nbsp; &nbsp; (extend-language<br>&gt; &nbsp; &nbsp; &nbsp;ext-grammar<br>&gt; &nbsp; &nbsp; &nbsp;(prim + - * /)<br>&gt; &nbsp; &nbsp; &nbsp;(C .... prim)<br>&gt; &nbsp; &nbsp; &nbsp;(e .... prim)<br>&gt; &nbsp; &nbsp; &nbsp;)<br>&gt; &nbsp; &nbsp; )<br>&gt;<br>&gt; &nbsp; #;(define test (term (fv1 (&quot;lam&quot; y (&quot;lam&quot; x (+ x y))))))
<br>&gt;<br>&gt; &nbsp; #;(define test2 (test-match ext2-grammar e_1 &#39;(+ (&quot;lam&quot; x (+ 1)))))<br>&gt;<br>&gt; &nbsp; )<br>&gt;<br>&gt; 1. how can I use &quot;define-metafunction/extension&quot;?<br>&gt;<br>&gt; firstly, it is inconvenient to rename fv to fv1
<br><br></div></div>You&#39;ve got two functions, however, that do different things. They<br>can&#39;t both have the same name, right?<br><div class="Ih2E3d"><br>&gt; 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&#39;re asking?</blockquote><div><br>let&#39;s do some tests:
<br>&nbsp;&gt; (term (fv (&quot;lam&quot; y (&quot;lam&quot; x (z (x y))))))<br>(z)<br>&gt; (term (fv (&quot;lam&quot; y (&quot;lam&quot; x (z (x 1))))))<br>fv: no clauses matched for ((&quot;lam&quot; y (&quot;lam&quot; x (z (x 1)))))
<br>&gt; (term (fv1 (&quot;lam&quot; y (&quot;lam&quot; x (z (x 1))))))<br>fv1: no clauses matched for ((&quot;lam&quot; y (&quot;lam&quot; x (z (x 1)))))<br><br>So, what I want is the &quot;fv&quot; 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>&gt; btw, is there also a demo show on &quot;define-multi-arg-metafunction&quot;?<br><br></div>Not yet, I&#39;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>&gt; 2. a little suggestion: we see that ext2-grammar is something wrong which<br>&gt; makes e and C all terminate on
<br>&gt; prim. however, redex just accept it. so , test2 make multiple matches. For<br>&gt; someone experienced to redex,<br>&gt; there is a quickly respond to the grammar. But, for the freshes, it takes<br>&gt; time to handle. So, I suggest redex
<br>&gt; 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&#39;t, so I&#39;m not sure that there is a simple check one could do here.
<br>In other words, why would the static check say that &quot;C&quot; is bad, but<br>that &quot;e&quot; 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>&nbsp; <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> &nbsp;For list-related administrative tasks:
<br> &nbsp;<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