@@ -85,24 +85,39 @@ array: func [
85
85
size [integer! block! ] "Size or block of sizes for each dimension"
86
86
/initial "Specify an initial value for all elements"
87
87
value "Initial value (will be called each time if a function)"
88
- /local block rest
88
+ /local block rest word
89
+ /with tag indexes ; Token to ensure internal use, and block of index expressions
89
90
] [
91
+ unless same? :tag 'tag [with: tag: indexes: none] ; Enforced internal option
90
92
if block? size [
93
+ if all [not with any-function? :value ] [ ; Make indexes to pass to function
94
+ indexes: append /dup make block! 2 * length? size [index? block] length? size
95
+ ]
91
96
if tail? rest: next size [rest: none]
92
97
unless integer? set /any 'size first size [
93
98
cause-error 'script 'expect-arg reduce ['array 'size type? :size ]
94
99
]
95
100
]
96
101
block: make block! size
97
102
case [
98
- block? rest [
99
- loop size [block: insert /only block array/initial rest :value ]
103
+ block? :rest [
104
+ either any-function? :value [ ; Must construct params to pass to function
105
+ word: in make object! copy [x: block] 'x ; Make a persistent word for this level
106
+ indexes: change next indexes word ; Put that word in the params block
107
+ loop size [ ; Pass indexes block to recursive call, at that level's position
108
+ set word insert /only get word array/initial/with rest :value 'tag indexes
109
+ ]
110
+ block: get word
111
+ ] [ ; Regular value, no parameter handling needed
112
+ loop size [block: insert /only block array/initial rest :value ]
113
+ ]
100
114
]
101
115
series? :value [
102
116
loop size [block: insert /only block copy/deep value]
103
117
]
104
- any-function? :value [ ; So value can be a thunk :)
105
- loop size [block: insert /only block value] ; Called every time
118
+ any-function? :value [
119
+ unless indexes [indexes: [index? block]] ; Single dimension, single index
120
+ loop size [block: insert /only block apply :value head indexes]
106
121
]
107
122
insert /dup block value size
108
123
]
@@ -421,7 +436,7 @@ printf: func [
421
436
split : func [
422
437
"Split a series into pieces; fixed or variable size, fixed number, or at delimiters"
423
438
series [series! ] "The series to split"
424
- dlm [block! integer! char! bitset! any-string! ] "Split size, delimiter(s), or rule(s)."
439
+ dlm [block! integer! char! bitset! any-string! ] "Split size, delimiter(s), or rule(s)."
425
440
/into "If dlm is an integer, split into n pieces, rather than pieces of length n."
426
441
/local size piece-size count mk1 mk2 res fill-val add-fill-val
427
442
] [
@@ -480,7 +495,7 @@ split: func [
480
495
; implied empty field after it, which we add here.
481
496
case [
482
497
bitset? dlm [
483
- ; ATTEMPT is here because LAST will return NONE for an
498
+ ; ATTEMPT is here because LAST will return NONE for an
484
499
; empty series, and finding none in a bitest is not allowed.
485
500
if attempt [find dlm last series] [add-fill-val]
486
501
]
@@ -496,7 +511,7 @@ split: func [
496
511
]
497
512
]
498
513
]
499
-
514
+
500
515
res
501
516
]
502
517
]
0 commit comments