;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname week2_f_full) (read-case-sensitive #t) (teachpacks ((lib "image.ss" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.ss" "teachpack" "2htdp"))))) (define mylistofnumbers (cons 4 (cons 3 empty))) ; a list-of-numbers is either: ; - empty ; - (cons number list-of-numbers) ; template: ; (cond [(empty? lon) ...] ; [(cons? lon) ...(first lon) ...(fun-for-lon (rest lon))...]) ; ) ; count : list-of-numbers -> number ; returns the number of numbers in a list (define (count lon) (cond [(empty? lon) 0] [(cons? lon) (+ 1 (count (rest lon)))]) ) (check-expect (count mylistofnumbers) 2) (check-expect (count (cons 4 (cons 3 (cons 2 (cons 1 empty))))) 4)