Documention for: extend.r Created by: vincentecuye on: 31-Jan-2013 Format: text/editable Downloaded on: 29-Nov-2021 Extend Author: Vincent Ecuyer Date: 31-Jan-2013 File: %extend.r ===Purpose Extends a series with sequential or duplicate values. ===Usage extend/to/cut value (series!) length (integer!) with: \table Argument Type Usage =row value series! the series to modifies =row length integer! either the number of items to append (or retire, if it's negative and /cut is used), or, with /to, the total number of items =row /to - the 'length is the total length (without /cut, doesn't do anything if the series is too long) =row /cut - shortens the series if it's too long (with /to), or if length is negative (without /to) =row /dup - duplicates values (repeats the existing values, but doesn't try to continue a sequence) /table ===Examples Empty series : appends none or null (0) values >> extend [] 10 == [none none none none none none none none none none] >> extend #{} 10 == #{00000000000000000000} One element : builds an incrementing sequence >> extend [1] 10 == [1 2 3 4 5 6 7 8 9 10 11] >> extend/to "a" 26 == "abcdefghijklmnopqrstuvwxyz" /dup disables the incrementation >> extend/dup [1] 10 == [1 1 1 1 1 1 1 1 1 1 1] Two elements or more : tries to continue the series >> extend [0 5] 6 == [0 5 10 15 20 25 30 35] >> extend [1 3 5] 3 == [1 3 5 7 9 11] >> extend [1 5 3] 3 == [1 5 3 1 5 3] It works with date!, time!, char!, number!, and tuple! elements >> extend/to reduce [now/date] 5 == [30-Jan-2013 31-Jan-2013 1-Feb-2013 2-Feb-2013 3-Feb-2013 ] >> extend/to [08:00:00 08:30:00] 8 == [8:00 8:30 9:00 9:30 10:00 10:30 11:00 11:30] >> extend/to [0.0.0.127 64.0.1.127] 4 == [0.0.0.127 64.0.1.127 128.0.2.127 192.0.3.127] /cut is used to shorten the series >> extend/cut [1 2 3 4 5 6] -1 == [1 2 3 4 5] >> extend/cut/to [0 1 2 3 4 5 6] 3 == [0 1 2] Non-numeric elements or mixed elements : repeats the values >> extend ["cat" "rabbit" "dog"] 5 == ["cat" "rabbit" "dog" "cat" "rabbit" "dog" "cat" "rabbit"] >> extend/to [5 dog 15] 8 == [5 dog 15 5 dog 15 5 dog]