- Exercise 2.1.1(a) val it = 7 ; int Exercise...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Exercise 2.1.1(a) val it = 7 ; int Exercise 2.1.1(c) val it = 2 : int We group operators from the left, so we first evaluate 11 div 2 , or 5, and then evaluate 5 mod 3 , which is 2. Exercise 2.1.1(e) val it = false : bool The andalso groups its operands before the orelse . Thus, the whole expression is grouped 3>4 orelse (5<6 andalso (not 7<>8)) Exercise 2.1.1(g) val it = 294 : int Note that AB in hexadecimal is 171 in decimal. Exercise 2.1.2(a) The / operator applies only to reals, not integers. Use div instead. Exercise 2.1.2(c) The and operator has a meaning not discussed in Section 2.1; it cannot be applied to boolean values. Use andalso instead. Exercise 2.1.2(e) A real number needs to have digits both before and after the decimal point. Instead of 4., use 4.0. Exercise 2.1.2(g) The concatenation operator ^ applies to strings, not characters. "a"^"b" would be correct. Exercise 2.1.2(i) Real numbers may not be compared using = or <> . A legal equivalent would be 1.0 <= 2.0 andalso 2.0 <= 1.0
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Exercise 2.1.3 There are many ways to break the string. Here is one: "\t\"\\\\\\\" stands for the double-quote \ \character, \\\n\t\\which otherwise \ \would be interpreted \\\n\t\\as the \ \string ender.\"" If you didn't ``get this,'' now that you see the tricks, try creating a string that will print the four displayed lines above. Exercise 2.1.4(a) if E then true else F Exercise 2.2.1(a) floor(123.45) works. We could also use trunc or round as the operator in this example. Exercise 2.2.1(d) ceil(~123.45) works. Operators trunc and round would also work in this case. Exercise 2.2.1(e) ord(#"Y") Exercise 2.2.1(g) real(ord(#"N")) Exercise 2.2.2(a) The function ceil requires a real argument, e.g., ceil(4.0) Exercise 2.2.2(c) The argument of chr must be in the range 0 to 255. Thus, 256 is not an acceptable argument. It is not clear how to fix this expresion, since there is no obvious intent. Exercise 2.2.2(e) Function ord must take a character as an argument. Perhaps chr(#"3") was meant. The result would be 51, the ASCII code for character #"3". Exercise 2.2.2(h) Again, ord requires a character as argument. Now, probably ord(#"a") was meant. Exercise 2.3.1(a) An alphanumeric identifier suitable for ordinary values.
Background image of page 2
Exercise 2.3.1(c) Not an identifier. The comma is not permitted in identifiers of any kind. Exercise 2.3.1(e) Not an identifier. The characters of symbolic and alphanumeric identifiers may not be combined in a single identifier. a<=b is interpreted as a sequence of three identifiers: a, <=, and b. Exercise 2.3.1(g) Not an identifier for the same reason as Exercise 2.3.1(e). Exercise 2.4.1(a) 4 Exercise 2.4.1(c) [4,5] Exercise 2.4.1(e) "foo" Exercise 2.4.1(g) ["c", "o", "b", "o", "l"] Exercise 2.4.2(a) There is no fourth component. The number following # must be 1, 2, or 3 for this tuple. Exercise 2.4.2(c)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/13/2012 for the course CS 91.531 taught by Professor Giam during the Fall '09 term at UMass Lowell.

Page1 / 38 - Exercise 2.1.1(a) val it = 7 ; int Exercise...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online