calc.scm 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/home/joshua/.guix-profile/bin/guile \
  2. -e main -s
  3. !#
  4. ;; This is a simple pre-fix calculator. Things it can calculate
  5. ;; + 3 4
  6. ;; + 3 - 5 3
  7. ;; use these modules to help my process the command line arguments.
  8. (use-modules (ice-9 getopt-long))
  9. ;; this will take a list and calculate the whole thing.
  10. (define (calc list)
  11. (let ([first-arg]))
  12. )
  13. (define (main args)
  14. ;;the option specification tells getopt-long how
  15. ;; to parse the command line
  16. (let* ((option-spec '((version (single-char #\v) (value #f))
  17. (help (single-char #\h) (value #f))
  18. (calc (single-char #\c) (value #t)
  19. ;; (required #t)
  20. )))
  21. ;; tell getopt-long to parse the command line and put the
  22. ;; data in options
  23. (options (getopt-long args option-spec))
  24. ;; was --help or -h used?
  25. (help-wanted (option-ref options 'help #f))
  26. (version-wanted (option-ref options 'version #f))
  27. ;; was -c or --calc used? If there was no value given,
  28. ;; then return #f
  29. (calc-wanted (option-ref options '() #f)))
  30. (if (or version-wanted help-wanted)
  31. (cond
  32. (help-wanted
  33. (display "calc [options]\n")
  34. (display "-v --version Display version\n")
  35. (display "-h, --help Display this help info\n"))
  36. (version-wanted
  37. (display "calc version 0.1\n")))
  38. (display calc-wanted))))