From 32252b8d89a48b6d1626295f24a8c47d85dfbd89 Mon Sep 17 00:00:00 2001 From: darkf Date: Tue, 11 Feb 2014 04:55:40 -0800 Subject: [PATCH] add more std modules --- std/basic.lamb | 6 ++++++ std/math.lamb | 9 +++++++++ std/op.lamb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 std/basic.lamb create mode 100644 std/math.lamb create mode 100644 std/op.lamb diff --git a/std/basic.lamb b/std/basic.lamb new file mode 100644 index 0000000..228ad2b --- /dev/null +++ b/std/basic.lamb @@ -0,0 +1,6 @@ +-- Standard basic library for the Lamb programming language +-- Copyright (c) 2013 darkf +-- Licensed under the terms of the zlib license, see LICENSE for details + +const(x) -> \_ -> x. +compose(f, g) -> \x -> f(g(x)). diff --git a/std/math.lamb b/std/math.lamb new file mode 100644 index 0000000..6787b6f --- /dev/null +++ b/std/math.lamb @@ -0,0 +1,9 @@ +-- Standard math library for the Lamb programming language +-- Copyright (c) 2013 darkf +-- Licensed under the terms of the zlib license, see LICENSE for details + +pow(base, 0) -> 1. +pow(base, exp) -> do + if exp < 0 then 1 / pow(base, neg(exp)) + else base * pow(base, exp-1) +end. \ No newline at end of file diff --git a/std/op.lamb b/std/op.lamb new file mode 100644 index 0000000..5b050d9 --- /dev/null +++ b/std/op.lamb @@ -0,0 +1,30 @@ +-- Standard operators library for the Lamb programming language +-- Copyright (c) 2013 darkf +-- Licensed under the terms of the zlib license, see LICENSE for details + +-- binary operators +add(x,y) -> x+y. +mul(x,y) -> x*y. +div(x,y) -> x/y. + +cons(x,y) -> x::y. + +eq(x,y) -> x==y. +neq(x,y) -> x != y. + +lt(x,y) -> x x>y. + +and(true,true) -> true. +and(_,_) -> false. + +or(true, _) -> true. +or(_, true) -> true. +or(_, _) -> false. + +xor(true, false) -> true. +xor(false, true) -> true. +xor(_, _) -> false. + +-- unary operators +neg(x) -> 0-x.