summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-08-15 20:24:01 +0200
committernea <nea@nea.moe>2023-08-15 20:24:01 +0200
commit54b0f2ea841d2ce3895713415481271aa3034b30 (patch)
tree401775e9ce327506546fa614e79decb667ab1aa4 /res
parentd1f49743a0a00a1156272d174e8b6b5c4bb9acec (diff)
downloadnealisp-54b0f2ea841d2ce3895713415481271aa3034b30.tar.gz
nealisp-54b0f2ea841d2ce3895713415481271aa3034b30.tar.bz2
nealisp-54b0f2ea841d2ce3895713415481271aa3034b30.zip
Add support for hex literals
Diffstat (limited to 'res')
-rw-r--r--res/builtins.lisp3
-rw-r--r--res/stdtest.lisp7
2 files changed, 10 insertions, 0 deletions
diff --git a/res/builtins.lisp b/res/builtins.lisp
index 64c59d3..19bab1f 100644
--- a/res/builtins.lisp
+++ b/res/builtins.lisp
@@ -28,6 +28,9 @@
(defun gt (l r) (lt r l))
(export gt)
+(comment "The absolute value returns the argument if it is non negative or (- 0 arg) if it is")
+(defun abs (arg) (if (lt arg 0) (- 0 arg) arg))
+(export abs)
(comment "if! a strict version of a regular if, meaning it evaluates both the falsy and the truthy case, instead of only one.")
(defun if! (cond ifTrue ifFalse) (if cond ifTrue ifFalse))
diff --git a/res/stdtest.lisp b/res/stdtest.lisp
index 42f9c94..b7553fa 100644
--- a/res/stdtest.lisp
+++ b/res/stdtest.lisp
@@ -20,3 +20,10 @@
(= actual expected)
(stringify "Expected" expected "got" actual)))
(export test.assert-eq)
+
+(comment "Assert that two number arguments are equal with some tolerance. Returns a closure")
+(defun test.assert-eqd (actual expected tolerance) (seq
+ (test.assert
+ (lt (abs (- expected actual)) tolerance)
+ (stringify "Expected" expected "got" actual "with a tolerance of" tolerance))))
+(export test.assert-eqd)