50 likes | 64 Views
CSC 160 Computer Programming for Non-Majors Syntax Rules. Prof. Adam M. Wittenstein Wittenstein@adelphi.edu http://www.adelphi.edu/~wittensa/csc160/. Syntax Rules #1-2. 1. Any picture is a legal expression; its value is itself. 2. A legal expression is the following in the given order:
E N D
CSC 160Computer Programmingfor Non-MajorsSyntax Rules Prof. Adam M. Wittenstein Wittenstein@adelphi.edu http://www.adelphi.edu/~wittensa/csc160/
Syntax Rules #1-2 1. 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 DrScheme file, ballis not a legal expression. *In a file containing (define ball ), ballis 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 58, to define a function, you need to type: (define (func-name param-name …) 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.