Skip to content

Commit

Permalink
FEAT: implemented PUT/SKIP as a counterpart of SELECT/SKIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Feb 15, 2025
1 parent a3417e9 commit 9a33e77
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/boot/actions.reb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ put: action [
key [any-type!]
value [any-type!] {The new value (returned)}
/case {Perform a case-sensitive search}
/skip {Treat the series as records of fixed size}
size [integer!]
]

insert: action [
Expand Down
3 changes: 2 additions & 1 deletion src/core/t-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,8 @@ static void No_Nones_Or_Logic(REBVAL *arg) {
case A_PUT:
arg2 = D_ARG(ARG_PUT_VALUE);
args = D_REF(ARG_PUT_CASE) ? AM_FIND_CASE : 0;
ret = Find_Block(ser, index, tail, arg, len, args, 1);
ret = IS_INTEGER(D_ARG(ARG_PUT_SIZE)) ? Int32s(D_ARG(ARG_PUT_SIZE), 1) : 1;
ret = Find_Block(ser, index, tail, arg, len, args, ret);
if(ret != NOT_FOUND) {
ret++;
if (ret >= tail) {
Expand Down
4 changes: 4 additions & 0 deletions src/tests/units/series-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,10 @@ Rebol [
--assert error? err: try [ put v 'a 2 ]
--assert 'protected = err/id

--test-- "PUT/SKIP"
--assert [a b 0 c] == (put blk: [a b b c] 'b 0 blk)
--assert [a b b 0] == (put/skip blk: [a b b c] 'b 0 2 blk)

===end-group===

===start-group=== "INSERT"
Expand Down

0 comments on commit 9a33e77

Please sign in to comment.