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

unused-test-ideas.lsp 1.4KB

123456789101112131415161718192021222324252627282930313233343536
  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. ; todo: add the nconc example somewhere and take care of the warning.
  15. '(define-test test-nconc
  16. "nconc like append attaches one list to the end of the other, but
  17. it does so in a more efficient, but potentially destructive way.
  18. Lisp lists are nil terminated. A symbol refers to the beginning of
  19. a list, and then progresses to find the end. 'nconc' simply takes
  20. the nil pointer at the end of the first list, and points it at the
  21. beginning of the next list."
  22. (assert-equal '(:a :b :c) (nconc '(:a :b) '(:c))) ;k
  23. (let ((abc '(:a :b :c))
  24. (xyz '(:x :y :z))
  25. (abcxyz nil))
  26. (setf abcxyz (nconc abc xyz))
  27. (assert-equal '(:a :b :c :x :y :z) abcxyz)
  28. (assert-equal '(:a :b :c :x :y :z) abc)
  29. (assert-equal '(:x :y :z) xyz)))