mirror of
				https://github.com/Dummi26/mers.git
				synced 2025-10-31 19:56:15 +01:00 
			
		
		
		
	updated example for github.io site
This commit is contained in:
		
							parent
							
								
									ac3221471f
								
							
						
					
					
						commit
						79a9d17ba9
					
				
							
								
								
									
										48
									
								
								index.html
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								index.html
									
									
									
									
									
								
							| @ -1,48 +0,0 @@ | ||||
| <!DOCTYPE html> | ||||
| <head> | ||||
| <meta charset=“UTF-8”> | ||||
| <link rel="stylesheet" href="external.css"> | ||||
| <title>Mark :: mers</title> | ||||
| </head> | ||||
| <body> | ||||
| <h1>Mers</h1> | ||||
| <section class="container"> | ||||
| <section class="container_left2 code-border"> | ||||
| <pre><code class="mers-code-snippet"> | ||||
| 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> | ||||
| </section> | ||||
| <section class="container_right"> | ||||
| <image | ||||
| alt="some picture related to mers (todo)" | ||||
| src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP//////////////////////////////////////////////////////////////////////////////////////2wBDAf//////////////////////////////////////////////////////////////////////////////////////wAARCAGCAcQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAECA//EACIQAQEAAgICAwEBAQEAAAAAAAABAhESMUFRIWFxgTLRIv/EABUBAQEAAAAAAAAAAAAAAAAAAAAB/8QAFhEBAQEAAAAAAAAAAAAAAAAAABFB/9oADAMBAAIRAxEAPwDQACgAAAAAKAAAIoCCoAAAAAAAioAAAAAACYeW2MPLYAAAAAAAAAAAAAAAAAAAAAAAAAAMgAoAAACooAICbWXbDWINAAAAIoCAAAAAAIoCBakoKDNoLh5bYw8tgAAAAAAAAAAAAAAAAAAAAAAAAAAyCgAAAoAACKwCXSy6RFR03By26Y1FaAAAARUABAUEBWLV2yAgA3OmasqA1h1W2MOq2Dje6F7pJsAa4nEGRricQZCzSAogCiAKIAogCiAKIAoig7AAAAyqKAAAqKAACXphuufQKyuyfKomlx+KfiyIroz5Wsg2ImwL2qeUBpIJsGmL2WpsBAAAAABvDptjDpsHG91cUvdXEHRm5KxQXksu3NqA1YxXRigyKaBAABdGgQU0CC6NUEF0AiooOwAAAMgbBRNqCeVZ8tUE2bRIDW0olvwCImwGo1GcemgavTMNoCoAKixARFQAAAAAEBRAHTDptjDpsHG91cUvdXEG2K6M3EGGpF4nQK51bUBqLUi0GKFAbiZLEyBmOmmI2B0biWsA6M2LKUHNQB2AAABkFBBQEFAZ+DUaAZ0lnw2lnwDkDWINaNNAM6qarYDGqfLYDHyny6AOaOqQHMdNRNQGBvXyagMDWouoDmN6iaBrDptjDpsHG91cUvdXEHRi1pigsrVc43AYqOljANRakWgxQpAbiZLEyBI2xG/AMVlqsg3GqzGqDnQoDsAAADKooAAAKCCoAXqiZX4oOSy6J2tx9A6S7VxlsrcyBsZ2bBTcZAa3E3E0mga3DbGjQNbNs/J8gogCgnyCoANYdNs4dNA43uril7qwG2K2xQZajKwHRixqUoJGqw1KDFWN6ia0Cy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AAAAAAAAADGXj9bYy8foNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMZeP0AbAAAAAAAAAAAAAAAAAAAAAAAAAAAB//Z" | ||||
| width="100%" height="100%" | ||||
| > | ||||
| <h3>Mers types</h3> | ||||
| <div> | ||||
| Mers uses a multiple-types system. | ||||
| It keeps track of which types a variable could have | ||||
| and constructs a type with that information. | ||||
| <br> | ||||
| For example, <code>int/float</code> can represent a number - int or float. | ||||
| Optional types can be <code>[]/[t]</code> - either nothing or one value (tuple with length 0 or 1). | ||||
| Mers doesn't have null, it just has the empty tuple <code>[]</code>. | ||||
| </div> | ||||
| <h3>No exceptions, no crashes</h3> | ||||
| <div> | ||||
| Errors in mers are passed as values. | ||||
| Because of the type system, you are forced to handle them explicitly. | ||||
| Mers will not crash in unexpected places, because the only way to crash | ||||
| it is by using one of the assume*() functions (similar to unwrap()s). | ||||
| </div> | ||||
| </section> | ||||
| </section> | ||||
| <hr> | ||||
| <h3>HTML preprocessor to help build this document written in mers:</h3> | ||||
| <section class="container"> | ||||
| <pre class="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="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> | ||||
| <pre class="container2_right"><code class="mers-code-snippet"> | ||||
| #!/usr/bin/env mers<br><br>// helper functions<br><br>fn read_string(path string) {<br>    bytes_to_string(fs_read(path).assume_no_enum()).assume_no_enum()<br>}<br>fn code_to_html(code string code_width_limit_chars int) {<br>    out = ""<br>    for line code.regex(".*").assume_no_enum() {<br>        if code_width_limit_chars.gtoe(0).and(line.len().gt(code_width_limit_chars)) {<br>            line = line.substring(0 code_width_limit_chars)<br>        }<br>        line = line<br>            .replace("&" "&amp;")<br>            .replace("<" "&lt;")<br>            .replace(">" "&gt;")<br>        out = out.add(line.add("<br>"))<br>    }<br>    out<br>}<br><br>// data<br><br>index = read_string("index.html")<br><br>index_html = index.code_to_html(75)<br>build_script = read_string("build.mers").code_to_html(-1)<br>welcome_script = read_string("welcome.mers").code_to_html(-1)<br><br>// process index.html<br><br>out = ""<br>for line index.regex("\\S*.*").assume_no_enum() {<br>    if line.starts_with("#") {<br>        // comment, ignore<br>    } else if line.starts_with("$") {<br>        if line.eq("$welcome_script") {<br>            out = out.add(welcome_script)<br>        } else if line.eq("$build_script") {<br>            out = out.add(build_script)<br>        } else if line.eq("$index.html") {<br>            out = out.add(index_html)<br>        }<br>    } else {<br>        // remove spaces<br>        loop {<br>            if line.starts_with(" ") {<br>                line = line.substring(1)<br>            } else {<br>                true // break<br>            }<br>        }<br>        out = out.add(line.add("\n"))<br>    }<br>}<br><br>fs_write("../index.html" string_to_bytes(out)).assume_no_enum()<br><br></code></pre> | ||||
| </section> | ||||
| </body> | ||||
| 
 | ||||
