sicp-solutions/chapter-2/ex-2.17.scm

7 lines
182 B
Scheme

#lang sicp
(define (last-pair list)
(cond ((null? list) (error "Can't get last element of empty list"))
((null? (cdr list)) list)
(else (last-pair (cdr list)))))