diff --git a/examples/rosetta/create a file on magnetic tape.art b/examples/rosetta/create a file on magnetic tape.art index f500746a91..effc6e34ea 100644 --- a/examples/rosetta/create a file on magnetic tape.art +++ b/examples/rosetta/create a file on magnetic tape.art @@ -1,6 +1,6 @@ -write "TAPE.FILE" { +{ This code should be able to write a file to magnetic tape -} \ No newline at end of file +} >> "TAPE.FILE" diff --git a/examples/rosetta/create a file.art b/examples/rosetta/create a file.art index 00beb6ec26..a06cfdb5ad 100644 --- a/examples/rosetta/create a file.art +++ b/examples/rosetta/create a file.art @@ -1,8 +1,8 @@ output: "output.txt" docs: "docs" -write output "" -write.directory docs ø +"" >> output +write.directory ø docs -write join.path ["/" output] "" -write.directory join.path ["/" docs] ø \ No newline at end of file +"" >> join.path ["/" output] +write.directory ø join.path ["/" docs] diff --git a/examples/rosetta/file input-output.art b/examples/rosetta/file input-output.art index 996fb840cf..515a5acb36 100644 --- a/examples/rosetta/file input-output.art +++ b/examples/rosetta/file input-output.art @@ -1,4 +1,4 @@ source: read "input.txt" -write "output.txt" source +source >> "output.txt" -print source \ No newline at end of file +print source diff --git a/examples/rosetta/fractal tree.art b/examples/rosetta/fractal tree.art index 5ae2fdf5d4..57ee6fa37c 100644 --- a/examples/rosetta/fractal tree.art +++ b/examples/rosetta/fractal tree.art @@ -30,4 +30,4 @@ svg: { drawTree svg 0.5*width height trunkLength startingAngle 'svg ++ "" -write "fractal.svg" svg \ No newline at end of file +svg >> "fractal.svg" diff --git a/examples/rosetta/goldbach's comet.art b/examples/rosetta/goldbach's comet.art index 4bee56b090..e7bfa7ec91 100644 --- a/examples/rosetta/goldbach's comet.art +++ b/examples/rosetta/goldbach's comet.art @@ -13,4 +13,4 @@ print ["\nG(1000000) =" G 1000000] csv: join.with:",\n" map select 4..2000 => even? 'x -> ~"|x|, |G x|" -write "comet.csv" csv \ No newline at end of file +csv >> "comet.csv" diff --git a/examples/rosetta/hello world - line printer.art b/examples/rosetta/hello world - line printer.art index 26d0157948..83f269cc6e 100644 --- a/examples/rosetta/hello world - line printer.art +++ b/examples/rosetta/hello world - line printer.art @@ -1 +1 @@ -write "/dev/lp0" "Hello World\n" \ No newline at end of file +"Hello World\n" >> "/dev/lp0" diff --git a/examples/rosetta/json.art b/examples/rosetta/json.art index b240db048d..8536222378 100644 --- a/examples/rosetta/json.art +++ b/examples/rosetta/json.art @@ -11,4 +11,4 @@ object: #[ married: false ] -print write.json ø object \ No newline at end of file +print write.json object ø diff --git a/examples/rosetta/make directory path.art b/examples/rosetta/make directory path.art index b5c9becc8d..658cde2768 100644 --- a/examples/rosetta/make directory path.art +++ b/examples/rosetta/make directory path.art @@ -1 +1 @@ -write.directory "path/to/some/directory" ø \ No newline at end of file +write.directory ø "path/to/some/directory" diff --git a/examples/rosetta/remove lines from a file.art b/examples/rosetta/remove lines from a file.art index 0373e3eca4..b0ce535576 100644 --- a/examples/rosetta/remove lines from a file.art +++ b/examples/rosetta/remove lines from a file.art @@ -8,7 +8,7 @@ removeFileLines: function [filename, start, cnt][ ] final: previous\[0..start-1] ++ previous\[start+cnt..dec size previous] - write filename join.with:"\n" final + join.with:"\n" final >> filename ] -removeFileLines "myfile.txt" 3 10 \ No newline at end of file +removeFileLines "myfile.txt" 3 10 diff --git a/examples/rosetta/take notes on the command line.art b/examples/rosetta/take notes on the command line.art index 471ed158cc..f29039b85b 100644 --- a/examples/rosetta/take notes on the command line.art +++ b/examples/rosetta/take notes on the command line.art @@ -4,5 +4,5 @@ switch empty? arg [ ][ output: (to :string now) ++ "\n" ++ "\t" ++ (join.with:" " to [:string] arg) ++ "\n" - write.append notes output -] \ No newline at end of file + write.append output notes +] diff --git a/examples/rosetta/write entire file.art b/examples/rosetta/write entire file.art index fedfb2df64..55dbc09d93 100644 --- a/examples/rosetta/write entire file.art +++ b/examples/rosetta/write entire file.art @@ -1,2 +1,2 @@ contents: "Hello World!" -write "output.txt" contents \ No newline at end of file +contents >> "output.txt" diff --git a/src/library/Files.nim b/src/library/Files.nim index d1c585ca46..50e8cac8d1 100644 --- a/src/library/Files.nim +++ b/src/library/Files.nim @@ -494,11 +494,11 @@ proc defineLibrary*() = builtin "write", alias = doublearrowright, op = opNop, - rule = PrefixPrecedence, + rule = InfixPrecedence, description = "write content to file at given path", args = { - "file" : {String,Null}, - "content" : {Any} + "content" : {Any}, + "file" : {String,Null} }, attrs = { "append" : ({Logical},"append to given file"), @@ -510,36 +510,36 @@ proc defineLibrary*() = returns = {Nothing}, example = """ ; write some string data to given file path - write "somefile.txt" "Hello world!" + write "Hello world!" "somefile.txt" .......... ; we can also write any type of data as JSON - write.json "data.json" myData + write.json myData "data.json" .......... ; append to an existing file - write.append "somefile.txt" "Yes, Hello again!" + write.append "Yes, Hello again!" "somefile.txt" """: #======================================================= when defined(SAFE): Error_OperationNotPermitted("write") - if yKind==Bytecode: + if xKind==Bytecode: let dataS = codify(newBlock(y.trans.constants), unwrapped=true, safeStrings=true) - let codeS = y.trans.instructions - discard writeBytecode(dataS, codeS, x.s) + let codeS = x.trans.instructions + discard writeBytecode(dataS, codeS, y.s) else: if (hadAttr("directory")): - createDir(x.s) + createDir(y.s) else: if (hadAttr("binary")): - writeToFile(x.s, y.n, append = (hadAttr("append"))) + writeToFile(y.s, x.n, append = (hadAttr("append"))) else: if (hadAttr("json")): - let rez = jsonFromValue(y, pretty=(not hadAttr("compact"))) - if x.kind==String: - writeToFile(x.s, rez, append = (hadAttr("append"))) + let rez = jsonFromValue(x, pretty=(not hadAttr("compact"))) + if y.kind==String: + writeToFile(y.s, rez, append = (hadAttr("append"))) else: push(newString(rez)) else: - writeToFile(x.s, y.s, append = (hadAttr("append"))) + writeToFile(y.s, x.s, append = (hadAttr("append"))) builtin "zip", alias = unaliased, diff --git a/tests/unittests/lib.files.art b/tests/unittests/lib.files.art index 0a9a3a0023..d7d523b6f2 100644 --- a/tests/unittests/lib.files.art +++ b/tests/unittests/lib.files.art @@ -17,12 +17,12 @@ topic: $[topic :string] [ ; ] createTempFolder: $[][ - write.directory "temp/" null + write.directory null "temp/" print "Created: temp/" ] createTestFolder: $[topic][ - write.directory ~"temp/|topic|" null + write.directory null ~"temp/|topic|" return ~"temp/|topic|" ] @@ -43,7 +43,7 @@ do [ dir: createTestFolder "copy" - write ~"|dir|/file.txt" "Hello, world!" + write "Hello, world!" ~"|dir|/file.txt" ensure -> exists? ~"|dir|/file.txt" ; ---------//---------//---------// @@ -64,8 +64,8 @@ do [ dir: createTestFolder "copy-empty-dir" folders: @["A" "B" "C"] - loop folders 'f -> write.directory ~"|dir|/input/|f|" null - write.directory ~"|dir|/dest" null + loop folders 'f -> write.directory null ~"|dir|/input/|f|" + write.directory null ~"|dir|/dest" ensure -> every? folders 'f -> exists? ~"|dir|/input/|f|" ensure -> exists? ~"|dir|/dest" @@ -85,9 +85,9 @@ do [ dir: createTestFolder "copy-filled-dir" folders: @["A" "B" "C"] - loop folders 'f -> write.directory ~"|dir|/input/|f|" null - loop folders 'f -> write ~"|dir|/input/|f|/file.txt" "." - write.directory ~"|dir|/dest" null + loop folders 'f -> write.directory null ~"|dir|/input/|f|" + loop folders 'f -> write "." ~"|dir|/input/|f|/file.txt" + write.directory null ~"|dir|/dest" ensure -> every? folders 'f -> exists? ~"|dir|/input/|f|/file.txt" ensure -> exists? ~"|dir|/dest" @@ -109,7 +109,7 @@ do [ dir: createTestFolder "delete" - write ~"|dir|/file.txt" "Hello, world!" + write "Hello, world!" ~"|dir|/file.txt" ensure -> exists? ~"|dir|/file.txt" @@ -128,7 +128,7 @@ do [ dir: createTestFolder "delete-empty-folders" folders: @["A" "B" "C"] - loop folders 'f -> write.directory ~"|dir|/|f|" null + loop folders 'f -> write.directory null ~"|dir|/|f|" ensure -> every? folders 'f -> exists? ~"|dir|/|f|" @@ -147,8 +147,8 @@ do [ dir: createTestFolder "delete-filled-dir" folders: @["A" "B" "C"] - loop folders 'f -> write.directory ~"|dir|/|f|" null - loop folders 'f -> write ~"|dir|/|f|/file.txt" "." + loop folders 'f -> write.directory null ~"|dir|/|f|" + loop folders 'f -> write "." ~"|dir|/|f|/file.txt" ensure -> every? folders 'f -> exists? ~"|dir|/|f|/file.txt" @@ -168,8 +168,8 @@ do [ dir: createTestFolder "move" - write.directory ~"|dir|/dest" null - write ~"|dir|/file.txt" "Hello, world!" + write.directory null ~"|dir|/dest" + write "Hello, world!" ~"|dir|/file.txt" ensure -> exists? ~"|dir|/file.txt" ensure -> not? exists? ~"|dir|/dest/file.txt" @@ -190,8 +190,8 @@ do [ dir: createTestFolder "move-empty-dir" folders: @["A" "B" "C"] - loop folders 'f -> write.directory ~"|dir|/input/|f|" null - write.directory ~"|dir|/dest" null + loop folders 'f -> write.directory null ~"|dir|/input/|f|" + write.directory null ~"|dir|/dest" ensure -> every? folders 'f -> and? @@ -219,9 +219,9 @@ do [ dir: createTestFolder "move-filled-dir" folders: @["A" "B" "C"] - loop folders 'f -> write.directory ~"|dir|/input/|f|" null - loop folders 'f -> write ~"|dir|/input/|f|/file.txt" "." - write.directory ~"|dir|/dest" null + loop folders 'f -> write.directory null ~"|dir|/input/|f|" + loop folders 'f -> write "." ~"|dir|/input/|f|/file.txt" + write.directory null ~"|dir|/dest" ensure -> every? folders 'f -> exists? ~"|dir|/input/|f|/file.txt" @@ -247,7 +247,7 @@ topic "permissions" ; do dir: createTestFolder "permissions" - write ~"|dir|/file.txt" "Hello, world!" + write "Hello, world!" ~"|dir|/file.txt" ensure -> exists? ~"|dir|/file.txt" ; ---------//---------//---------// @@ -262,7 +262,7 @@ topic "permissions" ; do ; ; dir: createTestFolder "permissions-set" ; -; write ~"|dir|/file.txt" "Hello, world!" +; write "Hello, world!" ~"|dir|/file.txt" ; ; ; action ; permissions.set: #[others:#[write:false]] ~"|dir|/file.txt" @@ -280,11 +280,11 @@ do [ dir: createTestFolder "read" - write ~"|dir|/test.txt" { + write { Hello, world This is a multiline File. :) - } + } ~"|dir|/test.txt" ensure -> exists? ~"|dir|/test.txt" ; ---------//---------//---------// @@ -299,7 +299,7 @@ do [ dir: createTestFolder "read-lines" - write ~"|dir|/test.txt" { + write { The Language ------------------------------ @@ -315,7 +315,7 @@ do [ according to the context - No reserved words or keywords - look for them as hard as you can; there are absolutely none - } + } ~"|dir|/test.txt" ensure -> exists? ~"|dir|/test.txt" @@ -339,7 +339,7 @@ do [ } } - write ~"|dir|/test.json" jsonSample + write jsonSample ~"|dir|/test.json" ensure -> exists? ~"|dir|/test.json" @@ -358,12 +358,12 @@ do dir: createTestFolder "read-csv" - write ~"|dir|/test.csv" { + write { language, version, platform Arturo, 0.9.83, win10 Python, 3.9, gnu/linux Ruby, 3.2.1, macOS - } + } ~"|dir|/test.csv" ensure -> exists? ~"|dir|/test.csv" @@ -379,12 +379,12 @@ do dir: createTestFolder "read-csv-delimiter" - write ~"|dir|/test.csv" { + write { language; version; platform Arturo; 0.9.83; win10 Python; 3.9; gnu/linux Ruby; 3.2.1; macOS - } + } ~"|dir|/test.csv" ensure -> exists? ~"|dir|/test.csv" @@ -399,12 +399,12 @@ do [ dir: createTestFolder "read-csv-headers" - write ~"|dir|/test.csv" { + write { language, version, platform Arturo, 0.9.83, win10 Python, 3.9, gnu/linux Ruby, 3.2.1, macOS - } + } ~"|dir|/test.csv" ensure -> exists? ~"|dir|/test.csv" @@ -438,7 +438,7 @@ topic "read.html" do } - write ~"|dir|/test.html" htmlSample + write htmlSample ~"|dir|/test.html" ensure -> exists? ~"|dir|/test.html" @@ -477,7 +477,7 @@ topic "read.xml" do } - write ~"|dir|/test.xml" xmlSample + write xmlSample ~"|dir|/test.xml" ensure -> exists? ~"|dir|/test.xml" @@ -515,7 +515,7 @@ topic "read.markdown" do } - write ~"|dir|/test.md" mdSample + write mdSample ~"|dir|/test.md" ensure -> exists? ~"|dir|/test.md" @@ -547,7 +547,7 @@ topic "read.toml" do pkg-manager = "^0.2" } - write ~"|dir|/test.toml" tomlSample + write tomlSample ~"|dir|/test.toml" ensure -> exists? ~"|dir|/test.toml" @@ -578,7 +578,7 @@ topic "read.toml -- from ini file" do pkg-manager = "^0.2" } - write ~"|dir|/test.ini" iniSample + write iniSample ~"|dir|/test.ini" ensure -> exists? ~"|dir|/test.ini" @@ -601,7 +601,7 @@ topic "read.toml -- from ini file" do ; code: [print 2 + 1] ; bcode: to :bytecode code ; -; write.binary "test.bcode" bcode +; write.binary bcode "test.bcode" ; print type read.bytecode "test.bcode" ; ; :binary ?? @@ -611,9 +611,9 @@ topic "read.binary" do [ dir: createTestFolder "read-bin" - write ~"|dir|/test.bin" { + write { Hello, World! - } + } ~"|dir|/test.bin" ensure -> exists? ~"|dir|/test.bin" @@ -650,7 +650,7 @@ topic "rename" do [ dir: createTestFolder "rename" - write ~"|dir|/file.txt" "Hello, world!" + write "Hello, world!" ~"|dir|/file.txt" ensure -> exists? ~"|dir|/file.txt" @@ -668,8 +668,8 @@ do [ dir: createTestFolder "rename-dir" - write.directory ~"|dir|/folder" null - write ~"|dir|/folder/file.txt" "." + write.directory null ~"|dir|/folder" + write "." ~"|dir|/folder/file.txt" ensure -> exists? ~"|dir|/folder/file.txt" @@ -701,7 +701,7 @@ do [ dir: createTestFolder "timestamp" - write ~"|dir|/file.txt" "Hello, world!" + write "Hello, world!" ~"|dir|/file.txt" ensure -> exists? ~"|dir|/file.txt" @@ -765,7 +765,7 @@ topic "zip & unzip - destination" dir: createTestFolder "zip-unzip-file-dest" - write ~"|dir|/file.txt" "Hello, world!" + write "Hello, world!" ~"|dir|/file.txt" ensure -> exists? ~"|dir|/file.txt" ;; outputs me an empty .zip @@ -806,11 +806,11 @@ topic "zip & unzip - destination" ; execute "mkdir temp/folder{A,B,C}/{A,B,C}" ; ; ; Using write because I can't redirect using `execute` function -; write "temp/folderA/A/file.txt" "Hello, world!" -; write "temp/folderB/B/file.txt" "Hello, world!" -; write "temp/folderC/C/file.txt" "Hello, world!" -; write "temp/folderA/file.txt" "Hello, world!" -; write "temp/file.txt" "Hello, world!" +; write "Hello, world!" "temp/folderA/A/file.txt" +; write "Hello, world!" "temp/folderB/B/file.txt" +; write "Hello, world!" "temp/folderC/C/file.txt" +; write "Hello, world!" "temp/folderA/file.txt" +; write "Hello, world!" "temp/file.txt" ; ; ; 1st assertion ; print execute "ls temp/**" @@ -837,7 +837,7 @@ do [ dir: createTestFolder "volume" - write ~"|dir|/test.bin" "Hello, World!" + write "Hello, World!" ~"|dir|/test.bin" ensure -> exists? ~"|dir|/test.bin" ; ---------//---------//---------// @@ -853,7 +853,7 @@ do [ dir: createTestFolder "write" - write ~"|dir|/file.txt" "Hello, world!" + write "Hello, world!" ~"|dir|/file.txt" ensure -> exists? ~"|dir|/file.txt" ; ---------//---------//---------// @@ -867,13 +867,13 @@ do [ dir: createTestFolder "write-append" - write ~"|dir|/file.txt" "Hello, world!" + write "Hello, world!" ~"|dir|/file.txt" ensure -> exists? ~"|dir|/file.txt" print read ~"|dir|/file.txt" ; ---------//---------//---------// - write.append ~"|dir|/file.txt" "\nFrom Arturo's World!" + write.append "\nFrom Arturo's World!" ~"|dir|/file.txt" print read.file ~"|dir|/file.txt" ] @@ -885,8 +885,8 @@ do [ ; ---------//---------//---------// - write.directory ~"|dir|/folder" null - write.directory ~"|dir|/directory" null + write.directory null ~"|dir|/folder" + write.directory null ~"|dir|/directory" ensure -> exists? ~"|dir|/folder" ensure -> exists? ~"|dir|/directory" @@ -900,12 +900,12 @@ do [ dir: createTestFolder "write-json" - write.json ~"|dir|/file.json" #[ + write.json #[ name: "Arturo", version: 1.9.83, build: "b/12", platform: "amd/win10" - ] + ] ~"|dir|/file.json" print read.file ~"|dir|/file.json" @@ -917,12 +917,12 @@ do [ dir: createTestFolder "write-c-json" - write.json.compact ~"|dir|/file.json" #[ + write.json.compact #[ name: "Arturo", version: 1.9.83, build: "b/12", platform: "amd/win10" - ] + ] ~"|dir|/file.json" print read.file ~"|dir|/file.json" @@ -933,7 +933,7 @@ do [ dir: createTestFolder "write-bin" - write.binary ~"|dir|/file.bin" "Hello, world!" + write.binary "Hello, world!" ~"|dir|/file.bin" print read.file ~"|dir|/file.bin" ] @@ -949,7 +949,7 @@ do [ print "file does not exist" ] - write ~"|dir|/file.txt" "Hello, world!" + write "Hello, world!" ~"|dir|/file.txt" if exists? ~"|dir|/file.txt" [ print "file exists" @@ -966,7 +966,7 @@ do [ print "directory does not exist" ] - write.directory ~"|dir|/dir" null + write.directory null ~"|dir|/dir" if directory? ~"|dir|/dir" [ print "directory exists" diff --git a/tools/genaiguide.art b/tools/genaiguide.art index 019430cd41..56767d5ff2 100644 --- a/tools/genaiguide.art +++ b/tools/genaiguide.art @@ -73,4 +73,4 @@ loop data [lib, contents][ ] unless empty? ppout -> - write ./"aiguide.md" ppout \ No newline at end of file + ppout >> ./"aiguide.md" diff --git a/tools/gendep.art b/tools/gendep.art index d2bfcf3fb9..2dd1834234 100644 --- a/tools/gendep.art +++ b/tools/gendep.art @@ -176,6 +176,6 @@ delete "src/arturo.png" delete "arturo.deps" -write "arturo.dot" "digraph Arturo {\n" ++ join.with:"\n" lines ++ "\n}" +"digraph Arturo {\n" ++ join.with:"\n" lines ++ "\n}" >> "arturo.dot" -execute "dot -Tpng arturo.dot -o arturo.png" \ No newline at end of file +execute "dot -Tpng arturo.dot -o arturo.png" diff --git a/tools/rc.art b/tools/rc.art index 4422bc2b36..b258207e3d 100755 --- a/tools/rc.art +++ b/tools/rc.art @@ -29,7 +29,7 @@ getTemplateRC: function [s][
OUT
} - write resPath s strip runScript s + strip runScript s >> resPath s replace templ ["SCR", "OUT"] @[read scrPath s, read resPath s] ] @@ -46,8 +46,8 @@ case cmd [ "n" [ print color #cyan "creating new RC example...\n" - write scrPath scr "" - write resPath scr "" + "" >> scrPath scr + "" >> resPath scr ] "c" [ print color #cyan "cleaning up RC res...\n" @@ -68,4 +68,4 @@ case cmd [ else [ panic "unrecognized command" ] -] \ No newline at end of file +] diff --git a/tools/sitegen.art b/tools/sitegen.art index 1e73fef976..41e98250cf 100755 --- a/tools/sitegen.art +++ b/tools/sitegen.art @@ -27,7 +27,7 @@ loop rosettas 'ro [ 'dict ++ ro ] -write "docs/website/data/rosetta.art" as.pretty.code dict +as.pretty.code dict >> "docs/website/data/rosetta.art" print as.pretty.code dict @@ -114,8 +114,8 @@ loop functions [modl,lst][ print join.path @[target ~"|func|.art"] if not? exists? target -> - write.directory target ø - write join.path @[target ~{|replace func "?" "-"|.art}] funcInfo + write.directory ø target + funcInfo >> join.path @[target ~{|replace func "?" "-"|.art}] ] ] funcs: new [] @@ -149,8 +149,8 @@ loop funcs 'f [ ] ] -write "docs/website/data/libraryModules.art" as.pretty.code sort unique modules -write "docs/website/data/libraryFunctions.art" as.pretty.code funcList -write "docs/website/data/librarySymbols.art" as.pretty.code symbList +as.pretty.code sort unique modules >> "docs/website/data/libraryModules.art" +as.pretty.code funcList >> "docs/website/data/libraryFunctions.art" +as.pretty.code symbList >> "docs/website/data/librarySymbols.art" inspect funcList