Scheme: Conceptual

Some problems are marked as malformed list problems, feel free to do them if you read my section on malformed lists, otherwise you should probably skip them.

WHat would scheme display?

>>> 17
______
>>> (+ 1 2)
______
>>> ‘(+ 1 2)
______
>>> (- (+ 3 3) (/ 4 2))
______
>>> (define x 3)
______
>>> (* x x)
______
>>> (define (f x) (if (= x 0) 0 1))
______
>>> (f x)
______
>>> ((lambda (x) (+ x 1)) 7)
______
>>> (((lambda (x) (lambda (y) (+ x y))) 3) 4)
______
>>> (cons 1 2)
(malformed list problem)
______
>>> (cons 3 (cons 4 (cons 5 nil)))
______
>>> (cons 1 (cons 2 (cons 3 4)))
(malformed list problem)
______
>>> (cons 1 (cons 3 4) (cons 2 nil))
(malformed list problem)
______
>>> (list 1 (list 2 (list 3 4)))
______
>>> (cons 1 (cons (cons 2 (cons 3 4)) (cons (cons 5 (cons 6 nil)) (cons 7 nil))))
(malformed list problem)
______

Scheme Lists

Draw out box and pointer and write out the cons statement that will produce the following lists (if possible), or prove why the list is not possible.

(6 7 8 9)

(8 3 4 7 . 5 6 9) (malformed list problem)

(8 3 4 7 (5 6 9))

(5 7 (9 10) (11 12) 13)

COde Writing

Write a function in scheme that will take in a list of numbers and remove all even numbers.
> (define lst '(3 5 2 6 7))
> (odd-only lst)
(3 5 7)
(define (odd-only lst)
    (if ______
        ______
        (if ______
            ______
            ______ ) ) )

Write a function in scheme that will take in a list and count the number of times a value (x) appears in it.
> (define lst '(3 7 2 6 7 8 7))
> (x-counter lst 7)
3
(define (x-counter lst x)
    (if ______
        ______
        (if ______
            ______
            ______ ) ) )