Prev | Current Page 496 | Next

Carl Reynolds and Paul Tymann

"Schaum's Outline of Principles of Computer Science"


expr --> term { ( + | - ) term }
term --> factor { ( * | / ) factor }
factor --> ex { ** ex }
ex --> ( expr ) | id
ANSWERS TO REVIEW QUESTIONS 189
4.8 What does this Scheme function do?
(define whatsThis
(lambda (n)
( cond((null? n) 0)
((null? (cdr n)) (car n))
((> (car n) (whatsThis (cdr n))) (car n))
( else (whatsThis (cdr n)))
)))
The function whatsThis returns the largest element in a list:
> (whatsThis (list 1 2 4 5 3))
5
>
4.9 Give an example of an irregularity in a language with which you are familiar.
In Java, one can test for the equality of two variables of a primitive type, such as int x and int y, using
the double equal sign ( == ) operator, but objects must be compared using the equals() method.
The Java switch statement takes only ???integral??? data types (e.g., int, char, short, byte) for case
values, and many times it would be convenient to use Strings or other objects as case labels.
Return values in Visual BASIC look like assignments.
In C, a function cannot return an array.
Etc.
4.10. Would it ever make sense to write a program in one language, planning from the beginning to rewrite
the program later in a different language? Give an example of a situation in which such a plan might
make sense, and not simply result in wasted time and effort.


Pages:
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
Hotel spa bilety lotnicze Noclegi Władysławowo koszule korporacyjne Apartamenty nad morzem