about summary refs log tree commit diff stats
path: root/filesystem.mu
blob: acfd39b2d9e3f8471737d7c3bffbaa075cef46cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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
  source-file:&:source:char <- start-reading 0/real-filesystem, [/tmp/mu-x]
  sink-file:&:sink:char, write-routine:num <- start-writing 0/real-filesystem, [/tmp/mu-y]
  {
    c:char, done?:bool, source-file <- read source-file
    break-if done?
    sink-file <- write sink-file, c
    loop
  }
  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
]
="n">map<recipe_ordinal, recipe>::iterator p = Recipe.begin(); p != Recipe.end(); ++p) { recipe& r = p->second; if (r.steps.empty()) continue; for (long long int index = 0; index < SIZE(r.steps); ++index) { instruction& inst = r.steps.at(index); for (long long int i = 0; i < SIZE(inst.ingredients); ++i) { populate_value(inst.ingredients.at(i)); } for (long long int i = 0; i < SIZE(inst.products); ++i) { populate_value(inst.products.at(i)); } } } } void populate_value(reagent& r) { if (r.initialized) return; // End Reagent-parsing Exceptions if (!is_integer(r.name)) return; r.set_value(to_integer(r.name)); }