2011-10-18 11:52:59 +02:00

24 lines
886 B
Plaintext

;; The first three lines of this file were inserted by DrScheme. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-abbr-reader.ss" "lang")((modname u02) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
(define A (list (cons 1 empty)(list 7) 9))
(define B (cons (cons 42 empty) (list 'Hello'world'!)))
;;Contract : list-length: list >>> number
;;Purpose : calculates the length of a list. Uses recursion
;;Example : (list-length A)
;; (list-length B)
;;Implementation
(define (list-length l)
(if (empty? l) ;;if
0 ;;if
(+ 1 (list-length (first l)) (list-length (rest l)))
)
)
;;Test
(list-length A)
(list-length B)
;;(check-expect (list-length A) 3)
;;(check-expect (list-length B) 2)