fn get_number_input(question string) {<br> println(question)<br> input = read_line()<br> // try to parse to an int, then a float.<br> in = match input {<br> input.parse_int() input<br> input.parse_float() input<br> }<br> // 'in' has type int/float/[] because of the match statement<br> switch! in {<br> int/float in<br> // replace [] with an appropriate error before returning<br> [] Err: "input was not a number."<br> }<br> // return type is int/float/Err(string)<br>}<br><br>answer = get_number_input("What is your favorite number?")<br><br>// switch can be used to branch based on a variables type.<br>// switch! indicates that every possible type must be handled.<br>switch! answer {<br> int {<br> println("Entered an integer")<br> answer.debug() // int<br> }<br> float {<br> println("Entered a decimal number")<br> answer.debug() // float<br> }<br> Err(string) println("Input was not a number!")<br>}<br><br>sleep(2)<br><br><br>// function that returns an anonymous function (function object).<br>// anonymous functions can be used as iterators in for-loops.<br>fn count_up() {<br> count = -1<br> () {<br> count = count.add(1)<br> count<br> }<br>}<br><br>for num count_up() {<br> println(num.to_string())<br> // once num is greater than 60,<br> // the loop stops and returns num.<br> if num.gt(60) num else []<br>}<br><br></code></pre>
<h3>HTML preprocessor to help build this document written in mers:</h3>
<sectionclass="container">
<preclass="container2_left"><code>
<!DOCTYPE html><br># This document will be processed by build.mers.<br># Lines starting with hashtags are comments and will be ignored.<br># Lines starting with dollar-signs insert special text.<br># To escape this, put a space before the hashtag or dollar sign.<br><head><br><meta charset=“UTF-8”><br><link rel="stylesheet" href="site/external.css"><br><title>Mark :: mers</title><br></head><br><body><br><h1>Mers</h1><br><section class="container"><br><section class="container_left2 code-border"><br><pre><code class="mers-code-snippet"><br>$welcome_script<br></code></pre><br></section><br><section class="container_right"><br><image<br> alt="some picture related to mers (todo)"<br> src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP//////<br> width="100%" height="100%"<br>><br><h3>Mers types</h3><br><div><br> Mers uses a multiple-types system.<br> It keeps track of which types a variable could have<br> and constructs a type with that information.<br><br><br> For example, <code>int/float</code> can represent a number - int or<br> Optional types can be <code>[]/[t]</code> - either nothing or one v<br> Mers doesn't have null, it just has the empty tuple <code>[]</code><br></div><br><h3>No exceptions, no crashes</h3><br><div><br> Errors in mers are passed as values.<br> Because of the type system, you are forced to handle them explicitl<br> Mers will not crash in unexpected places, because the only way to c<br> it is by using one of the assume*() functions (similar to unwrap()s<br></div><br></section><br></section><br><hr><br><h3>HTML preprocessor to help build this document written in mers:</h3><br><section class="container"><br><pre class="container2_left"><code><br>$index.html<br></code></pre><br><pre class="container2_right"><code class="mers-code-snippet"><br>$build_script<br></code></pre><br></section><br></body><br><br></code></pre>