diff --git a/macros.scm b/macros.scm new file mode 100644 index 0000000..eacb970 --- /dev/null +++ b/macros.scm @@ -0,0 +1,3 @@ +(define-syntax _ (syntax-rules () ((_ . cmd) (run (fold (lambda (e o) (string-append o " " (->string e))) "" 'cmd))))) +(define-syntax _rl (syntax-rules () ((_rl . cmd) (cmd->list (fold (lambda (e o) (string-append o " " (->string e))) "" 'cmd) read-line)))) +(define-syntax _rc (syntax-rules () ((_rc f . cmd) (cmd->list (fold (lambda (e o) (string-append o " " (->string e))) "" 'cmd) 'f)))) \ No newline at end of file diff --git a/makefile b/makefile index 5b7fd7a..7b9c09f 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,7 @@ # Makefile for Chicken-scheme shell cscsh: shell.scm - csc shell.scm -o hiss + csc shell.scm -compile-syntax -o hiss .PHONY: clean clean: diff --git a/shell.scm b/shell.scm index 5f18ffb..8e12bf4 100644 --- a/shell.scm +++ b/shell.scm @@ -1,5 +1,6 @@ ;;; documentation at http://thintz.com/chicken-scheme-shell -(use readline symbol-utils) +(use readline symbol-utils srfi-1) +(include "macros.scm") (define (getenv2 e) ;; handles exorcism of getenv from 4.6.4 onwards @@ -21,6 +22,8 @@ (define exit? (make-parameter #f)) (define (exit) (exit? #t)) +(define (%run-cmd cmd) (with-input-from-pipe cmd read-file)) + ; now we can can actually use things in a more lispy way ; #;1> (cmd->list "ls" read-line) ; (file1 file2 file3) @@ -42,16 +45,14 @@ (define (shell-repl) (if (exit?) - #t - (let ((x (read))) - (handle-exceptions - exn - (begin (print-error-message exn) - (display (with-output-to-string (lambda () (print-call-chain))))) - (if (unbound? x) - (run (symbol->string x)) - (display (eval x))) - (newline)) - (shell-repl)))) + #t + (begin (handle-exceptions + exn + (begin (print-error-message exn) + (display (with-output-to-string (lambda () (print-call-chain))))) + (let ((x (read))) + (write (eval x)))) + (newline) + (shell-repl)))) (shell-repl)