toys.scm 890 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/home/joshua/.guix-profile/bin/guile \
  2. -e main -s
  3. !#
  4. ;; for read-line
  5. (use-modules (ice-9 rdelim))
  6. (define (string-to-bool string)
  7. (if (string=? string "y")
  8. #t
  9. #f))
  10. (define* (ask-question question bool #:key
  11. commentary)
  12. (display question)
  13. (display "\n")
  14. (let ([answer (read-line)])
  15. (if (eq? bool (string-to-bool answer))
  16. (display "Correct\n")
  17. (display "Wrong\n")))
  18. (display "\n")
  19. (when commentary
  20. (display commentary)
  21. (display "\n")))
  22. (define (atom? arg)
  23. (not (list? arg)))
  24. (define (main args)
  25. (ask-question "Is this an atom? atom\n" #t)
  26. (ask-question "Is this an atom? 1234" #t)
  27. (ask-question "Is this a list? (atom)" #t)
  28. (ask-question "Is this an atom? (1 2 3)" #f)
  29. (ask-question "Is this an list? ()" #t
  30. #:commentary "Yes. This is a special list, called the empty list.")
  31. )