Peter Bex avatar Peter Bex committed 9eff8e3

Use better ->string conversion routine

Comments (0)

Files changed (1)

 
    ;; macros
    run/collecting run/string run/strings run/port run/file run/sexp run/sexps
-   || &&
-   (& run-final-thunk maybe-symbol->string)
-   (run maybe-symbol->string) (exec-epf maybe-symbol->string))
+   || && (& run-final-thunk maybe->string) (run maybe->string) (exec-epf maybe->string))
 
 (import chicken scheme data-structures)
 
 ;; execve can be used in a sensible way?  Scsh has its own PATH, so we could
 ;; use something similar to that, but it's more work.
 (define (exec-path prog . args)
-  ;; Args can include numbers and such, too!  That's why we're using ->string
-  (process-execute (maybe-symbol->string prog) (map ->string args)))
+  (process-execute (maybe->string prog) (map maybe->string args)))
 
 ;; TODO: continue-threads argument
 (define (fork/pipe #!optional thunk)
 (define %fork/pipe fork/pipe)
 (define %fork/pipe+ fork/pipe+)
 
-(define (maybe-symbol->string s)
-  (if (symbol? s) (symbol->string s) s))
-
+(define (maybe->string s)
+  (cond ((string? s) s)
+        ((or (symbol? s) (number? s)) (->string s))
+        (else (error "Expected a string, symbol or number"))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Baroque procedural interface ;;
     ((_ (> ?file-name)) (setup-redirection (> 1 ?file-name)))
     ((_ (>> ?file-name)) (setup-redirection (>> 1 ?file-name)))
     ((_ (> ?fd ?file-name))
-     (duplicate-fileno (file-open (maybe-symbol->string `?file-name)
+     (duplicate-fileno (file-open (maybe->string `?file-name)
                                   (fx+ open/wronly open/creat))
                        `?fd))
     ((_ (>> ?fd ?file-name))
-     (duplicate-fileno (file-open (maybe-symbol->string `?file-name)
+     (duplicate-fileno (file-open (maybe->string `?file-name)
                                   (fx+ open/wronly (fx+ open/append open/creat)))
                        `?fd))
     ((_ (< ?fd ?file-name))
-     (duplicate-fileno (file-open (maybe-symbol->string `?file-name)
-                                  open/rdonly)
+     (duplicate-fileno (file-open (maybe->string `?file-name) open/rdonly)
                        `?fd))
     ((_ (<< ?fd ?object))
      (fork/pipe (lambda () (display ?object))))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.