diff options
author | ubq323 <ubq323@ubq323.website> | 2024-08-17 21:31:39 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2024-08-17 21:31:39 +0100 |
commit | e45cdd61a4cd9f5b0eb7613a88c4989ad58eebeb (patch) | |
tree | bd250efb557c44e8e97d6d151be6338d1751e061 | |
parent | b90e206280859d2069c5ce02faf39c1a70202a08 (diff) |
add s,@ aka spendsplat
-rw-r--r-- | lib.c | 7 | ||||
-rw-r--r-- | tests/spendsplat.bth | 1 | ||||
-rw-r--r-- | tests/spendsplat.out | 1 |
3 files changed, 9 insertions, 0 deletions
@@ -116,6 +116,12 @@ static Val fn_spend(State *S, int nargs, Val *args) { } return VAL_OBJ(objstring_take(S, new, len)); } +static Val fn_spendsplat(State *S, int nargs, Val *args) { + CHECK(nargs==1, "need exactly 1 arg for spendsplat"); + CHECK(IS_ARR(args[0]), "need arr arg for spendsplat"); + ObjArr *a = AS_ARR(args[0]); + return fn_spend(S, a->len, a->d); +} static Val fn_ssplit(State *S, int nargs, Val *args) { CHECK(nargs==2,"need exactly 2 args for ssplit"); CHECK(IS_STRING(args[0]) && IS_STRING(args[1]), "need two strings for ssplit"); @@ -196,6 +202,7 @@ static BuiltinFunc builtin_funcs[] = { { "#", fn_len }, { ",", fn_pend }, { "s,", fn_spend }, + { "s,@", fn_spendsplat }, { "ssplit", fn_ssplit }, { "schars-ascii", fn_schars_ascii }, diff --git a/tests/spendsplat.bth b/tests/spendsplat.bth new file mode 100644 index 0000000..38de40f --- /dev/null +++ b/tests/spendsplat.bth @@ -0,0 +1 @@ +(say (s,@ ['abc 'def 'ghi])) diff --git a/tests/spendsplat.out b/tests/spendsplat.out new file mode 100644 index 0000000..500533a --- /dev/null +++ b/tests/spendsplat.out @@ -0,0 +1 @@ +abcdefghi |