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. > (*) 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 > > (*) Third definition > > The LHS is (<var> <var> <var>), while the RHS is (<var> <sym> <var> > <sym>), > > Therefore it's a legal <def>. OKAY. ____________________ Racket Users list: http://lists.racket-lang.org/users