正在加载图片...
Scheme expression evaluation Scheme programming consists of writing and evaluating expressions. The simplest name of an arithmetic operator(things like+, ",")followed by one or more other Ofthe expressions are things like numbers. More complex arithmetic expressions consist expressions, all of this enclosed in parentheses. So the Scheme expression for adding 3 and 4 is(+3 4)rather than 3+4 While in the *scheme* buffer, try typing a simple expression such as 1375 Typing this expression inserts it into the buffer. To ask Scheme to evaluate it, we type c x C-e, which causes the interpreter to read the expression immediately preceding the cursor, evaluate it(according to the kinds of rules described in lecture)and print out the esult which is called the expression's"value". Try this An expression may be typed on a single line or on several lines, the Scheme interpreter ignores redundant spaces and line breaks. It is to your advantage to format your work so that you(and others) can read it easily. It is also helpful in detecting errors introduced by incorrectly placed parentheses. For example, the two expressions (*5(+2(/42)(/83))) (*5(+2(/42))(/83)) look deceptively similar but have different values Properly indented, however, the difference is obvious (*5 (+2 /42) (/83))) (+2 (/42)) Edwin provides several commands that" pretty-print your code, indenting lines to refle the inherent structure of the Scheme expressions(see Section B 2. 1 of the Don t Panic manual ) Make a habit of typing c-i at the end of a line, instead of RETURN, when enter Scheme expressions, so that the automatic indentation takes place. Tab and M other useful edwin formatting commands While the Scheme interpreter ignores redundant spaces and carriage returns, it does not ignore redundant parentheses! Try evaluatingScheme Expression Evaluation Scheme programming consists of writing and evaluating expressions. The simplest expressions are things like numbers. More complex arithmetic expressions consist of the name of an arithmetic operator (things like +, -, *) followed by one or more other expressions, all of this enclosed in parentheses. So the Scheme expression for adding 3 and 4 is (+ 3 4) rather than 3 + 4. While in the *scheme* buffer, try typing a simple expression such as 1375 Typing this expression inserts it into the buffer. To ask Scheme to evaluate it, we type C￾x C-e, which causes the interpreter to read the expression immediately preceding the cursor, evaluate it (according to the kinds of rules described in lecture) and print out the result which is called the expression's “value”. Try this. An expression may be typed on a single line or on several lines; the Scheme interpreter ignores redundant spaces and line breaks. It is to your advantage to format your work so that you (and others) can read it easily. It is also helpful in detecting errors introduced by incorrectly placed parentheses. For example, the two expressions (* 5 (+ 2 (/ 4 2) (/ 8 3))) (* 5 (+ 2 (/ 4 2)) (/ 8 3)) look deceptively similar but have different values. Properly indented, however, the difference is obvious. (* 5 (+ 2 (/ 4 2) (/ 8 3))) (* 5 (+ 2 (/ 4 2)) (/ 8 3)) Edwin provides several commands that “pretty-print” your code, indenting lines to reflect the inherent structure of the Scheme expressions (see Section B.2.1 of the Don't Panic manual). Make a habit of typing C-j at the end of a line, instead of RETURN, when you enter Scheme expressions, so that the automatic indentation takes place. Tab and M-q are other useful Edwin formatting commands. While the Scheme interpreter ignores redundant spaces and carriage returns, it does not ignore redundant parentheses! Try evaluating ((+ 3 4))
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有