|
|
@ -16,8 +16,10 @@ |
|
|
|
|
|
|
|
|
|
|
|
namespace blaze { |
|
|
|
namespace blaze { |
|
|
|
|
|
|
|
|
|
|
|
// (apply + 1 2 (list 3 4)) -> (+ 1 2 3 4) -> 10
|
|
|
|
void Environment::loadCollectionModify() |
|
|
|
ADD_FUNCTION( |
|
|
|
{ |
|
|
|
|
|
|
|
// (apply + 1 2 (list 3 4)) -> (+ 1 2 3 4) -> 10
|
|
|
|
|
|
|
|
ADD_FUNCTION( |
|
|
|
"apply", |
|
|
|
"apply", |
|
|
|
{ |
|
|
|
{ |
|
|
|
CHECK_ARG_COUNT_AT_LEAST("apply", SIZE(), 2); |
|
|
|
CHECK_ARG_COUNT_AT_LEAST("apply", SIZE(), 2); |
|
|
@ -49,8 +51,8 @@ ADD_FUNCTION( |
|
|
|
return value; |
|
|
|
return value; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// (cons 1 (list 2 3))
|
|
|
|
// (cons 1 (list 2 3))
|
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"cons", |
|
|
|
"cons", |
|
|
|
{ |
|
|
|
{ |
|
|
|
CHECK_ARG_COUNT_IS("cons", SIZE(), 2); |
|
|
|
CHECK_ARG_COUNT_IS("cons", SIZE(), 2); |
|
|
@ -68,8 +70,8 @@ ADD_FUNCTION( |
|
|
|
return makePtr<List>(result_nodes); |
|
|
|
return makePtr<List>(result_nodes); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// (concat (list 1) (list 2 3)) -> (1 2 3)
|
|
|
|
// (concat (list 1) (list 2 3)) -> (1 2 3)
|
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"concat", |
|
|
|
"concat", |
|
|
|
{ |
|
|
|
{ |
|
|
|
size_t count = 0; |
|
|
|
size_t count = 0; |
|
|
@ -89,9 +91,9 @@ ADD_FUNCTION( |
|
|
|
return makePtr<List>(result_nodes); |
|
|
|
return makePtr<List>(result_nodes); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// (conj '(1 2 3) 4 5 6) -> (6 5 4 1 2 3)
|
|
|
|
// (conj '(1 2 3) 4 5 6) -> (6 5 4 1 2 3)
|
|
|
|
// (conj [1 2 3] 4 5 6) -> [1 2 3 4 5 6]
|
|
|
|
// (conj [1 2 3] 4 5 6) -> [1 2 3 4 5 6]
|
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"conj", |
|
|
|
"conj", |
|
|
|
{ |
|
|
|
{ |
|
|
|
CHECK_ARG_COUNT_AT_LEAST("conj", SIZE(), 1); |
|
|
|
CHECK_ARG_COUNT_AT_LEAST("conj", SIZE(), 1); |
|
|
@ -118,8 +120,8 @@ ADD_FUNCTION( |
|
|
|
return makePtr<Vector>(nodes); |
|
|
|
return makePtr<Vector>(nodes); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// (map (fn* (x) (* x 2)) (list 1 2 3)) -> (2 4 6)
|
|
|
|
// (map (fn* (x) (* x 2)) (list 1 2 3)) -> (2 4 6)
|
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"map", |
|
|
|
"map", |
|
|
|
{ |
|
|
|
{ |
|
|
|
CHECK_ARG_COUNT_IS("map", SIZE(), 2); |
|
|
|
CHECK_ARG_COUNT_IS("map", SIZE(), 2); |
|
|
@ -147,8 +149,8 @@ ADD_FUNCTION( |
|
|
|
return makePtr<List>(nodes); |
|
|
|
return makePtr<List>(nodes); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// (set-nth (list 1 2 3) 1 "foo") -> (1 "foo" 3)
|
|
|
|
// (set-nth (list 1 2 3) 1 "foo") -> (1 "foo" 3)
|
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"set-nth", |
|
|
|
"set-nth", |
|
|
|
{ |
|
|
|
{ |
|
|
|
CHECK_ARG_COUNT_IS("set-nth-element", SIZE(), 3); |
|
|
|
CHECK_ARG_COUNT_IS("set-nth-element", SIZE(), 3); |
|
|
@ -173,10 +175,10 @@ ADD_FUNCTION( |
|
|
|
return makePtr<List>(collection_nodes); |
|
|
|
return makePtr<List>(collection_nodes); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// (seq '(1 2 3)) -> (1 2 3)
|
|
|
|
// (seq '(1 2 3)) -> (1 2 3)
|
|
|
|
// (seq [1 2 3]) -> (1 2 3)
|
|
|
|
// (seq [1 2 3]) -> (1 2 3)
|
|
|
|
// (seq "foo") -> ("f" "o" "o")
|
|
|
|
// (seq "foo") -> ("f" "o" "o")
|
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"seq", |
|
|
|
"seq", |
|
|
|
{ |
|
|
|
{ |
|
|
|
CHECK_ARG_COUNT_IS("seq", SIZE(), 1); |
|
|
|
CHECK_ARG_COUNT_IS("seq", SIZE(), 1); |
|
|
@ -223,10 +225,10 @@ ADD_FUNCTION( |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
// (assoc {:a 1 :b 2} :a 3 :c 1) -> {:a 3 :b 2 :c 1}
|
|
|
|
// (assoc {:a 1 :b 2} :a 3 :c 1) -> {:a 3 :b 2 :c 1}
|
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"assoc", |
|
|
|
"assoc", |
|
|
|
{ |
|
|
|
{ |
|
|
|
CHECK_ARG_COUNT_AT_LEAST("assoc", SIZE(), 1); |
|
|
|
CHECK_ARG_COUNT_AT_LEAST("assoc", SIZE(), 1); |
|
|
@ -245,8 +247,8 @@ ADD_FUNCTION( |
|
|
|
return makePtr<HashMap>(elements); |
|
|
|
return makePtr<HashMap>(elements); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// (dissoc {:a 1 :b 2 :c 3} :a :c :d) -> {:b 2}
|
|
|
|
// (dissoc {:a 1 :b 2 :c 3} :a :c :d) -> {:b 2}
|
|
|
|
ADD_FUNCTION( |
|
|
|
ADD_FUNCTION( |
|
|
|
"dissoc", |
|
|
|
"dissoc", |
|
|
|
{ |
|
|
|
{ |
|
|
|
CHECK_ARG_COUNT_AT_LEAST("dissoc", SIZE(), 1); |
|
|
|
CHECK_ARG_COUNT_AT_LEAST("dissoc", SIZE(), 1); |
|
|
@ -261,5 +263,6 @@ ADD_FUNCTION( |
|
|
|
|
|
|
|
|
|
|
|
return makePtr<HashMap>(elements); |
|
|
|
return makePtr<HashMap>(elements); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace blaze
|
|
|
|
} // namespace blaze
|
|
|
|