Merge pull request #652 from hellerve/veit/const

Add const
This commit is contained in:
Erik Svedäng 2020-01-29 11:02:40 +01:00 committed by GitHub
commit d9a2da18b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

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

21
test/generics.carp Normal file
View File

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