| @ -17,36 +17,37 @@ fn get_number_input(question string) { | ||||
| 
 | ||||
| answer = get_number_input("What is your favorite number?") | ||||
| 
 | ||||
| answer.debug() // type: int/float/Err(string) | ||||
| // switch can be used to branch based on a variables type. | ||||
| // switch! indicates that every possible type must be handled. | ||||
| switch! answer { | ||||
|     int { | ||||
|         println("Entered an integer") | ||||
|         answer.debug() // int | ||||
|         answer.debug() // type: int | ||||
|     } | ||||
|     float { | ||||
|         println("Entered a decimal number") | ||||
|         answer.debug() // float | ||||
|         answer.debug() // type: float | ||||
|     } | ||||
|     Err(string) println("Input was not a number!") | ||||
| } | ||||
| 
 | ||||
| sleep(2) | ||||
| // wait one second | ||||
| sleep(1) | ||||
| 
 | ||||
| 
 | ||||
| // function that returns an anonymous function (function object). | ||||
| // anonymous functions can be used as iterators in for-loops. | ||||
| fn count_up() { | ||||
|     count = -1 | ||||
| fn square_numbers() { | ||||
|     i = 0 | ||||
|     () { | ||||
|         count = count.add(1) | ||||
|         count | ||||
|         i = i + 1 | ||||
|         i * i | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| for num count_up() { | ||||
| for num square_numbers() { | ||||
|     println(num.to_string()) | ||||
|     // once num is greater than 60, | ||||
|     // the loop stops and returns num. | ||||
|     if num.gt(60) num else [] | ||||
|     // once num is greater than 60, the loop stops. | ||||
|     num.gt(50) | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 mark
						mark