CSC 160 Computer Programming for Non-Majors Syntax Rules Prof. Adam M. Wittenstein
Syntax Rules # Any picture is a legal expression; its value is itself. 2. A legal expression is the following in the given order: --a left-parenthesis --a function name --one or more legal expressions --a right-parenthesis Its value is the resulting picture (what you get by applying the named function to the values of the smaller expressions inside it).
Syntax Rule #3 ► Any identifier, if already defined, is a legal expression. *In an empty DrRacket file, ball is not a legal expression. *In a file containing (define ball ), ball is a legal expression.
Syntax Rule #4: Defining a Variable ► To define a variable: (define var-name its-value) ► That is, a legal expression is: a left-parenthesis, then the word define, then a previously-undefined name, then a legal expression, then a right-parenthesis.
Syntax Rule #5 ► As described in words on page 63, to define a function, you need to type: (define (func-name param-name …) expression)) expression)) ► The first one, func-name, needs to be an identifier that has not been used before. ► The others, param-names, can be any identifier, as long as you do not use the same one twice in the same function.