From 6c1901cccb2701120e640b2b0044d05047ce9642 Mon Sep 17 00:00:00 2001 From: hellerve Date: Tue, 28 Jan 2020 19:31:05 +0100 Subject: [PATCH 1/2] core: add const --- core/Generics.carp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/Generics.carp b/core/Generics.carp index 456050e3..b1598291 100644 --- a/core/Generics.carp +++ b/core/Generics.carp @@ -74,6 +74,7 @@ The margin of error is 0.00001.") (not (neg? x))) (defn id [x] x) +(defn const [x] (fn [_] x)) (defn null? [p] (Pointer.eq NULL (the (Ptr t) p))) @@ -106,4 +107,4 @@ The margin of error is 0.00001.") (defn /= [a b] (not (= a b))) -) \ No newline at end of file +) From 29d34bbeeecc8fdf0df0a7c97001bd42e9b34244 Mon Sep 17 00:00:00 2001 From: hellerve Date: Tue, 28 Jan 2020 21:32:15 +0100 Subject: [PATCH 2/2] test: add generics --- test/generics.carp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/generics.carp diff --git a/test/generics.carp b/test/generics.carp new file mode 100644 index 00000000..082477e2 --- /dev/null +++ b/test/generics.carp @@ -0,0 +1,21 @@ +(load "Test.carp") + +(use Test) + +(deftest test + (assert-equal test + 1 + (id 1) + "id works I" + ) + (assert-equal test + &(Maybe.Just 1) + &(id (Maybe.Just 1)) + "id works II" + ) + (assert-equal test + 20 + ((const 20) 1) + "const works" + ) +)