Login
7 branches 0 tags
Ben (Win10) Added a simple module system e201dbe 3 years ago 689 Commits
nujel / binlib / io.nuj
; Nujel - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
; This project uses the MIT license, a copy should be included under /LICENSE

[def test-context "Nujel Standalone"]

[defn file/eval [path environment]
       "Evaluate a Nujel source file in the current context"
       [when-not environment [set! environment root-closure]]
       [for-in [form [read [file/read path]]]
               [eval-in environment form]]]

[defn load [filename]
  [try [fn [err]
         [display/error err]
         #f]
       [file/eval filename]
       [pfmtln "Loaded {filename}"]
       #t]]

[defn file/file? [filename]
       [ref [file/stat filename] :regular-file?]]

[defn file/dir? [filename]
       [ref [file/stat filename] :directory?]]

[defn directory/read-relative [path]
      [map [directory/read path]
           [fn [a]
               [cat path "/" a]]]]

[defn directory/read-recursive [path]
       [flatten [map [directory/read-relative path]
                     [fn [A] [if [file/dir? A]
                                 [directory/read-recursive A]
                                 A]]]]]

[defn popen/trim [cmd]
  "Run CMD using popen and return the trimmed stdout"
  [trim [cdr [popen cmd]]]]