about summary refs log tree commit diff stats
path: root/html/088file.mu.html
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-10-23 23:15:12 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-23 23:15:12 -0700
commit2e4f0bbd12231a51ae08df4fe0f8847111fde405 (patch)
tree581166406a4749ac2dcd87c8555cc95dbb1bbd52 /html/088file.mu.html
parent2225b945ad5ba9310081b371bf32a9f575646e1b (diff)
downloadmu-2e4f0bbd12231a51ae08df4fe0f8847111fde405.tar.gz
3578
Diffstat (limited to 'html/088file.mu.html')
-rw-r--r--html/088file.mu.html40
1 files changed, 23 insertions, 17 deletions
diff --git a/html/088file.mu.html b/html/088file.mu.html
index e6ef6e98..26fa0c7c 100644
--- a/html/088file.mu.html
+++ b/html/088file.mu.html
@@ -47,15 +47,21 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
   <span class="Constant">local-scope</span>
   <span class="Constant">load-ingredients</span>
   <span class="Delimiter">{</span>
-    <span class="muControl">break-if</span> resources
-    <span class="Comment"># real file system</span>
-    file:num <span class="Special">&lt;-</span> $open-file-for-reading filename
-    assert file, <span class="Constant">[file not found]</span>
-    contents:&amp;:source:char, sink:&amp;:sink:char <span class="Special">&lt;-</span> new-channel<span class="Constant"> 30</span>
-    start-running receive-from-file file, sink
+    <span class="muControl">break-unless</span> resources
+    <span class="Comment"># fake file system</span>
+    contents <span class="Special">&lt;-</span> start-reading-from-fake-resources resources, filename
     <span class="muControl">return</span>
   <span class="Delimiter">}</span>
-  <span class="Comment"># fake file system</span>
+  <span class="Comment"># real file system</span>
+  file:num <span class="Special">&lt;-</span> $open-file-for-reading filename
+  assert file, <span class="Constant">[file not found]</span>
+  contents:&amp;:source:char, sink:&amp;:sink:char <span class="Special">&lt;-</span> new-channel<span class="Constant"> 30</span>
+  start-running receive-from-file file, sink
+]
+
+<span class="muRecipe">def</span> start-reading-from-fake-resources resources:&amp;:resources, resource:text<span class="muRecipe"> -&gt; </span>contents:&amp;:source:char [
+  <span class="Constant">local-scope</span>
+  <span class="Constant">load-ingredients</span>
   i:num <span class="Special">&lt;-</span> copy<span class="Constant"> 0</span>
   data:&amp;:@:resource <span class="Special">&lt;-</span> get *resources, <span class="Constant">data:offset</span>
   len:num <span class="Special">&lt;-</span> length *data
@@ -64,8 +70,8 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
     <span class="muControl">break-if</span> done?
     tmp:resource <span class="Special">&lt;-</span> index *data, i
     i <span class="Special">&lt;-</span> add i,<span class="Constant"> 1</span>
-    curr-filename:text <span class="Special">&lt;-</span> get tmp, <span class="Constant">name:offset</span>
-    found?:bool <span class="Special">&lt;-</span> equal filename, curr-filename
+    curr-resource:text <span class="Special">&lt;-</span> get tmp, <span class="Constant">name:offset</span>
+    found?:bool <span class="Special">&lt;-</span> equal resource, curr-resource
     <span class="muControl">loop-unless</span> found?
     contents:&amp;:source:char, sink:&amp;:sink:char <span class="Special">&lt;-</span> new-channel<span class="Constant"> 30</span>
     curr-contents:text <span class="Special">&lt;-</span> get tmp, <span class="Constant">contents:offset</span>
@@ -109,16 +115,16 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
   <span class="Constant">load-ingredients</span>
   source:&amp;:source:char, sink:&amp;:sink:char <span class="Special">&lt;-</span> new-channel<span class="Constant"> 30</span>
   <span class="Delimiter">{</span>
-    <span class="muControl">break-if</span> resources
-    <span class="Comment"># real file system</span>
-    file:num <span class="Special">&lt;-</span> $open-file-for-writing filename
-    assert file, <span class="Constant">[no such file]</span>
-    routine-id <span class="Special">&lt;-</span> start-running transmit-to-file file, source
+    <span class="muControl">break-unless</span> resources
+    <span class="Comment"># fake file system</span>
+    <span class="Comment"># beware: doesn't support multiple concurrent writes yet</span>
+    routine-id <span class="Special">&lt;-</span> start-running transmit-to-fake-file resources, filename, source
     <span class="muControl">reply</span>
   <span class="Delimiter">}</span>
-  <span class="Comment"># fake file system</span>
-  <span class="Comment"># beware: doesn't support multiple concurrent writes yet</span>
-  routine-id <span class="Special">&lt;-</span> start-running transmit-to-fake-file resources, filename, source
+  <span class="Comment"># real file system</span>
+  file:num <span class="Special">&lt;-</span> $open-file-for-writing filename
+  assert file, <span class="Constant">[no such file]</span>
+  routine-id <span class="Special">&lt;-</span> start-running transmit-to-file file, source
 ]
 
 <span class="muRecipe">def</span> transmit-to-file file:num, source:&amp;:source:char<span class="muRecipe"> -&gt; </span>source:&amp;:source:char [