<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Sep 8, 2014 at 9:51 PM, </div><div class="gmail_quote">Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:</div><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On Sep 2, 2014, at 12:05 PM, Daniel Bastos wrote:<br>
<br>
> Exercise 20.1.2. Argue why the following sentences are legal<br>
> definitions:<br>
><br>
> (define (f x) (x 10))<br>
><br>
> (define (f x) f)<br>
><br>
> (define (f x y) (x 'a y 'b))<br>
><br>
> Solution. The relevant part of the grammar is the following.<br>
><br>
>  <def> = (define (<var> <var> ...<var>) <exp>)<br>
>        | (define <var> <exp>)<br>
>        | (define-struct <var> (<var> <var> ...<var>))<br>
><br>
> (*) First definition<br>
><br>
> The LHS is a list of <var>, since we find f and x as members of the<br>
> list and they're both variables. The RHS is a list consisting of a<br>
> <var> and a <num>.<br>
<br></span>Small correction. Let's not call (x 10) a list. It's an application. '(x 10) would be a list and this one character is critical.<br></blockquote><div><br></div><div>Indeed. Here's a full rewrite for completeness. (Thanks!)</div><div><br></div><div><div>Exercise 20.1.2. Argue why the following sentences are legal</div><div>definitions:</div><div><br></div><div>(define (f x) (x 10))</div><div><br></div><div>(define (f x) f)</div><div><br></div><div>(define (f x y) (x 'a y 'b))</div><div><br></div><div>Solution. The relevant part of the grammar is the following.</div><div><br></div><div>  <def> = (define (<var> <var> ...<var>) <exp>)</div><div>        | (define <var> <exp>)</div><div>        | (define-struct <var> (<var> <var> ...<var>))</div><div><br></div><div>(*) First definition</div><div><br></div><div>The LHS is a list of <var>, since we find f and x as members of the</div><div>list and they're both variables. The RHS is an application of the form </div><div>(<var> <num>), which makes up an <exp>, satisfying the first form</div><div>of <def>. In other words,</div><div><br></div><div>  (define (<var> <var>) (<var> <num)) =</div><div>  (define (<var> <var>) (<exp> <exp>) =</div><div>  (define (<var> <var>) <exp>).</div><div><br></div><div>Therefore it's a legal <def>.</div><div><br></div><div>(*) Second definition</div><div><br></div><div>Same LHS as the previous, so we need only check the RHS which is a</div><div><var>. <var> is a valid form of <exp>, so we have</div><div><br></div><div>  (define (<var> <var>) <var>) =</div><div>  (define (<var> <var>) <exp>).</div><div><br></div><div>Therefore it's a legal <def>.</div><div><br></div><div>(*) Third definition</div><div><br></div><div>The LHS is (<var> <var> <var>), while the RHS is (<var> <sym> <var></div><div><sym>), so we have</div><div><br></div><div>  (define (<var> <var> <var>) (<var> <sym> <var> <sym>)) =</div><div>  (define (<var> <var> <var>) (<exp> <exp> <exp> <exp>)) =</div><div>  (define (<var> <var> <var>) <exp>).</div><div><br></div><div>Therefore it's a legal <def>.</div></div></div></div></div>