-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprefix-p.robin
40 lines (30 loc) · 980 Bytes
/
prefix-p.robin
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
32
33
34
35
36
37
38
39
40
;'<<SPEC'
-> Tests for functionality "Evaluate Robin Expression (with List)"
`prefix?` evaluates its first and second arguments to obtain lists.
It then evaluates to `#t` if the first list is a prefix of the second
list, `#f` otherwise. A list A is a prefix of a list B if A is `empty?`,
or the head of A is `equal?` to the head of B and the tail of A is a
prefix of the tail of B.
| (prefix? (list 1 2 3) (list 1 2 3 4 5 6))
= #t
| (prefix? (list 1 2 5) (list 1 2 3 4 5 6))
= #f
| (prefix? () (list 1 2 3 4 5 6))
= #t
| (prefix? () (literal schpritz))
= #t
| (prefix? (list 1 2 3) (list 1 2 3))
= #t
| (prefix? (list 1 2 3 4) (list 1 2 3))
= #f
'<<SPEC'
(define prefix? (fun (la lb)
(bind prefix?-r (fun (self la lb)
(if (empty? la)
#t
(if (empty? lb)
#f
(if (equal? (head la) (head lb))
(self self (tail la) (tail lb))
#f))))
(prefix?-r prefix?-r la lb))))