Login
7 branches 0 tags
Ben (Win10) Better REPL integration, especially for nujel-mode cba3e57 3 years ago 643 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 help [i]
       "Describe 10 functions at offset 1"
       [when-not [int? i] [set! i [int i]]]

       [for-each [map [symbol-table off 10] string]
                 [fn [l] [def desc [describe l]]
                         [pfmtln "{l} {desc}"]]]
       [def sc [/ [symbol-count] 10]]
       [pfmtln "Help page {i} of {sc}"]]

[defn file/eval [path environment]
       "Evaluate a Nujel source file in the current context"
       [when-not environment [set! environment root-closure]]
       [def source [cons 'do [read [file/read path]]]]
       [macroexpand/forms source environment]]

[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]]]]