1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-16 05:34:48 +00:00

Add tuple/brackets

Fix macro expansion via macex for bracketed tuples.
This commit is contained in:
Calvin Rose 2019-02-11 18:37:59 -05:00
parent c64e92a5de
commit 17783c3c3e
2 changed files with 14 additions and 1 deletions

View File

@ -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)

View File

@ -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"