diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fbff89e..a2c9a8a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## 0.4.0 - ?? +- Remove `tuple/append` and `tuple/prepend`, which may have seened like `O(1)` + operations. Instead, use the `splice` special to extend tuples. - Add `-m` flag to main client to allow specifying where to load system modules from. - Add `-c` flag to main client to allow compiling Janet modules to images. diff --git a/src/core/core.janet b/src/core/core.janet index 0194dbc0..3e1bc582 100644 --- a/src/core/core.janet +++ b/src/core/core.janet @@ -311,7 +311,7 @@ [i preds &] (default preds @['and]) (if (>= i len) - (tuple/prepend body 'do) + ['do ;body] (do (def {i bindings (+ i 1) verb diff --git a/src/core/tuple.c b/src/core/tuple.c index cbcd28d5..8af69092 100644 --- a/src/core/tuple.c +++ b/src/core/tuple.c @@ -106,26 +106,6 @@ static Janet cfun_tuple_slice(int32_t argc, Janet *argv) { return janet_wrap_tuple(janet_tuple_n(view.items + range.start, range.end - range.start)); } -static Janet cfun_tuple_prepend(int32_t argc, Janet *argv) { - janet_arity(argc, 1, -1); - JanetView view = janet_getindexed(argv, 0); - Janet *n = janet_tuple_begin(view.len - 1 + argc); - memcpy(n - 1 + argc, view.items, sizeof(Janet) * view.len); - for (int32_t i = 1; i < argc; i++) { - n[argc - i - 1] = argv[i]; - } - return janet_wrap_tuple(janet_tuple_end(n)); -} - -static Janet cfun_tuple_append(int32_t argc, Janet *argv) { - janet_arity(argc, 1, -1); - JanetView view = janet_getindexed(argv, 0); - Janet *n = janet_tuple_begin(view.len - 1 + argc); - memcpy(n, view.items, sizeof(Janet) * view.len); - memcpy(n + view.len, argv + 1, sizeof(Janet) * (argc - 1)); - return janet_wrap_tuple(janet_tuple_end(n)); -} - static Janet cfun_tuple_type(int32_t argc, Janet *argv) { janet_fixarity(argc, 1); const Janet *tup = janet_gettuple(argv, 0); @@ -150,19 +130,6 @@ static const JanetReg tuple_cfuns[] = { "they default to 0 and the length of arrtup respectively." "Returns the new tuple.") }, - { - "tuple/append", cfun_tuple_append, - JDOC("(tuple/append tup & items)\n\n" - "Returns a new tuple that is the result of appending " - "each element in items to tup.") - }, - { - "tuple/prepend", cfun_tuple_prepend, - JDOC("(tuple/prepend tup & items)\n\n" - "Prepends each element in items to tuple and " - "returns a new tuple. Items are prepended such that the " - "last element in items is the first element in the new tuple.") - }, { "tuple/type", cfun_tuple_type, JDOC("(tuple/type tup)\n\n" diff --git a/test/suite1.janet b/test/suite1.janet index f86ddf33..a48d30df 100644 --- a/test/suite1.janet +++ b/test/suite1.janet @@ -97,8 +97,8 @@ # of the triangle to the leaves of the triangle. (defn myfold [xs ys] - (let [xs1 (tuple/prepend xs 0) - xs2 (tuple/append xs 0) + (let [xs1 [;xs 0] + xs2 [0 ;xs] m1 (map + xs1 ys) m2 (map + xs2 ys)] (map max m1 m2))) @@ -178,7 +178,7 @@ # Large functions (def manydefs (seq [i :range [0 300]] (tuple 'def (gensym) (string "value_" i)))) (array/push manydefs (tuple * 10000 3 5 7 9)) -(def f (compile (tuple/prepend manydefs 'do) *env*)) +(def f (compile ['do ;manydefs] *env*)) (assert (= (f) (* 10000 3 5 7 9)) "long function compilation") # Some higher order functions and macros