University of Virginia Computer Science CS150: Computer Science, Fall 2005 |
(none) 5 September 2005 |
The length of an empty list is zero. So, when the list is null, we should evaluate to 0.
The length of the list, (cons el lst) is one more than the length of the list lst. So, when the list is a pair of an element and a list, we should evaluate to (+ 1 (length (cdr lst)))
(define (length lst) (if (null? lst) ___________________________ ; what to do for empty list ______________________________________ ; what to do for pair list ))
(define (sumlist lst) )
Examples:
> (map car (list (cons 1 2) (cons 2 3)))
(1 2)
> (map + null)
()
> (map (lambda (x) (* x x)) (list 1 2 3))
(2 4 6)
> (map (lambda (el) (> el 3)) (list 2 4 6))
__________________
> (map (lambda (el) (+ 1 el)) (list 1 2 3))
__________________
(define (map f lst) )The analyze-flop-situation proceudre from PS2 uses map:
(map (lambda (turn-card) (analyze-turn-situation hole1 hole2 (cons turn-card community))) current-deck)))What is this expression doing?
The choose-n procedure from PS2 uses map:
(map (lambda (clst) (cons (car lst) clst)) (choose-n (- n 1) ;;; all possibilities using the first element (cdr lst)))))))What is this expression doing?
"); print ( $res[$first] ) ; print (" |
CS 150: Computer Science University of Virginia |
evans@virginia.edu Using these Materials |