guess-number.scm 681 B

12345678910111213141516171819202122232425262728
  1. #!/bin/guile \
  2. -e main -s
  3. !#
  4. ;; create a random number cool!
  5. (define number (random 100 (random-state-from-platform)))
  6. (define (main args)
  7. (display "I have a favorite number between 1 and 100. Your Guess? ")
  8. (display "\n")
  9. (display "\n")
  10. ;; create a named let that loops until you guess the number correctly.
  11. (let loop ((guess (read)) (number number))
  12. (cond
  13. ((< guess number)
  14. (begin
  15. (display "Guess higher")
  16. (display "\n")
  17. (loop (read) number)))
  18. ((> guess number)
  19. (display "Guess lower")
  20. (display "\n")
  21. (loop (read) number))
  22. (else
  23. (begin
  24. (display "Correct!")
  25. (display "\n"))))))