Fork of https://github.com/google/lisp-koans so that I could go through them. THIS CONTAINS ANSWERS.

atoms-vs-lists.lsp 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ;; Copyright 2013 Google Inc.
  2. ;;
  3. ;; Licensed under the Apache License, Version 2.0 (the "License");
  4. ;; you may not use this file except in compliance with the License.
  5. ;; You may obtain a copy of the License at
  6. ;;
  7. ;; http://www.apache.org/licenses/LICENSE-2.0
  8. ;;
  9. ;; Unless required by applicable law or agreed to in writing, software
  10. ;; distributed under the License is distributed on an "AS IS" BASIS,
  11. ;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. ;; See the License for the specific language governing permissions and
  13. ;; limitations under the License.
  14. (define-test test-list-or-atom
  15. "Lists in lisp are forms beginning and ending with rounded parentheses.
  16. Atoms are symbols, numbers, or other forms usually separated by
  17. white-space or parentheses. The function 'listp' will return true iff
  18. the input is a list. The function 'atom' will return true iff the
  19. input is an atom."
  20. (true-or-false? ___ (listp '(1 2 3)))
  21. (true-or-false? ___ (atom '(1 2 3)))
  22. (true-or-false? ___ (listp '("heres" "some" "strings")))
  23. (true-or-false? ___ (atom '("heres" "some" "strings")))
  24. (true-or-false? ___ (listp "a string"))
  25. (true-or-false? ___ (atom "a string"))
  26. (true-or-false? ___ (listp 2))
  27. (true-or-false? ___ (atom 2))
  28. (true-or-false? ___ (listp '(("first" "list") ("second" "list"))))
  29. (true-or-false? ___ (atom '(("first" "list") ("second" "list")))))
  30. (define-test test-empty-list-is-both-list-and-atom
  31. "the empty list, nil, is unique in that it is both a list and an atom"
  32. (true-or-false? ___ (listp nil))
  33. (true-or-false? ___ (atom nil)))
  34. (define-test test-keywords
  35. "symbols like :hello or :like-this are treated differently in lisp.
  36. Called keywords, they are symbols that evaluate to themselves."
  37. (true-or-false? ___ (equal :this-is-a-keyword :this-is-a-keyword))
  38. (true-or-false? ___ (equal :this-is-a-keyword ':this-is-a-keyword)))