1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(use-modules (ice-9 match)
(srfi srfi-1))
(define (last lst)
(match lst
(() '())
((x) x)
((head . tail) (last tail))))
(define rest cdr)
(define (last* lst)
(cond
((null? lst) '())
((= (length lst) 1) (first lst))
(else
(last* (rest lst)))))
(define (last** lst)
(cond
((null? lst) '())
((null? (rest lst)) (first lst))
(else
(last** (rest lst)))))
(last '("hello" "world" "alligator"))
(last* '("hello" "world" "alligator"))
(last** '("hello" "world" "alligator"))