reworked inner loop; now checks for a lisp symbol before trying to run on the system shell. also added helper function for converting a shell programs output to a list.
This commit is contained in:
47
shell.scm
47
shell.scm
@@ -1,5 +1,5 @@
|
|||||||
;;; documentation at http://thintz.com/chicken-scheme-shell
|
;;; documentation at http://thintz.com/chicken-scheme-shell
|
||||||
(use shell readline)
|
(use readline symbol-utils)
|
||||||
|
|
||||||
(define (getenv2 e)
|
(define (getenv2 e)
|
||||||
;; handles exorcism of getenv from 4.6.4 onwards
|
;; handles exorcism of getenv from 4.6.4 onwards
|
||||||
@@ -21,20 +21,37 @@
|
|||||||
(define exit? (make-parameter #f))
|
(define exit? (make-parameter #f))
|
||||||
(define (exit) (exit? #t))
|
(define (exit) (exit? #t))
|
||||||
|
|
||||||
|
; now we can can actually use things in a more lispy way
|
||||||
|
; #;1> (cmd->list "ls" read-line)
|
||||||
|
; (file1 file2 file3)
|
||||||
|
; #;2> (map (lambda (file) (run (string-append "cat " file)))
|
||||||
|
; (cmd->list "ls" read-line))
|
||||||
|
; ...contents of all the files in the current directory
|
||||||
|
(define (cmd->list cmd read-func)
|
||||||
|
(with-input-from-pipe
|
||||||
|
cmd
|
||||||
|
(lambda ()
|
||||||
|
(letrec ((get-next (lambda (o)
|
||||||
|
(let ((v (read-func)))
|
||||||
|
(if (not (eof-object? v))
|
||||||
|
(get-next (cons v o))
|
||||||
|
(reverse o))))))
|
||||||
|
(get-next '())))))
|
||||||
|
|
||||||
|
(define (run cmd) (process-wait (process-run cmd)))
|
||||||
|
|
||||||
(define (shell-repl)
|
(define (shell-repl)
|
||||||
(if (exit?)
|
(if (exit?)
|
||||||
#t
|
#t
|
||||||
(let ((x (read)))
|
(let ((x (read)))
|
||||||
(begin (handle-exceptions
|
(handle-exceptions
|
||||||
exn
|
exn
|
||||||
(handle-exceptions
|
(begin (print-error-message exn)
|
||||||
exn
|
(display (with-output-to-string (lambda () (print-call-chain)))))
|
||||||
(begin (print-error-message exn)
|
(if (unbound? x)
|
||||||
(display (with-output-to-string (lambda () (print-call-chain)))))
|
(run (symbol->string x))
|
||||||
(execute (list x)))
|
(display (eval x)))
|
||||||
(display (eval x))
|
(newline))
|
||||||
(newline))
|
(shell-repl))))
|
||||||
(newline)
|
|
||||||
(shell-repl)))))
|
|
||||||
|
|
||||||
(shell-repl)
|
(shell-repl)
|
||||||
|
|||||||
Reference in New Issue
Block a user