CS2613/labs/L05/match.rkt

19 lines
425 B
Racket
Raw Normal View History

2022-09-27 18:09:00 -03:00
#lang racket
(define (list-length list)
(match list
[`() 0]
[(cons head tail) (cons (f head)
(list-length f tail))]))
(module+ test
(require rackunit)
(check-equal? (list-length '(1 2 3)) 3)
(check-equal? (list-length '()) 0))
(define (my-map2 f lst)
(match lst
['() '()]
[(list head tail ...) (cons (f head)
(my-map2 f tail))]))