Skip to content

Commit

Permalink
Merge pull request #119 from skx/114-require
Browse files Browse the repository at this point in the history
Allow loading a file with (require 'foo)
  • Loading branch information
skx authored Jan 7, 2023
2 parents c0f7e41 + 01791cc commit 94402b9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions stdlib/stdlib/file.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,16 @@ NOTE: This is a non-portable function!
(def! load-file (fn* (filename)
"Load and execute the contents of the supplied filename."
(eval (join (list "(do " (slurp filename) "\nnil)")))))


;; Similar to load-file, but with automatic suffix addition and error-testing.
(def! require (fn* (name)
"Load and execute the given file, adding a .yal suffix.
To load and execute foo.yal, returning nil if that doesn't exist:
Example: (require 'foo)"
(let* (fname (sprintf "%s%s" name ".yal"))
(if (file:stat fname)
(load-file fname)
nil))))

0 comments on commit 94402b9

Please sign in to comment.