diff options
-rw-r--r-- | Readme.md | 24 | ||||
-rw-r--r-- | html/immutable-error.mu.html | 47 | ||||
-rw-r--r-- | html/immutable-error.png | bin | 0 -> 28154 bytes | |||
-rw-r--r-- | html/mutable.mu.html | 47 | ||||
-rw-r--r-- | html/mutable.png | bin | 0 -> 10501 bytes | |||
-rw-r--r-- | immutable-error.mu | 13 | ||||
-rw-r--r-- | mutable.mu | 13 |
7 files changed, 144 insertions, 0 deletions
diff --git a/Readme.md b/Readme.md index 65e89fb7..a8dc9028 100644 --- a/Readme.md +++ b/Readme.md @@ -214,6 +214,30 @@ augment scenarios with corresponding abilities. --- +Mu assumes that all ingredients passed in to functions are immutable by +default -- *unless* they are also products. So this program will throw an +error: + +<img alt='immutable ingredient triggering an error' src='html/immutable-error.png'> + +To modify `foo`'s ingredient, you have to add it to the list of products +returned: + +<img alt='mutable ingredient' src='html/mutable.png'> + +The names of the variables are important here: a function that takes an +(immutable) address and returns a different one is different from a function +that takes a mutable address (and also returns it). + +Immutability checks can be annoying sometimes, but the benefit they provide is +that you always know what a function modifies just by looking at its header. +They provide all the benefits of [referential transparency](https://en.wikipedia.org/wiki/Referential_transparency) +that we typically associate with (particularly purely functional) high-level +languages -- but without giving up the flexibility to imperatively modify +variables willy-nilly. + +--- + You can append arbitrary properties to reagents besides types and spaces. Just separate them with slashes. diff --git a/html/immutable-error.mu.html b/html/immutable-error.mu.html new file mode 100644 index 00000000..52c661c5 --- /dev/null +++ b/html/immutable-error.mu.html @@ -0,0 +1,47 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - immutable-error.mu</title> +<meta name="Generator" content="Vim/7.4"> +<meta name="plugin-version" content="vim7.4_v2"> +<meta name="syntax" content="none"> +<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } +body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; } +* { font-size: 12pt; font-size: 1em; } +.muRecipe { color: #ff8700; } +.Comment { color: #9090ff; } +.Constant { color: #00a0a0; } +.Special { color: #c00000; } +--> +</style> + +<script type='text/javascript'> +<!-- + +--> +</script> +</head> +<body> +<pre id='vimCodeElement'> +<span class="Comment"># compare mutable.mu</span> + +<span class="muRecipe">def</span> main [ + <span class="Constant">local-scope</span> + x:address:number<span class="Special"> <- </span>new <span class="Constant">number:type</span> + foo x +] + +<span class="muRecipe">def</span> foo x:address:number [ + <span class="Constant">local-scope</span> + <span class="Constant">load-ingredients</span> + *x<span class="Special"> <- </span>copy <span class="Constant">34</span> <span class="Comment"># will cause an error because x is immutable in this function</span> +] +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/immutable-error.png b/html/immutable-error.png new file mode 100644 index 00000000..b48fae69 --- /dev/null +++ b/html/immutable-error.png Binary files differdiff --git a/html/mutable.mu.html b/html/mutable.mu.html new file mode 100644 index 00000000..f4cb97b6 --- /dev/null +++ b/html/mutable.mu.html @@ -0,0 +1,47 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - mutable.mu</title> +<meta name="Generator" content="Vim/7.4"> +<meta name="plugin-version" content="vim7.4_v2"> +<meta name="syntax" content="none"> +<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } +body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color: #080808; } +* { font-size: 12pt; font-size: 1em; } +.muRecipe { color: #ff8700; } +.Comment { color: #9090ff; } +.Constant { color: #00a0a0; } +.Special { color: #c00000; } +--> +</style> + +<script type='text/javascript'> +<!-- + +--> +</script> +</head> +<body> +<pre id='vimCodeElement'> +<span class="Comment"># compare immutable-error.mu</span> + +<span class="muRecipe">def</span> main [ + <span class="Constant">local-scope</span> + x:address:number<span class="Special"> <- </span>new <span class="Constant">number:type</span> + foo x +] + +<span class="muRecipe">def</span> foo x:address:number<span class="muRecipe"> -> </span>x:address:number [ + <span class="Constant">local-scope</span> + <span class="Constant">load-ingredients</span> + *x<span class="Special"> <- </span>copy <span class="Constant">34</span> +] +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/mutable.png b/html/mutable.png new file mode 100644 index 00000000..d2f47ebc --- /dev/null +++ b/html/mutable.png Binary files differdiff --git a/immutable-error.mu b/immutable-error.mu new file mode 100644 index 00000000..b75e2791 --- /dev/null +++ b/immutable-error.mu @@ -0,0 +1,13 @@ +# compare mutable.mu + +def main [ + local-scope + x:address:number <- new number:type + foo x +] + +def foo x:address:number [ + local-scope + load-ingredients + *x <- copy 34 # will cause an error because x is immutable in this function +] diff --git a/mutable.mu b/mutable.mu new file mode 100644 index 00000000..5de7777e --- /dev/null +++ b/mutable.mu @@ -0,0 +1,13 @@ +# compare immutable-error.mu + +def main [ + local-scope + x:address:number <- new number:type + foo x +] + +def foo x:address:number -> x:address:number [ + local-scope + load-ingredients + *x <- copy 34 +] |