[racket] missing solution 20.1.2 ex:syn-funcs
On Mon, Sep 8, 2014 at 9:51 PM,
Matthias Felleisen <matthias at ccs.neu.edu> wrote:
On Sep 2, 2014, at 12:05 PM, Daniel Bastos wrote:
>
> > Exercise 20.1.2. Argue why the following sentences are legal
> > definitions:
> >
> > (define (f x) (x 10))
> >
> > (define (f x) f)
> >
> > (define (f x y) (x 'a y 'b))
> >
> > Solution. The relevant part of the grammar is the following.
> >
> > <def> = (define (<var> <var> ...<var>) <exp>)
> > | (define <var> <exp>)
> > | (define-struct <var> (<var> <var> ...<var>))
> >
> > (*) First definition
> >
> > The LHS is a list of <var>, since we find f and x as members of the
> > list and they're both variables. The RHS is a list consisting of a
> > <var> and a <num>.
>
> 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.
>
Indeed. Here's a full rewrite for completeness. (Thanks!)
Exercise 20.1.2. Argue why the following sentences are legal
definitions:
(define (f x) (x 10))
(define (f x) f)
(define (f x y) (x 'a y 'b))
Solution. The relevant part of the grammar is the following.
<def> = (define (<var> <var> ...<var>) <exp>)
| (define <var> <exp>)
| (define-struct <var> (<var> <var> ...<var>))
(*) First definition
The LHS is a list of <var>, since we find f and x as members of the
list and they're both variables. The RHS is an application of the form
(<var> <num>), which makes up an <exp>, satisfying the first form
of <def>. In other words,
(define (<var> <var>) (<var> <num)) =
(define (<var> <var>) (<exp> <exp>) =
(define (<var> <var>) <exp>).
Therefore it's a legal <def>.
(*) Second definition
Same LHS as the previous, so we need only check the RHS which is a
<var>. <var> is a valid form of <exp>, so we have
(define (<var> <var>) <var>) =
(define (<var> <var>) <exp>).
Therefore it's a legal <def>.
(*) Third definition
The LHS is (<var> <var> <var>), while the RHS is (<var> <sym> <var>
<sym>), so we have
(define (<var> <var> <var>) (<var> <sym> <var> <sym>)) =
(define (<var> <var> <var>) (<exp> <exp> <exp> <exp>)) =
(define (<var> <var> <var>) <exp>).
Therefore it's a legal <def>.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140915/6d6bc76e/attachment.html>