-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathp70b.lisp
27 lines (25 loc) · 810 Bytes
/
p70b.lisp
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
;;;; (*) Check whether a given expression represents a multiway tree
;;;;
;;;; Write a function istree which succeeds if and only if its
;;;; argument is a Lisp expression representing a multiway tree.
;;;;
;;;; Example:
;;;; * (istree '(a (f g) c (b d e)))
;;;; T
(in-package :99-problems)
(defun is-mw-tree (list)
(cond ((null list) nil)
((symbolp list) t)
((listp list)
(and (> (length list) 1)
(symbolp (car list))
(loop for child in (cdr list) always (is-mw-tree child))))
(t nil)))
(define-test is-mw-tree-test
(assert-true (is-mw-tree 'a))
(assert-true (is-mw-tree '(a b)))
(assert-true (is-mw-tree '(a (f g) c (b d e))))
(assert-false (is-mw-tree '()))
(assert-false (is-mw-tree '((a b) c)))
(assert-false (is-mw-tree '(a)))
(assert-false (is-mw-tree '(a (b) c))))