-
Notifications
You must be signed in to change notification settings - Fork 4
/
launcher.scm
30 lines (27 loc) · 974 Bytes
/
launcher.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
(use posix srfi-1)
(define (usage #!optional exit-code)
(print (pathname-strip-directory (program-name)) " [ --help ] [ <example-file> ]")
(when exit-code (exit exit-code)))
(define (prompt-example)
(let* ((example-files (sort (glob (make-pathname "examples" "*.scm")) string<))
(example-indices (iota (length example-files))))
(let loop ()
(print "Select one of the examples below:")
(for-each (lambda (i ex)
(print i ". " (pathname-file ex)))
example-indices
example-files)
(display "Example number (press ENTER to abort): ")
(let ((selected-index (string->number (read-line))))
(unless selected-index (exit 0))
(if (memq selected-index example-indices)
(list-ref example-files selected-index)
(loop))))))
(let ((args (command-line-arguments)))
(print args)
(when (member "--help" args) (usage 0))
(set! *logic-file*
(if (null? (cdr args))
(prompt-example)
(cadr args)))
(load "lib/core.scm"))