os.WriteFile creates or replaces a file. Pass a string where Go wants []byte. Glojure coerces it. A second write with the same path replaces the contents.
os.WriteFile
[]byte
(let [[dir _] (os.MkdirTemp "" "glj-write") path (path:filepath.Join dir "out.txt")] (os.WriteFile path "one\ntwo\n" 0644) (print (slurp path)) (os.WriteFile path "replaced\n" 0644) (print (slurp path)) (os.RemoveAll dir))
The examples use WriteFile and slurp because those work in current glj. Temporary directories from MkdirTemp are removed before the program exits.
WriteFile
slurp
glj
MkdirTemp
The second write replaces the first.
$ glj writing-files.glj one two replaced
Next example: Line Filters.
A hands-on tour in the style of Go by Example. Glojure is a Clojure interpreter hosted on Go.