diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-08-18 21:31:01 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-08-18 21:31:01 -0700 |
commit | 513ba3308502df6b576afd95aa20a57e0ec76d1f (patch) | |
tree | 322a84ab27928096e29af1f23c9b0b0fa638e4e1 /html/filesystem.mu.html | |
parent | 7cc017e545cb3d4c4b67403eff0c82993e2b587b (diff) | |
download | mu-513ba3308502df6b576afd95aa20a57e0ec76d1f.tar.gz |
3227
Diffstat (limited to 'html/filesystem.mu.html')
-rw-r--r-- | html/filesystem.mu.html | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/html/filesystem.mu.html b/html/filesystem.mu.html index 17cecb3a..8fb32b8a 100644 --- a/html/filesystem.mu.html +++ b/html/filesystem.mu.html @@ -30,21 +30,27 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color </head> <body> <pre id='vimCodeElement'> +<span class="Comment"># example program: copy one file into another, character by character</span> +<span class="Comment"># BEWARE: this will modify your file system</span> +<span class="Comment"># before running it, put some text into /tmp/mu-x</span> +<span class="Comment"># after running it, check /tmp/mu-y</span> + <span class="muRecipe">def</span> main [ <span class="Constant">local-scope</span> - $print <span class="Constant">[file to read from: ]</span>, <span class="Constant">[/tmp/mu-fs]</span> - <span class="Comment"># initialize filesystem</span> - fs:address:filesystem<span class="Special"> <- </span>copy <span class="Constant">0/real-filesystem</span> - content-source:address:source:character<span class="Special"> <- </span>start-reading fs, <span class="Constant">[/tmp/mu-fs]</span> - <span class="Comment"># read from channel until exhausted and print out characters</span> + source-file:address:source:character<span class="Special"> <- </span>start-reading <span class="Constant">0/real-filesystem</span>, <span class="Constant">[/tmp/mu-x]</span> + sink-file:address:sink:character, write-routine:number<span class="Special"> <- </span>start-writing <span class="Constant">0/real-filesystem</span>, <span class="Constant">[/tmp/mu-y]</span> <span class="Delimiter">{</span> - c:character, done?:boolean, content-source<span class="Special"> <- </span>read content-source + c:character, done?:boolean, source-file<span class="Special"> <- </span>read source-file <span class="muControl">break-if</span> done? - $print <span class="Constant">[Next: ]</span>, c, <span class="Constant">10/newline</span> + eof?:boolean<span class="Special"> <- </span>equal c, <span class="Constant">-1</span> + <span class="muControl">break-if</span> eof? + sink-file<span class="Special"> <- </span>write sink-file, c <span class="muControl">loop</span> <span class="Delimiter">}</span> - $print <span class="Constant">[Done reading]</span>, <span class="Constant">10/newline</span> - <span class="Comment"># TODO: writing to file</span> + close sink-file + <span class="Comment"># make sure to wait for the file to be actually written to disk</span> + <span class="Comment"># (Mu practices structured concurrency: <a href="http://250bpm.com/blog:71)">http://250bpm.com/blog:71)</a></span> + wait-for-routine write-routine ] </pre> </body> |