As always an unreadable or unclear answer is a wrong answer.
Expressions
Enter the following expressions into the clisp and write the results. If an expression is entered and nothing happens, check your parentheses!
2. (+ (* 3 12) 10)
3. (+ 2 4 6 8)
4. (setq x 12)
5. (setq y 20)
6. (* (- y x) (+ x y))
7. (setq z (+ x y))
8. z
9. (setq ans (+ z (* x 2)))
10. ans
11. (> 50 43)
12. (<= 3 53)
13. (setq one 5)
14. (setq two 10)
15. (= one 5)
16. (= two (* 2 one))
17. (setq name 'george)
18. (eq name 'george)
19. (eq name name)
20. (eq 'name 'george)
21. (and (= one 5) (eq? name 'george))
22. (or (= one 5) (eq? name 'george))
23. (not (= one 1))
1. (cons 'a '(b c))
(cons '(a) '(b c))
(cons 'a 'b)
(cons 'a (cons 'b '() ))
2. (equal (+ 4 5 6) (+ 6 5 4))
(equal 5 'five)
(equal (car '(a b c)) 'a)
3. (equal (+ 3 2) 5)
(equal '(1 2 3) '(1 (2 3)))
4. (null '())
(null '(1 2))
5. (car (cons 'a '(b c)))
(cdr (cons 'a '(b c)))
(cadr (cons 'a '(b c)))
A list data structure is central to Lisp as an abstract data type. A list is formed by enclosing any number of items within matching left and right parentheses. Write the resulting list for each expression shown below.
2. (setq two (cons 'a (cons 'b 'c)))
4. two
5. (setq rslt1 (car one))
6. (setq rslt2 (car two))
7. (setq rslt3 (caddr one))
8. (setq rslt4 (caddr two)) ----Why
error??
9. (setq lst (cons (cons 'a '()) (cons 'b (cons 'c '()))))
10. (setq get-a (car (car (cdr '(b (a c) d)))))
11. (setq get-b (car (cdaddr '(z (y) (x b) (a)))))
12. (setq make-new (cons (car '(a b c)) (cdr '(1 2 3))))
13. (setq ans1 (equal (car '(a b)) (car (cdr '(b a)))))
14. (setq ans2 (equal (cons 'a '(b c))
16. (atom (car lst))
17. (atom (caar lst))
Using the symbols one and two and the procedure cons, we can construct the list object
(one (two three four))
(one (two three) four)
((one two) (three four))
((b a) (c d))
(((a)))
((d c) (a) b)
The most widely used LISP syntactic form for conditional execution is cond which has the following syntax:
(You may use lists from the above list section to fill in the following cond-construct.)