mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-26 05:45:37 +03:00
commit
7d3931c46a
@ -7,6 +7,11 @@
|
||||
(set! &total (f &total (nth xs i))))
|
||||
total)))
|
||||
|
||||
(defn first [a]
|
||||
@(Array.nth a 0))
|
||||
|
||||
(defn last [a]
|
||||
@(Array.nth a (Int.dec (Array.count a))))
|
||||
)
|
||||
|
||||
;; BUGS! These function definitions will not create the required typedef for Array, for instance:
|
||||
|
@ -1,4 +1,5 @@
|
||||
(defmodule Char
|
||||
(register = (Fn [Char Char] Bool))
|
||||
(register str (Fn [Char] String))
|
||||
(register to-int (Fn [Char] Int))
|
||||
(register from-int (Fn [Int] Char))
|
||||
|
@ -26,5 +26,7 @@
|
||||
|
||||
(defn max [a b] (if (> a b) a b))
|
||||
(defn min [a b] (if (< a b) a b))
|
||||
)
|
||||
|
||||
(defn even? [a] (= (mod a 2) 0))
|
||||
(defn odd? [a] (not (even? a)))
|
||||
)
|
||||
|
@ -30,4 +30,7 @@
|
||||
|
||||
(defn max [a b] (if (> a b) a b))
|
||||
(defn min [a b] (if (< a b) a b))
|
||||
|
||||
(defn even? [a] (= (mod a 2l) 0l))
|
||||
(defn odd? [a] (not (even? a)))
|
||||
)
|
||||
|
@ -68,3 +68,6 @@
|
||||
|
||||
(defmacro ==> [:rest forms]
|
||||
(thread-last-internal forms))
|
||||
|
||||
(defmacro swap! [x y]
|
||||
(list 'let (array 'tmp y) (list 'do (list 'set! &y x) (list 'set! &x 'tmp))))
|
||||
|
@ -261,6 +261,10 @@ string String_from_MINUS_chars(Array a) {
|
||||
return s;
|
||||
}
|
||||
|
||||
bool Char__EQ_(char a, char b) {
|
||||
return a == b;
|
||||
}
|
||||
|
||||
string Char_str(char c) {
|
||||
char *buffer = CARP_MALLOC(3);
|
||||
snprintf(buffer, 3, "\\%c", c);
|
||||
|
16
test/array.carp
Normal file
16
test/array.carp
Normal file
@ -0,0 +1,16 @@
|
||||
(load "Test.carp")
|
||||
|
||||
(use Array)
|
||||
(use Test)
|
||||
|
||||
(defn main []
|
||||
(with-test test
|
||||
(assert-equal test
|
||||
1
|
||||
(first &[1 2 3])
|
||||
"first works as expected")
|
||||
(assert-equal test
|
||||
\c
|
||||
(last &[\a \b \c])
|
||||
"last works as expected")
|
||||
(print-test-results test)))
|
@ -17,4 +17,12 @@
|
||||
1
|
||||
(abs -1)
|
||||
"abs works as expected")
|
||||
(assert-equal test
|
||||
false
|
||||
(even? 3)
|
||||
"even? works as expected")
|
||||
(assert-equal test
|
||||
true
|
||||
(odd? 3)
|
||||
"odd? works as expected")
|
||||
(print-test-results test)))
|
||||
|
@ -17,4 +17,12 @@
|
||||
1l
|
||||
(abs -1l)
|
||||
"abs works as expected")
|
||||
(assert-equal test
|
||||
false
|
||||
(even? 3l)
|
||||
"even? works as expected")
|
||||
(assert-equal test
|
||||
true
|
||||
(odd? 3l)
|
||||
"odd? works as expected")
|
||||
(print-test-results test)))
|
||||
|
Loading…
Reference in New Issue
Block a user