Skip to content

Latest commit

 

History

History
64 lines (54 loc) · 1.56 KB

File metadata and controls

64 lines (54 loc) · 1.56 KB

Lem v0.1 Nasty Example Snippets

1. Nested if/else as expressions

let x = if a = if b = 1 else = 2 else = 3
  • Parses as: IfExpr(cond=a, then=IfExpr(cond=b, then=1, else=2), else=3)

2. Match with tuple and wildcard

match t = { (a, _) => 1, _ => 2 }
  • Parses as: MatchExpr(expr=t, arms=[(PatternTuple([a, _]), 1), (PatternWildcard, 2)])

3. Assignment in loop

let mut x = 0
while x < 10 = x = x + 1
  • Parses as: LetStmt(mut), WhileExpr(cond=BinaryExpr(<), body=AssignStmt)

4. Function call with tuple and list

f((1, 2), List[3, 4])
  • Parses as: CallExpr(func=f, args=[TupleExpr, ListExpr])

5. Use with nested block

use f = open_file("foo") in
    if cond = print(read_line(f)) else = print("no")
  • Parses as: UseStmt(name=f, resource=CallExpr, body=IfExpr)

6. Try in match arm

match x = { Some(v) => try f(v), None => 0 }
  • Parses as: MatchExpr(arms=[(PatternOption(Some, v), TryExpr(CallExpr(f, v))), ...])

7. Multiple effects in function

fn foo() with io, time = print(now())
  • Parses as: FnDecl(effects=[io, time], body=ExprStmt(CallExpr))

8. Break with value in loop

loop = if cond = break 42 else = continue
  • Parses as: LoopExpr(body=IfExpr(..., then=BreakStmt(42), else=ExprStmt(continue)))

9. Nested match and if

match x = { Ok(v) => if v > 0 = v else = -v, Err(e) => 0 }
  • Parses as: MatchExpr(arms=[(PatternResult(Ok, v), IfExpr), ...])

10. List and map in let

let xs = List[1,2,3]
let m = Map["a" => 1, "b" => 2]
  • Parses as: LetStmt(xs, ListExpr), LetStmt(m, MapExpr)