mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-04 01:25:04 +03:00
Add some more calls to implement to make tests pass
This commit is contained in:
parent
e6f8f3aff1
commit
f13a2fdd9d
@ -105,6 +105,7 @@ Returns `Nothing` if the array is empty.")
|
||||
(set! eq false)
|
||||
(break))))
|
||||
eq)))
|
||||
(implements = Array.=)
|
||||
|
||||
(doc maximum "gets the maximum in an array (elements must support `<`) and wraps it in a `Just`.
|
||||
|
||||
@ -144,6 +145,7 @@ If the array is empty, returns `Nothing`")
|
||||
(for [i start-index end-index]
|
||||
(set! result (push-back result @(unsafe-nth xs i))))
|
||||
result))
|
||||
(implements slice Array.slice)
|
||||
|
||||
(doc prefix "gets a prefix array to `end-index`.")
|
||||
(defn prefix [xs end-index]
|
||||
|
@ -13,6 +13,8 @@
|
||||
|
||||
(defmodule RefBool
|
||||
(defn = [a b]
|
||||
(Bool.= @a @b)))
|
||||
(Bool.= @a @b))
|
||||
(implements = RefBool.=)
|
||||
)
|
||||
|
||||
(defn not [a] (Bool.not a))
|
||||
|
@ -58,11 +58,15 @@
|
||||
(defmodule CharRef
|
||||
(defn = [a b]
|
||||
(Char.= @a @b))
|
||||
(implements = CharRef.=)
|
||||
(defn < [a b]
|
||||
(Char.< @a @b))
|
||||
(implements < CharRef.<)
|
||||
(defn > [a b]
|
||||
(Char.> @a @b))
|
||||
(implements > CharRef.>)
|
||||
)
|
||||
|
||||
(defmodule PtrChar
|
||||
(register str (Fn [(Ptr Char)] String)))
|
||||
(register str (Fn [(Ptr Char)] String))
|
||||
(implements str PtrChar.str))
|
||||
|
@ -1,5 +1,9 @@
|
||||
(definterface unsafe-nth (Fn [(Ref (a b) c) Int] &b))
|
||||
(implements unsafe-nth Array.unsafe-nth)
|
||||
(implements unsafe-nth StaticArray.unsafe-nth)
|
||||
(definterface length (Fn [(Ref (a b))] Int))
|
||||
(implements unsafe-nth Array.length)
|
||||
(implements unsafe-nth StaticArray.length)
|
||||
|
||||
(defmodule Collections
|
||||
(defn empty? [a]
|
||||
|
@ -27,8 +27,10 @@
|
||||
(use Id)
|
||||
(defn hash [k]
|
||||
(get-tag k))
|
||||
(implements hash Color.hash)
|
||||
(defn = [a b]
|
||||
(= (hash (the (Ref Id) a)) (hash b)))
|
||||
(implements = Color.=)
|
||||
|
||||
(def table
|
||||
{(Black) @"30"
|
||||
|
@ -68,7 +68,8 @@
|
||||
(implements floor Double.floor)
|
||||
(implements frexp Double.frexp)
|
||||
(implements ldexp Double.ldexp)
|
||||
(implements log Double.log10)
|
||||
(implements log Double.log)
|
||||
(implements log10 Double.log10)
|
||||
(implements mod Double.mod)
|
||||
(implements modf Double.modf)
|
||||
(implements pow Double.pow)
|
||||
@ -95,7 +96,7 @@ The margin of error is `0.00001`.")
|
||||
|
||||
(defn dec [x]
|
||||
(- x 1.0))
|
||||
(implements inc Double.dec)
|
||||
(implements dec Double.dec)
|
||||
|
||||
(defn add-ref [x y]
|
||||
(Double.+ @x @y))
|
||||
@ -105,10 +106,13 @@ The margin of error is `0.00001`.")
|
||||
(defmodule DoubleRef
|
||||
(defn = [a b]
|
||||
(Double.= @a @b))
|
||||
(implements = DoubleRef.=)
|
||||
|
||||
(defn < [a b]
|
||||
(Double.< @a @b))
|
||||
(implements < DoubleRef.<)
|
||||
|
||||
(defn > [a b]
|
||||
(Double.> @a @b))
|
||||
(implements > DoubleRef.>)
|
||||
)
|
||||
|
@ -79,7 +79,8 @@ The margin of error is 0.00001.")
|
||||
(implements floor Float.floor)
|
||||
(implements frexp Float.frexp)
|
||||
(implements ldexp Float.ldexp)
|
||||
(implements log Float.log10)
|
||||
(implements log Float.log)
|
||||
(implements log10 Float.log10)
|
||||
(implements mod Float.mod)
|
||||
(implements modf Float.modf)
|
||||
(implements pow Float.pow)
|
||||
|
@ -95,10 +95,13 @@
|
||||
(defmodule IntRef
|
||||
(defn = [a b]
|
||||
(Int.= @a @b))
|
||||
(implements = IntRef.=)
|
||||
|
||||
(defn < [a b]
|
||||
(Int.< @a @b))
|
||||
(implements < IntRef.<)
|
||||
|
||||
(defn > [a b]
|
||||
(Int.> @a @b))
|
||||
(implements > IntRef.>)
|
||||
)
|
||||
|
@ -11,66 +11,82 @@
|
||||
(set! a (* a b))
|
||||
(set! x (Int.inc x))))
|
||||
(Int.abs vh)))
|
||||
(implements hash String.hash)
|
||||
)
|
||||
|
||||
(defmodule Int
|
||||
(defn hash [k] (the Int @k))
|
||||
(implements hash Int.hash)
|
||||
)
|
||||
|
||||
(defmodule Long
|
||||
(defn hash [k] (to-int (the Long @k)))
|
||||
(implements hash Long.hash)
|
||||
)
|
||||
|
||||
(defmodule Bool
|
||||
(defn hash [k] (if (the Bool @k) 1 0))
|
||||
(implements hash Bool.hash)
|
||||
)
|
||||
|
||||
(defmodule Char
|
||||
(defn hash [k] (to-int (the Char @k)))
|
||||
(implements hash Char.hash)
|
||||
)
|
||||
|
||||
(defmodule Byte
|
||||
(defn hash [k] (to-int (the Byte @k)))
|
||||
(implements hash Byte.hash)
|
||||
)
|
||||
|
||||
(defmodule Float
|
||||
(defn hash [k] (Float.to-bytes @k))
|
||||
(implements hash Float.hash)
|
||||
)
|
||||
|
||||
(defmodule Double
|
||||
(defn hash [k] (Long.to-int (Double.to-bytes @k)))
|
||||
(implements hash Double.hash)
|
||||
)
|
||||
|
||||
(defmodule Int8
|
||||
(defn hash [k] (Long.to-int (Int8.to-long @k)))
|
||||
(implements hash Int8.hash)
|
||||
)
|
||||
|
||||
(defmodule Int16
|
||||
(defn hash [k] (Long.to-int (Int16.to-long @k)))
|
||||
(implements hash Int16.hash)
|
||||
)
|
||||
|
||||
(defmodule Int32
|
||||
(defn hash [k] (Long.to-int (Int32.to-long @k)))
|
||||
(implements hash Int32.hash)
|
||||
)
|
||||
|
||||
(defmodule Int64
|
||||
(defn hash [k] (Long.to-int (Int64.to-long @k)))
|
||||
(implements hash Int64.hash)
|
||||
)
|
||||
|
||||
(defmodule Uint8
|
||||
(defn hash [k] (Long.to-int (Uint8.to-long @k)))
|
||||
(implements hash Uint8.hash)
|
||||
)
|
||||
|
||||
(defmodule Uint16
|
||||
(defn hash [k] (Long.to-int (Uint16.to-long @k)))
|
||||
(implements hash Uint16.hash)
|
||||
)
|
||||
|
||||
(defmodule Uint32
|
||||
(defn hash [k] (Long.to-int (Uint32.to-long @k)))
|
||||
(implements hash Uint32.hash)
|
||||
)
|
||||
|
||||
(defmodule Uint64
|
||||
(defn hash [k] (Long.to-int (Uint64.to-long @k)))
|
||||
(implements hash Uint64.hash)
|
||||
)
|
||||
|
||||
(defmodule Pair
|
||||
@ -79,6 +95,7 @@
|
||||
(set! code (+ (* 31 code) (hash (Pair.a pair))))
|
||||
(set! code (+ (* 31 code) (hash (Pair.b pair))))
|
||||
code))
|
||||
(implements hash Pair.hash)
|
||||
)
|
||||
|
||||
(deftype (Bucket a b) [entries (Array (Pair a b))])
|
||||
@ -261,6 +278,7 @@
|
||||
(and (= (length m1) (length m2))
|
||||
;; we could use contains? and get-with-default here to avoid requiring a (zero) for the value type
|
||||
(all? &(fn [k v] (= v &(get m2 k))) m1)))
|
||||
(implements = Map.=)
|
||||
|
||||
(doc for-each "Execute the binary function f for all keys and values in the map m.")
|
||||
(defn for-each [m f]
|
||||
@ -449,6 +467,7 @@
|
||||
(defn = [set-a set-b]
|
||||
(and (= (Set.length set-a) (Set.length set-b))
|
||||
(subset? set-a set-b)))
|
||||
(implements = Set.=)
|
||||
|
||||
(doc for-each "Execute the unary function f for each element in the set s.")
|
||||
(defn for-each [s f]
|
||||
@ -507,4 +526,5 @@
|
||||
@"{"
|
||||
set)]
|
||||
(String.append &res " }")))
|
||||
(implements str Set.str)
|
||||
)
|
||||
|
@ -51,6 +51,7 @@ It is the inverse of [`just?`](#just?).")
|
||||
(match-ref b
|
||||
(Nothing) false
|
||||
(Just y) (= x y))))
|
||||
(implements = Maybe.=)
|
||||
|
||||
(doc unsafe-ptr "Creates a `(Ptr a)` from a `(Maybe a)`. If the `Maybe` was
|
||||
`Nothing`, this function will return a `NULL` value.")
|
||||
@ -69,4 +70,5 @@ It is the inverse of [`just?`](#just?).")
|
||||
|
||||
(doc zero "returns `Nothing`.")
|
||||
(defn zero [] (Nothing))
|
||||
(implements zero Maybe.zero)
|
||||
)
|
||||
|
@ -29,12 +29,16 @@ If you want to replace all occurrences of the pattern, use `-1`.")
|
||||
(defn matches? [pat s] (/= (find pat s) -1))
|
||||
|
||||
(register str (Fn [&Pattern] String))
|
||||
(implements str Pattern.str)
|
||||
(register prn (Fn [&Pattern] String))
|
||||
(implements prn Pattern.prn)
|
||||
|
||||
(register init (Fn [&String] Pattern))
|
||||
(register = (Fn [&Pattern &Pattern] Bool))
|
||||
(implements = Pattern.=)
|
||||
(register delete (Fn [Pattern] ()))
|
||||
(register copy (Fn [&Pattern] Pattern))
|
||||
(implements copy Pattern.copy)
|
||||
|
||||
(doc from-chars "creates a pattern that matches a group of characters from a list of those characters.")
|
||||
(defn from-chars [chars]
|
||||
|
@ -1,4 +1,6 @@
|
||||
(defmodule Pointer
|
||||
(defn inc [a] (Pointer.add a 1l))
|
||||
(implements inc Pointer.inc)
|
||||
(defn dec [a] (Pointer.sub a 1l))
|
||||
(implements dec Pointer.dec)
|
||||
)
|
||||
|
@ -106,6 +106,7 @@ It is the inverse of [`success?`](#success?).")
|
||||
(match-ref b
|
||||
(Success _) false
|
||||
(Error y) (= x y))))
|
||||
(implements = Result.=)
|
||||
)
|
||||
|
||||
(defmodule Maybe
|
||||
|
@ -50,6 +50,9 @@
|
||||
(defn prn [a] (Int8.prn @a))
|
||||
(defn str [a] (Int8.str @a))
|
||||
(defn = [a b] (Int8.= @a @b))
|
||||
(implements prn Int8Extra.prn)
|
||||
(implements str Int8Extra.str)
|
||||
(implements = Int8Extra.=)
|
||||
)
|
||||
|
||||
(defmodule Int16
|
||||
@ -93,6 +96,9 @@
|
||||
(defn prn [a] (Int16.prn @a))
|
||||
(defn str [a] (Int16.str @a))
|
||||
(defn = [a b] (Int16.= @a @b))
|
||||
(implements prn Int16Extra.prn)
|
||||
(implements str Int16Extra.str)
|
||||
(implements = Int16Extra.=)
|
||||
)
|
||||
|
||||
(defmodule Int32
|
||||
@ -136,6 +142,9 @@
|
||||
(defn prn [a] (Int32.prn @a))
|
||||
(defn str [a] (Int32.str @a))
|
||||
(defn = [a b] (Int32.= @a @b))
|
||||
(implements prn Int32Extra.prn)
|
||||
(implements str Int32Extra.str)
|
||||
(implements = Int32Extra.=)
|
||||
)
|
||||
|
||||
(defmodule Int64
|
||||
@ -179,6 +188,9 @@
|
||||
(defn prn [a] (Int64.prn @a))
|
||||
(defn str [a] (Int64.str @a))
|
||||
(defn = [a b] (Int64.= @a @b))
|
||||
(implements prn Int64Extra.prn)
|
||||
(implements str Int64Extra.str)
|
||||
(implements = Int64Extra.=)
|
||||
)
|
||||
|
||||
(defmodule Uint8
|
||||
@ -222,6 +234,9 @@
|
||||
(defn prn [a] (Uint8.prn @a))
|
||||
(defn str [a] (Uint8.str @a))
|
||||
(defn = [a b] (Uint8.= @a @b))
|
||||
(implements prn Uint8Extra.prn)
|
||||
(implements str Uint8Extra.str)
|
||||
(implements = Uint8Extra.=)
|
||||
)
|
||||
|
||||
(defmodule Uint16
|
||||
@ -265,6 +280,9 @@
|
||||
(defn prn [a] (Uint16.prn @a))
|
||||
(defn str [a] (Uint16.str @a))
|
||||
(defn = [a b] (Uint16.= @a @b))
|
||||
(implements prn Uint16Extra.prn)
|
||||
(implements str Uint16Extra.str)
|
||||
(implements = Uint16Extra.=)
|
||||
)
|
||||
|
||||
(defmodule Uint32
|
||||
@ -308,6 +326,9 @@
|
||||
(defn prn [a] (Uint32.prn @a))
|
||||
(defn str [a] (Uint32.str @a))
|
||||
(defn = [a b] (Uint32.= @a @b))
|
||||
(implements prn Uint32Extra.prn)
|
||||
(implements str Uint32Extra.str)
|
||||
(implements = Uint32Extra.=)
|
||||
)
|
||||
|
||||
(defmodule Uint64
|
||||
@ -351,4 +372,7 @@
|
||||
(defn prn [a] (Uint64.prn @a))
|
||||
(defn str [a] (Uint64.str @a))
|
||||
(defn = [a b] (Uint64.= @a @b))
|
||||
(implements prn Uint64Extra.prn)
|
||||
(implements str Uint64Extra.str)
|
||||
(implements = Uint64Extra.=)
|
||||
)
|
||||
|
@ -20,6 +20,7 @@
|
||||
(register from-chars (Fn [&(Array Char)] String))
|
||||
(register tail (λ [(Ref String)] String))
|
||||
(register format (Fn [&String &String] String))
|
||||
(implements format String.format)
|
||||
(register string-set! (Fn [&String Int Char] ()))
|
||||
(register string-set-at! (Fn [&String Int &String] ()))
|
||||
(register allocate (Fn [Int Char] String))
|
||||
@ -171,14 +172,15 @@
|
||||
|
||||
(defn < [a b]
|
||||
(String.< &a &b))
|
||||
(implements = StringCopy.<)
|
||||
(implements < StringCopy.<)
|
||||
|
||||
(defn > [a b]
|
||||
(String.> &a &b))
|
||||
(implements = StringCopy.>)
|
||||
(implements > StringCopy.>)
|
||||
|
||||
(defn prn [s]
|
||||
(prn &(the String s)))
|
||||
(implements prn StringCopy.prn)
|
||||
|
||||
(defn str [s]
|
||||
(str &(the String s)))
|
||||
@ -187,12 +189,14 @@
|
||||
|
||||
(defmodule Bool
|
||||
(register str (Fn [Bool] String))
|
||||
(implements str Bool.str)
|
||||
(register format (Fn [&String Bool] String))
|
||||
(implements format Bool.format)
|
||||
)
|
||||
|
||||
(defmodule Int
|
||||
(register str (Fn [Int] String))
|
||||
(implements str Int.str)
|
||||
(register format (Fn [&String Int] String))
|
||||
(implements format Int.format)
|
||||
(register from-string (λ [&String] Int))
|
||||
@ -201,6 +205,7 @@
|
||||
|
||||
(defmodule Byte
|
||||
(register str (Fn [Byte] String))
|
||||
(implements str Byte.str)
|
||||
(register format (Fn [&String Byte] String))
|
||||
(implements format Byte.format)
|
||||
(register from-string (λ [&String] Byte))
|
||||
@ -209,6 +214,7 @@
|
||||
|
||||
(defmodule Float
|
||||
(register str (Fn [Float] String))
|
||||
(implements str Float.str)
|
||||
(register format (Fn [&String Float] String))
|
||||
(implements format Float.format)
|
||||
(register from-string (λ [&String] Float))
|
||||
@ -217,6 +223,7 @@
|
||||
|
||||
(defmodule Long
|
||||
(register str (Fn [Long] String))
|
||||
(implements str Long.str)
|
||||
(register format (Fn [&String Long] String))
|
||||
(implements format Long.format)
|
||||
(register from-string (λ [&String] Long))
|
||||
@ -225,6 +232,7 @@
|
||||
|
||||
(defmodule Double
|
||||
(register str (Fn [Double] String))
|
||||
(implements str Double.str)
|
||||
(register format (Fn [&String Double] String))
|
||||
(implements format Double.format)
|
||||
(register from-string (λ [&String] Double))
|
||||
@ -233,6 +241,7 @@
|
||||
|
||||
(defmodule Char
|
||||
(register str (Fn [Char] String))
|
||||
(implements str Char.str)
|
||||
(register prn (Fn [Char] String))
|
||||
(implements prn Char.prn)
|
||||
(register format (Fn [&String Char] String))
|
||||
@ -245,17 +254,21 @@
|
||||
(defn prn [x] (Int.str @x))
|
||||
(implements prn IntRef.prn)
|
||||
(defn str [x] (Int.str @x))
|
||||
(implements str IntRef.str)
|
||||
)
|
||||
|
||||
(defmodule BoolRef
|
||||
(defn prn [x] (Bool.str @x))
|
||||
(implements prn BoolRef.prn)
|
||||
(defn str [x] (Bool.str @x)))
|
||||
(defn str [x] (Bool.str @x))
|
||||
(implements str BoolRef.str)
|
||||
)
|
||||
|
||||
(defmodule ByteRef
|
||||
(defn prn [x] (Byte.str @x))
|
||||
(implements prn ByteRef.prn)
|
||||
(defn str [x] (Byte.str @x))
|
||||
(implements str ByteRef.str)
|
||||
)
|
||||
|
||||
(defmodule Long (defn prn [x] (Long.str x)) (implements prn Long.prn))
|
||||
|
@ -4,14 +4,17 @@
|
||||
(defn = [p1 p2]
|
||||
(and (= (Pair.a p1) (Pair.a p2))
|
||||
(= (Pair.b p1) (Pair.b p2))))
|
||||
(implements = PairRef.=)
|
||||
|
||||
(defn < [p1 p2]
|
||||
(if (= (Pair.a p1) (Pair.a p2))
|
||||
(< (Pair.b p1) (Pair.b p2))
|
||||
(< (Pair.a p1) (Pair.a p2))))
|
||||
(implements < PairRef.<)
|
||||
|
||||
(defn > [p1 p2]
|
||||
(PairRef.< p2 p1)))
|
||||
(implements > PairRef.=)
|
||||
|
||||
(defmodule Pair
|
||||
(defn init-from-refs [r1 r2]
|
||||
@ -20,12 +23,15 @@
|
||||
(defn = [p1 p2]
|
||||
(and (= (Pair.a &p1) (Pair.a &p2))
|
||||
(= (Pair.b &p1) (Pair.b &p2))))
|
||||
(implements = Pair.=)
|
||||
|
||||
(defn < [p1 p2]
|
||||
(PairRef.< &p1 &p2))
|
||||
(implements < Pair.<)
|
||||
|
||||
(defn > [p1 p2]
|
||||
(PairRef.> &p1 &p2))
|
||||
(implements > Pair.>)
|
||||
|
||||
(doc reverse "reverses a `Pair` `p` such that its first member is its second member and vice versa.")
|
||||
(defn reverse [p]
|
||||
|
@ -7,13 +7,15 @@
|
||||
|
||||
(defmodule ArrayExtension
|
||||
(defn fmap [f a] (Array.endo-map f a))
|
||||
(implements fmap ArrayExtension.fmap)
|
||||
)
|
||||
|
||||
(deftype Box [x Int])
|
||||
|
||||
(defmodule Box
|
||||
(defn fmap [f box] (let [new-x (~f @(Box.x &box))]
|
||||
(Box.set-x box new-x))))
|
||||
(Box.set-x box new-x)))
|
||||
(implements fmap Box.fmap))
|
||||
|
||||
(use Box)
|
||||
(use ArrayExtension)
|
||||
|
@ -9,7 +9,12 @@
|
||||
(defn > [a b]
|
||||
(> (Age.x a) (Age.x b)))
|
||||
(defn < [a b]
|
||||
(< (Age.x a) (Age.x b))))
|
||||
(< (Age.x a) (Age.x b)))
|
||||
|
||||
(implements = Age.=)
|
||||
(implements > Age.>)
|
||||
(implements < Age.<)
|
||||
)
|
||||
|
||||
(defn main []
|
||||
(let-do [ints (Array.sort [10 3 75 40])
|
||||
|
@ -291,9 +291,11 @@
|
||||
(defn < [a b]
|
||||
(< (Array.length a)
|
||||
(Array.length b)))
|
||||
(implements < ArrayCompareExtension.<)
|
||||
(defn > [a b]
|
||||
(> (Array.length a)
|
||||
(Array.length b))))
|
||||
(implements > ArrayCompareExtension.>)
|
||||
(defn array-sort-1 []
|
||||
(let [xs [[0 0] [0 0 0] [0 0 0 0] [0]]
|
||||
ys (Array.sort xs)]
|
||||
|
@ -15,11 +15,13 @@
|
||||
;; A function with correct nr of args but just generic types used to really confuse the type checker:
|
||||
(defmodule Confuse
|
||||
(defn = [a b]
|
||||
true))
|
||||
true)
|
||||
(implements = Confuse.=))
|
||||
|
||||
(defmodule Young
|
||||
(defn = [y1 y2]
|
||||
(Int.= @(age y1) @(age y2))))
|
||||
(Int.= @(age y1) @(age y2)))
|
||||
(implements = Young.=))
|
||||
|
||||
;; Now I want to use 'Young.=' in with 'Ur.compare'
|
||||
(defn f []
|
||||
|
Loading…
Reference in New Issue
Block a user