prerequisites.scm 759 B

12345678910111213141516171819202122232425262728293031323334
  1. ;;; =============
  2. ;;; PREREQUISITES
  3. ;;; =============
  4. (library (prerequisites)
  5. (export atom?
  6. one?
  7. pick)
  8. (import
  9. (except (rnrs base) let-values map)
  10. (only (guile)
  11. lambda* λ))
  12. (define atom?
  13. (λ (x)
  14. (and (not (pair? x))
  15. (not (null? x)))))
  16. ;; In theory we could define other things as numbers, for example
  17. ;; church numerals. The definition of ~one?~ is a layer of
  18. ;; abstraction over numbers and their representation in code.
  19. (define one?
  20. (λ (x)
  21. ;; In theory we could define other things as numbers, for
  22. ;; example church numerals.
  23. (= x 1)))
  24. (define pick
  25. (λ (n lat)
  26. (cond
  27. [(one? n) (car lat)]
  28. [else
  29. (pick (- n 1) (cdr lat))]))))