[racket] htdp: functions of section 19 violate the grammar of section 8
It makes sense, yes. I mean, the overall message. But I'm trying to
pinpoint where the grammar of section 8 tells me "no, you cannot put a
function name in an argument of an application". I read again the
entire section 8, am reading section 19 again and I still don't see
it. I'll write my argument and you'll spot a false statement
somewhere.
(By the way, I know the language Beginning Student doesn't allow a
function name to be passed as an application argument. I've checked
it.)
It's clear that a primitive cannot be passed as an argument in the
grammar of section 8. Here's my proof. An application in that grammar
is of the form (<var> <exp> ...<exp>). Since primitives do not appear
in this form, it cannot be present in an application. (We're done.)
However, any expression /can/ be used as an application argument
because an application is of the form (<var> <exp> ...<exp>). What are
the possible expressions in the grammar of section 8? It begins with
<var>. When I define a user-defined function, its name is a <var>.
Therefore, any user-defined function's name is an expression and hence
can appear in an application.
But section 20 says that "[an argument [...] is an expression, and the
class of expressions does not contain primitive operations and
function names. It does contain variables, but we agreed that they are
only those variables mentioned in variable definitions and as function
parameters."
This must be where the problem is. Where did we agree to that? I went
back to section 8 to see what a <var> is. "The first category is that
of variables, which are the names of functions and values." So a <var>
names a function such as
(define (f x) (* 2 x))
and so f should be allowed to appear as an application argument.
Doesn't that follow from the text?
Thank you!
On Wed, Sep 10, 2014 at 4:10 PM, Stephen Chang <stchang at ccs.neu.edu> wrote:
> The arguments are the <exp> ...<exp>. The function position is <var> or <prm>
>
> Essentially, the grammar in sec20 extends sec8 with the ability to:
> - pass functions and primitives, like +, as arguments, and
> - compute the applied function in the function position instead of
> always using predefined <var>s or <prm>s
>
> Does that make sense?