add more std modules

This commit is contained in:
darkf 2014-02-11 04:55:40 -08:00
parent f7890c07fe
commit 32252b8d89
3 changed files with 45 additions and 0 deletions

6
std/basic.lamb Normal file
View File

@ -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)).

9
std/math.lamb Normal file
View File

@ -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.

30
std/op.lamb Normal file
View File

@ -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<y.
gt(x,y) -> 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.