Directories in Lisp
Here’s the translation of the Go code to Lisp, formatted in Markdown for Hugo:
Our first program demonstrates working with directories in the file system. Here’s the full source code:
This Lisp program demonstrates various operations on directories:
We use ensure-directories-exist
to create directories, which is similar to os.MkdirAll
in Go.
uiop:delete-directory-tree
is used for recursive directory deletion, similar to os.RemoveAll
.
uiop:directory-files
is used to list directory contents, analogous to os.ReadDir
.
uiop:chdir
changes the current working directory, just like os.Chdir
.
We implement a walk-directory
function that recursively visits all subdirectories and files, similar to filepath.WalkDir
in Go.
The unwind-protect
macro is used to ensure cleanup of the created directory, similar to Go’s defer
.
To run this program, save it as directories.lisp
and use your Lisp implementation. For example, with SBCL:
Note that the exact output might vary depending on your Lisp implementation and operating system.