27 lines
739 B
Common Lisp
27 lines
739 B
Common Lisp
;; Take a positive int and print that many dots
|
|
|
|
;; repetition
|
|
(defun print-dots(num-of-dots)
|
|
(do ((i 0 (+ i 1)))
|
|
((= i num-of-dots) 'done)
|
|
(format t ". ")))
|
|
;; recursion
|
|
(defun print-dots-rec(num-of-dots)
|
|
;plusp checks if it's a positivie integer above 0.0
|
|
(if (plusp num-of-dots)
|
|
(progn
|
|
(format t ". ")
|
|
(print-dots-rec(- num-of-dots 1)))))
|
|
|
|
;; Take a list and return the number of times the symbol "a" occurs in it
|
|
(defun count-a-symbols(lst)
|
|
(do ((new-lst lst (cdr new-lst))
|
|
(n 0 (+ n (if (eq (car new-lst) 'a) 1 0))))
|
|
((not new-lst) n)))
|
|
|
|
;; Now do a recursive version (which is probably easier)
|
|
(defun count-a-symbols-rec(lst)
|
|
(if lst
|
|
(+ (if (eq (car lst) 'a)1 0) (count-a-symbols-rec(cdr lst)))
|
|
1))
|