Created
          July 28, 2019 14:22 
        
      - 
      
 - 
        
Save mflatt/f7313e1561210be56313903fd75c6607 to your computer and use it in GitHub Desktop.  
    statement trees based on binary operators
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Designated "statement" grouping operators with precedence from | |
| strongest to weakest: | |
| , => = & | : | |
| Examples, showing intended use followed by full parenthesization: | |
| define : f(s) = | |
| printf("hi ~a\n", s), | |
| "hi" | |
| | f(s, x) = f(x+y) | |
| (define : ((f(s) = | |
| (printf("hi ~a\n", s), | |
| "hi")) | |
| | (f(s, x) = f(x+y)))) | |
| define : f(s) = | |
| printf("hi ~a\n", s), | |
| "hi" | |
| (define : (f(s) = | |
| (printf("hi ~a\n", s), | |
| "hi"))) | |
| cond : | |
| is_one() => "one" | |
| | is_two() => "two" | |
| | else => printf("else\n"), "many" | |
| (cond : | |
| (((is_one() => "one") | |
| | (is_two() => "two")) | |
| | (else => (printf("else\n"), "many")))) | |
| match : v : | |
| "apple" => "apple pie" | |
| | cons($x, $y) => string_append(x, " ", y) | |
| | _ => error("unknown combination") | |
| (match : (v : | |
| ((("apple" => "apple pie") | |
| | (cons($x, $y) => string_append(x, " ", y)) | |
| | (_ => error("unknown combination")))))) | |
| map(lambda : (x, y) => x+y, | |
| list(1, 2, 3), | |
| list(3, 4, 5)) | |
| map((lambda : ((x, y) => x+y)), | |
| list(1, 2, 3), | |
| list(3, 4, 5)) | |
| map(lambda : (0, y) => y | |
| | (x, y) => x+y, | |
| list(1, 2, 3), | |
| list(3, 4, 5)) | |
| map((lambda : (((0, y) => y) | |
| | (x, y) => x+y)), | |
| list(1, 2, 3), | |
| list(3, 4, 5)) | |
| and : f() & g() & h() | |
| (and : ((f() & g()) & h())) | |
| or : f() | g() | h() | |
| (or : ((f() | g()) | h())) | |
| let : x = 1 : | |
| f(x, x) | |
| (let : ((x = 1) : | |
| f(x, x))) | |
| let : x = 1 | |
| & y = 2 | |
| & z = 3 : | |
| x+y+z | |
| (let : (((x = 1) | |
| & (y = 2)) | |
| & (z = 3)) : | |
| x+y+z) | |
| define : powerset(s) = | |
| (generator : () => | |
| (cond : | |
| is_empty(s) => yield(empty) | |
| | else => (for : e = in_producer(powerset(rest(s))) | |
| yield(cons(first(s), e)), | |
| yield(e))), | |
| void()) | |
| (define : (powerset(s) = | |
| (generator : () => | |
| (cond : | |
| ((is_empty(s) => yield(empty)) | |
| | (else => (for : e = in_producer(powerset(rest(s))) | |
| yield(cons(first(s), e)), | |
| yield(e)))))), | |
| void())) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment