mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-12 04:58:18 +03:00
105 lines
1.6 KiB
Plaintext
105 lines
1.6 KiB
Plaintext
|
|
;; Generic Arrays
|
|
|
|
(defn get-a-float [xs]
|
|
(* 2.0f (nth xs 0)))
|
|
|
|
(defn test-get-a-float []
|
|
(do (bake get-a-float)))
|
|
|
|
(test-get-a-float)
|
|
|
|
|
|
|
|
(defn array-literal []
|
|
[10 20 30])
|
|
|
|
(defn test-array-literal []
|
|
(bake array-literal))
|
|
|
|
(test-array-literal)
|
|
|
|
|
|
|
|
(defn get-a-float [xs]
|
|
(* 2.0f (nth xs 0)))
|
|
|
|
(defn test-get-a-float []
|
|
(do
|
|
(bake get-a-float)))
|
|
|
|
|
|
|
|
(defn test-int-array []
|
|
(+ 100 (nth (array-of-size 3) 0)))
|
|
|
|
;; (test-int-array) ;; FAILS...
|
|
|
|
|
|
|
|
(defn small-array []
|
|
(let [a (array-of-size 3)
|
|
b (array-set a 0 10)
|
|
c (array-set b 1 20)
|
|
d (array-set c 2 30)]
|
|
d))
|
|
|
|
(bake small-array)
|
|
;; (def small-ast (lambda-to-ast (code small-array)))
|
|
;; (def small-con (gencon small-ast))
|
|
;; (def small-sol (solve-constraints small-con))
|
|
;; (def small-asta (annotate-ast small-ast))
|
|
|
|
|
|
|
|
(defn small-array-2 []
|
|
(array-set
|
|
(array-set
|
|
(array-set
|
|
(array-of-size 3)
|
|
0 10)
|
|
1 20)
|
|
2 30))
|
|
|
|
(bake small-array-2)
|
|
;; (def small-2-ast (lambda-to-ast (code small-array-2)))
|
|
;; (def small-2-con (gencon small-2-ast))
|
|
;; (def small-2-sol (solve-constraints small-2-con))
|
|
;; (def small-2-asta (annotate-ast small-2-ast))
|
|
|
|
|
|
|
|
(defn array-literal []
|
|
[10 20 30])
|
|
|
|
(bake array-literal)
|
|
|
|
|
|
|
|
(defn array-literal-2 []
|
|
[10.1 20.7 30.2])
|
|
|
|
(bake array-literal-2)
|
|
|
|
|
|
|
|
(defn array-of-arrays []
|
|
[(array-literal) (array-literal)])
|
|
|
|
(bake array-of-arrays)
|
|
|
|
|
|
|
|
(defstruct Vector
|
|
[x :int
|
|
y :int])
|
|
|
|
(defn test-print-array-of-vector []
|
|
(let [vecs [(Vector 1001 1002)
|
|
(Vector 1003 1004)
|
|
(Vector 1005 1006)]]
|
|
(assert-eq "[(Vector 1001 1002) (Vector 1003 1004) (Vector 1005 1006)]" (str vecs))))
|
|
|
|
(test-print-array-of-vector)
|
|
|