Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Exercises after The Little Schemer chapter 2
;; write the function "2nd" that given a list of atoms
;; returns the second atom
;; return values for illegal cases are up to you
;; try to be reasonable though
(define 2nd
(lambda (lat)
;; ...
))
;; then write the results for these applications by running your function
(2nd '()) ;; ???
(2nd '(a)) ;; ???
(2nd '(a b c)) ;; ???
(2nd '((a) b c) ;; ???
;; don't limit yourself to these inputs though, try to think about possible inputs your function
;; might receive: it should work with lists of atoms but it might happen that the input
;; is not what you expect
;; write the function "last" that given a list of atoms
;; returns the last atom, you can only use recursion, car and cdr
;; do not bother checking for lists of S-exp, assume
;; you will always get list of atoms
(define last
(lambda (lat)
;; ...
))
;; then write the results for these applications
(last '())
(last '(1 2 3 4))
(last '(a))
(last '(Moreno e Paola))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.