diff options
Diffstat (limited to 'filesystem.mu')
-rw-r--r-- | filesystem.mu | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/filesystem.mu b/filesystem.mu index 274397be..3e6c45f7 100644 --- a/filesystem.mu +++ b/filesystem.mu @@ -1,16 +1,22 @@ +# example program: copy one file into another, character by character +# BEWARE: this will modify your file system +# before running it, put some text into /tmp/mu-x +# after running it, check /tmp/mu-y + def main [ local-scope - $print [reading characters from /tmp/mu-fs], 10/newline - # initialize filesystem - fs:address:filesystem <- copy 0/real-filesystem - content-source:address:source:character <- start-reading fs, [/tmp/mu-fs] - # read from channel until exhausted and print out characters + source-file:address:source:character <- start-reading 0/real-filesystem, [/tmp/mu-x] + sink-file:address:sink:character, write-routine:number <- start-writing 0/real-filesystem, [/tmp/mu-y] { - c:character, done?:boolean, content-source <- read content-source + c:character, done?:boolean, source-file <- read source-file break-if done? - $print [ ], c, 10/newline + eof?:boolean <- equal c, -1 + break-if eof? + sink-file <- write sink-file, c loop } - $print [done reading], 10/newline - # TODO: writing to file + close sink-file + # make sure to wait for the file to be actually written to disk + # (Mu practices structured concurrency: http://250bpm.com/blog:71) + wait-for-routine write-routine ] |