![]() |
![]() |
|
home—info—lectures—exams—hws—archive
Due Oct.22 (Wed). Turn in hardcopy and (on WebCT) a file with running code.
(10pts) Here is a grammar for a hypothetical language, N0:
Expr ::= Number | Var | ParenExpr | BinExpr | IfZExpr ParenExpr ::= ( Expr ) BinExpr ::= ( Expr BinOp Expr ) IfZExpr ::= if Expr is0 then Expr else Expr ; BinOp ::= plus | minus | times |
For each of the following, either give a parse tree,
or give a brief motivation of why the string is not a valid N0
(check-expect (subst 'apple 'dell (list 'orange 'apple 'banana))
(list 'orange 'dell 'banana))
(check-expect (subst 'apple 'dell (list 'orange 'banana))
(list 'orange 'banana))
(check-expect (subst 'apple 'dell (list 'apple 'orange 'apple 'apple 'banana))
(list 'dell 'orange 'dell 'dell 'banana))
|
; string-append* : (listof string?) -> string?
; Return a string with *all* the elements of `strs` appended, left-to-right.
;
(define (string-append* strs)
(cond [(empty? strs) ""]
[(cons? strs) (string-append (first strs)
(string-append* (rest strs))))))
;>>>TODO:
(define (string-append*-v2 data)
)
(check-expect (string-append*-v2 empty) "")
(check-expect (string-append*-v2 (list "hi") "hi")
(check-expect (string-append*-v2 (list "hi" "there")) "hithere")
(check-expect (string-append*-v2 (list "aye " "bee " "sea ")) "aye bee sea ")
|
(check-expect (count-blues 'unknown) 0) (check-expect (count-blues lieselotte) 0) (check-expect (count-blues kristin) 1) (check-expect (count-blues ian) 3) |
(check-expect (baby-boomers 'unknown) empty) (check-expect (baby-boomers lieselotte) empty) (define aa (make-child "aa" 1950 'gray 'unknown 'unknown)) (check-expect (baby-boomers aa) (list "aa")) (check-expect (baby-boomers (make-child "bb" 1970 'green aa ian)) (list "aa")) |
(5pts) (Hypothetical situtation:) Imagine that a genetic test shows that somebody's eyes are not quite blue (a recessive gene), but actually (say) azure (a dominant gene).
Write a function
(check-expect (blue->azure 'unknown) 'unknown)
(check-expect (blue->azure lieselotte) lieselotte)
(check-expect (blue->azure kristin)
(make-child "Kristin" 1943 'azure lieselotte 'unknown))
(check-expect (blue->azure ian)
(make-child "Ian"
1966
'azure
(make-child "Kristin" 1943 'azure lieselotte 'unknown)
(make-child "Gordon"
1938
'brown
(make-child "Lois" 1899 'brown 'unknown 'unknown)
(make-child "George" 1894 'azure 'unknown 'unknown))))
|
(5pts) Imagine further, that anybody with green eyes can't have had an azure-eyed ancestor.
Write a function
(check-expect (blue->azure/stop-at-green 'unknown) 'unknown)
(check-expect (blue->azure/stop-at-green lieselotte) lieselotte)
(check-expect (blue->azure/stop-at-green kristin)
(make-child "Kristin" 1943 'azure lieselotte 'unknown))
(check-expect (blue->azure/stop-at-green
(make-child "cc"
2000
'orange
kristin
(make-child "bb" 1970 'green aa ian)))
(make-child "cc"
2000
'orange
(make-child "Kristin" 1943 'azure lieselotte 'unknown)
(make-child "bb" 1970 'green aa ian)))
|
1
2Well, you can make idiomatic translations e.g. a java
variable “
home—info—lectures—exams—hws—archive
| ©2009, Ian Barland, Radford University Last modified 2009.Dec.01 (Tue) |
Please mail any suggestions (incl. typos, broken links) to ibarland |
![]() |