REBOL Programming/array

USAGE:Edit

ARRAY size /initial value 

DESCRIPTION:Edit

Makes and initializes a series of a given size.

ARRAY is a function value.

ARGUMENTSEdit

  • size -- Size or block of sizes for each dimension (Type: integer block)

REFINEMENTSEdit

  • /initial -- Specify an initial value for all elements
    • value -- Initial value (will be called each time if a function) (Type: any)

(SPECIAL ATTRIBUTES)Edit

  • catch

SOURCE CODEEdit

array: func [
    "Makes and initializes a series of a given size." 
    [catch] 
    size [integer! block!] "Size or block of sizes for each dimension" 
    /initial "Specify an initial value for all elements" 
    value {Initial value (will be called each time if a function)} 
    /local block rest
][
    if block? size [
        if tail? rest: next size [rest: none] 
        unless integer? set/any 'size pick size 1 [
            throw-error 'script 'expect-arg reduce ['array 'size type? get/any 'size]
        ]
    ] 
    block: make block! size 
    case [
        block? rest [
            loop size [block: insert/only block array/initial rest :value]
        ] 
        series? :value [
            loop size [block: insert/only block copy/deep value]
        ] 
        any-function? :value [
            loop size [block: insert/only block value]
        ] 
        insert/dup block value size
    ] 
    head block
]
Last modified on 27 October 2012, at 22:18