Download presentation
Presentation is loading. Please wait.
1
CSC 160 Computer Programming for Non-Majors Syntax Rules Prof. Adam M. Wittenstein Wittenstein@adelphi.eduhttp://www.adelphi.edu/~wi16133/csc160/
2
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).
3
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.
4
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.
5
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.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.