;'<<SPEC'
<!--
Copyright (c) 2012-2024, Chris Pressey, Cat's Eye Technologies.
This file is distributed under a 2-clause BSD license. See LICENSES/ dir.
SPDX-License-Identifier: LicenseRef-BSD-2-Clause-X-Robin
-->
### `prefix?` ###
-> 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))))