[racket] missing solution 20.1.1 ex:sem-funcs

From: Daniel Bastos (dbastos at toledo.com)
Date: Tue Sep 2 11:45:23 EDT 2014

A candidate for a solution.

Exercise 20.1.1. Assume the Definitions window in DrScheme contains
(define (f x) x). Identify the values among the following expressions:

(1) (cons f empty)
(2) (f f)
(3) (cons f (cons 10 (cons (f 10) empty)))

Explain why they are values and why the remaining expressions are not
values.

Solution. First we consider (1). Here's the relevant part of the
grammar.

  <lst> = empty | (cons <val> <lst>)

  <val> = <boo> | <sym> | <num> | empty | <lst>
  | <var> (names of defined functions)
  | <prm>

So (1) is a value because it is <lst> of the form (cons <var> empty),
where f is <var> because it is a defined function.

Let's consider (3) before (2). (3) is a list of either <var> or <num>,
so (3) is <val> as well.

Now we consider (2). Here's the relevant part of the grammar.

  <exp>       =    <var>
  | <prm>
  | (<exp> <exp> ...<exp>)

So (2) is (<var> <var>), a list of expressions, which is an <exp>, not
a <val>. So (2) is not a value, although it's a legal expression.

Posted on the users mailing list.