From 17783c3c3e2878f4fee8a83846a89d219af2846e Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Mon, 11 Feb 2019 18:37:59 -0500 Subject: [PATCH] Add tuple/brackets Fix macro expansion via macex for bracketed tuples. --- src/core/core.janet | 4 +++- src/core/tuple.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/core/core.janet b/src/core/core.janet index 54040812..75bc64ab 100644 --- a/src/core/core.janet +++ b/src/core/core.janet @@ -1324,7 +1324,9 @@ value, one key will be ignored." (def ret (case (type x) - :tuple (dotup x) + :tuple (if (= (tuple/type x) :brackets) + (tuple/brackets ;(map macex1 x)) + (dotup x)) :array (map macex1 x) :struct (table/to-struct (dotable x macex1)) :table (dotable x macex1) diff --git a/src/core/tuple.c b/src/core/tuple.c index a648412d..800106bc 100644 --- a/src/core/tuple.c +++ b/src/core/tuple.c @@ -94,6 +94,12 @@ int janet_tuple_compare(const Janet *lhs, const Janet *rhs) { /* C Functions */ +static Janet cfun_tuple_brackets(int32_t argc, Janet *argv) { + const Janet *tup = janet_tuple_n(argv, argc); + janet_tuple_flag(tup) |= JANET_TUPLE_FLAG_BRACKETCTOR; + return janet_wrap_tuple(tup); +} + static Janet cfun_tuple_slice(int32_t argc, Janet *argv) { JanetRange range = janet_getslice(argc, argv); JanetView view = janet_getindexed(argv, 0); @@ -131,6 +137,11 @@ static Janet cfun_tuple_type(int32_t argc, Janet *argv) { } static const JanetReg tuple_cfuns[] = { + { + "tuple/brackets", cfun_tuple_brackets, + JDOC("(tuple/brackets & xs)\n\n" + "Creates a new bracketed tuple containing the elements xs.") + }, { "tuple/slice", cfun_tuple_slice, JDOC("(tuple/slice arrtup [,start=0 [,end=(length arrtup)]])\n\n"