eq? and neq? bugfix; add pow
This commit is contained in:
parent
360be76de9
commit
ec7ffbdd9a
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@ludus/ludus-js-pure",
|
||||
"version": "0.1.38",
|
||||
"version": "0.1.39",
|
||||
"description": "A Ludus interpreter in a pure JS function.",
|
||||
"type": "module",
|
||||
"main": "build/ludus.mjs",
|
||||
|
|
22
prelude.ld
22
prelude.ld
|
@ -81,7 +81,7 @@ fn eq? {
|
|||
(x, y) -> base :eq? (x, y)
|
||||
(x, y, ...zs) -> if eq? (x, y)
|
||||
then loop (y, zs) with {
|
||||
(a, []) -> eq? (a, x)
|
||||
(a, [b]) -> if eq? (a, x) then eq? (a, b) else false
|
||||
(a, [b, ...cs]) -> if eq? (a, x)
|
||||
then recur (b, cs)
|
||||
else false
|
||||
|
@ -123,18 +123,15 @@ fn not {
|
|||
(_) -> false
|
||||
}
|
||||
|
||||
fn neq? {
|
||||
fn neq? {
|
||||
"Returns true if none of the arguments have the same value."
|
||||
(x) -> false
|
||||
(x, y) -> not (eq? (x, y))
|
||||
(x, y, ...zs) -> if eq? (x, y)
|
||||
then false
|
||||
else loop (y, zs) with {
|
||||
(a, []) -> neq? (a, x)
|
||||
(a, [b, ...cs]) -> if neq? (a, x)
|
||||
then recur (b, cs)
|
||||
else false
|
||||
}
|
||||
(x, y, ...zs) -> {
|
||||
let z_set = set(zs)
|
||||
let xyz_set = ${x, y, ...z_set}
|
||||
eq? (count (xyz_set), add(2, count (zs)))
|
||||
}
|
||||
}
|
||||
|
||||
& tuples: not a lot you can do with them functionally
|
||||
|
@ -507,6 +504,11 @@ fn mult {
|
|||
((x, y), scalar as :number) -> mult (scalar, (x, y))
|
||||
}
|
||||
|
||||
fn pow {
|
||||
"Raises a number to the power of another number."
|
||||
(x as :number, y as :number) -> base :pow (x, y)
|
||||
}
|
||||
|
||||
fn div {
|
||||
"Divides numbers. Panics on division by zero."
|
||||
(x as :number) -> x
|
||||
|
|
|
@ -286,6 +286,7 @@
|
|||
"div" /
|
||||
"doc" doc
|
||||
"downcase" string/ascii-lower
|
||||
"e" math/e
|
||||
"eq?" deep=
|
||||
"first" first
|
||||
"floor" math/floor
|
||||
|
@ -302,6 +303,7 @@
|
|||
"nth" ludus/get
|
||||
"or" ludus/or
|
||||
"pi" math/pi
|
||||
"pow" math/pow
|
||||
"print!" print!
|
||||
"prn" prn
|
||||
"push" array/push
|
||||
|
@ -334,4 +336,3 @@
|
|||
(set (b (keyword k)) v))
|
||||
b))
|
||||
|
||||
(to_number " 123 a ")
|
||||
|
|
Loading…
Reference in New Issue
Block a user