JanetDocsPlaygroundI'm feeling luckyGitHub sign in

spit



    function
    boot.janet on line 1708, column 1

    (spit path contents &opt mode)

    Write `contents` to a file at `path`. Can optionally append to the 
    file.


2 examplesSign in to add an example
Loading...
# create new file with content "text"
(spit "file.txt" "text")

# append to file
(spit "file.txt" "text" :a)
KrasjetPlayground
# foo.txt is a file with contents "hello\nworld\n".
(slurp "foo.txt")  # => @"hello\nworld\n"
(string/split "\n" (slurp "foo.txt"))  # => @["hello" "world" ""]

(defn slurp-lines [path]
  (string/split "\n" (slurp path)))

(slurp-lines "foo.txt")  # => @["hello" "world" ""]

(string/join @["hello" "world" ""] "\n")  # => "hello\nworld\n"
(spit "foo2.txt" (string/join @["hello" "world" ""] "\n"))
# The contents of foo.txt and foo2.txt are now identical.

(defn spit-lines [path lines]
  (spit path (string/join lines "\n")))

(spit-lines "foo3.txt" (slurp-lines "foo.txt"))
# The contents of foo.txt and foo3.txt are now identical.
cellularmitosisPlayground