[racket] missing solution 20.1.2 ex:syn-funcs

From: Daniel Bastos (dbastos at toledo.com)
Date: Tue Sep 2 12:05:18 EDT 2014

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>. That composes 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>.

Posted on the users mailing list.