-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.scm
45 lines (36 loc) · 965 Bytes
/
example.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(import (chicken format)
(chicken process-context)
(chicken string))
(import commands)
;;;
;;; Definition of commands
;;;
(define-command 'concat
#<#EOF
concat arg1 ...
Concatenate all given arguments.
EOF
(lambda (args)
(print (string-intersperse args ""))))
(define-command 'reverse
#<#EOF
reverse arg1 ...
Reverse all given arguments.
EOF
(lambda (args)
(print (string-intersperse (reverse args)))))
;;;
;;; Code of the main dispatcher program
;;;
;;; Command line parsing and command dispatching
(let ((args (command-line-arguments)))
(when (null? args)
(show-main-help 1))
(when (member (car args) (help-options))
(show-main-help 0))
(let ((cmd-name (string->symbol (car args))))
(or (and-let* ((command (alist-ref cmd-name (commands))))
((command-proc command) (cdr args)))
(begin
(fprintf (current-error-port) "Invalid command: ~a\n" cmd-name)
(exit 1)))))