diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 39 |
1 files changed, 37 insertions, 2 deletions
@@ -2,12 +2,47 @@ A place where I can make some bad decisions. -Puck is an experimental, memory safe, strongly typed, imperative and functional programming language. +Puck is an experimental, memory safe, structurally typed, imperative and functional programming language. It aims to be clean and succinct while performant: having the flexibility/metaprogramming of [Nim](https://nim-lang.org/) with the error handling of [Swift](https://www.swift.org/) and the performance/safety guarantees of [Rust](https://www.rust-lang.org/). You may judge for yourself if Puck meets these ideals. -```puck +```nim +import std/tables + +module AST: + pub type Value = interface + func repr(self: Self): string + pub type Ident = string + pub type Expr = ref union + Literal: Value + Variable: Ident + Abstraction: struct[param: Ident, body: Expr] + Application: struct[body, arg: Expr] + Conditional: struct + cond, then_case, else_case: Expr + + pub func eval(expr: Expr, context: var HashTable[Ident, ref Value]): Result[ref Value] + match expr + of Literal(value): + Okay(value) + of Variable(ident): + context.get(ident) + of Application{body, arg}: + if body of Abstraction{param, body as inner_body}: + context.set(param, eval(arg)) + inner_body.eval(context) + else: + Error(InvalidExpr) + of Conditional{cond, then_case, else_case}: + if eval(cond, context): + then_case.eval(context) + else: + else_case.eval(context) + of _: + Error(InvalidExpr) + +AST.eval((λx.x) 413) ``` ## Why Puck? |