New to lisp. I was wondering why I get this error. "1 is not of type LIST." -


(defun fizzbuzz(lst emptylist)     (if (= (mod (car lst) 3) 0)     (fizzbuzz (cdr lst) (append emptylist (list(append (car lst) '(fizz)))))     )     (if (= (mod (car lst) 5) 0)     (fizzbuzz (cdr lst) (append emptylist (list(append (car lst) '(buzz)))))     )     (if (and (= (mod (car lst) 3) 0) (= (mod (car lst) 5) 0))     (fizzbuzz (cdr lst) (append emptylist (list(append (car lst)      '(fizzbuzz)))))     )     (fizzbuzz (cdr lst) (append emptylist (car lst)))          

)

(fizzbuzz '(1 2 3 4 5) '(0)) 

keep in mind new. professor wants practice recursion using lisp. program supposed add numbers arent divisible 5 or 3 list. divisible 3 inserted list (3 fizz). divisible 5: (5 buzz). divisible both (15 fizzbuzz). how return new list function? why getting error listed in title of post?

you getting error because of last expression (fizzbuzz (cdr lst) (append emptylist (car lst))).

first round (fizzbuzz '(1 2 3 4 5) '(0)) becomes (fizzbuzz '(2 3 4 5) '(0 . 1)) , try (append '(0 . 1) 2). append can handle dotted list , atom last argument, cannot append dotted list when not last argument. supposed 1?

also know have no stop condition , separate if run unconditionally other if 15 first recurse in first, throw away result. recurse in second throw value away well. unconditionally recurse in last. i'm pretty sure want 1 of them called , if-elseif-else , lisp version of cond:

(cond    (p1 c1)      ; if p1 c1   (p2 c2 c2b)  ; elseif p2 c2 , c2b (last expression becomes result)   (p3 c3)      ; elseif p3 c3   (t  a4))     ; else a4 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -