Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

dup, make-blank-value, and shift functions

    ; used in SHIFT below
	dup: func [value len [integer!] /local type] [
        type: either series? value [value] [either char? value [""] [[]]]
		head insert/only/dup make type len value len
	]

    ; used in SHIFT below
    make-blank-value: func [type] [
        any [
            attempt [make type 0]
            attempt [make type ""]
            attempt [make type []]
            attempt [make type none]
        ]
    ]

    shift: func [
        "Shift values in a series; length doesn't change."
        series [series!]
        /left   "Shift left (the default)"
        /right  "Shift right"
        /part range [number!] "Shift this many positions"  ; TBD series! support?
        /with fill "Fill vacated slots with this value"
        /local pad
    ][
        range: any [range 1]
        if any [empty? series  0 = range] [return series]
        pad: dup any [fill make-blank-value last series] range
        either right [
            head insert head clear skip tail series negate range pad
        ][
            append remove/part series range pad
        ]
    ]
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS