hello 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #! /usr/local/bin/guile -s
  2. !#
  3. ;;; Commentary:
  4. ;;; This is the famous Hello-World-program, written for Guile. It is a
  5. ;;; little bit enhanced in that it understands the command line options
  6. ;;; `--help' (-h) and `--version' (-v), which print a short usage
  7. ;;; description or version information, respectively.
  8. ;;; Author: Martin Grabmueller
  9. ;;; Date: 2001-05-29
  10. ;;; Code:
  11. (use-modules (ice-9 getopt-long))
  12. ;; This is the grammar for the command line synopsis we expect.
  13. ;;
  14. (define command-synopsis
  15. '((version (single-char #\v) (value #f))
  16. (help (single-char #\h) (value #f))))
  17. ;; Display version information.
  18. ;;
  19. (define (display-version)
  20. (display "hello 0.0.1\n"))
  21. ;; Display the usage help message.
  22. ;;
  23. (define (display-help)
  24. (display "Usage: hello [options...]\n")
  25. (display " --help, -h Show this usage information\n")
  26. (display " --version, -v Show version information\n"))
  27. ;; Interpret options, if --help or --version was given, print out the
  28. ;; requested information and exit. Otherwise, print the famous
  29. ;; message.
  30. ;;
  31. (define (main options)
  32. (let ((help-wanted (option-ref options 'help #f))
  33. (version-wanted (option-ref options 'version #f)))
  34. (if (or version-wanted help-wanted)
  35. (begin
  36. (if version-wanted
  37. (display-version))
  38. (if help-wanted
  39. (display-help)))
  40. (begin
  41. (display "Hello, World!") (newline)))))
  42. ;; Call the main program with parsed command line options.
  43. ;;
  44. (main (getopt-long (command-line) command-synopsis))
  45. ;; Local variables:
  46. ;; mode: scheme
  47. ;; End: