Skip to content

Instantly share code, notes, and snippets.



Created May 30, 2009
What would you like to do?
this script enables gosh to call the external commands as a function without any definitions.
#!/usr/bin/env gosh
(use gauche.process)
(use srfi-1)
(use srfi-13)
(define (tree-filter f tree)
(define (rec t s)
(cond [(null? t) s]
[(pair? t) (rec (car t) (rec (cdr t) s))]
[(f t) (cons t s)]
[else s]))
(rec tree '()))
(define (command? sym)
(and (symbol? sym)
(string=? (string-take (symbol->string sym) 1) "!")))
(define (command-name com)
(string->symbol (string-drop (symbol->string com) 1)))
(define (exec-command command . args)
(process-output->string-list (cons command args)))
(define-macro (with-command . body)
(let1 commands (delete-duplicates (tree-filter command? body) eq?)
`(let ,(map (lambda (command)
(cut exec-command ',(command-name command) <...>)))
(define (main args)
(define (reader)
(let1 exp (read)
(if (eof-object? exp)
`(with-command ,exp))))
(read-eval-print-loop reader)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.