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-3 of 3 total  RSS 

LIMIT - Make sure val falls between lower and upper bounds, inclusive; uses length for series values.

    limit: func [
        "Make sure val falls between lower and upper bounds, inclusive; uses length for series values."
        val
        lower [integer!]
        upper [integer!]
        /show "For series values, show extension/truncation (dot/none for extension, 3 dots for truncation)."
        /local fill
    ][
        either not series? val [max min val upper lower] [
            either all [
                upper >= length? val
                lower <= length? val
            ] [val] [
                ; If extending the series, use NONE as the fill value, so the
                ; block can still be processed easily.
                fill: either any-string? val ["."] [none]
                head either lower >= length? val [
                    insert/only/dup tail val fill subtract lower length? val
                ][
                    clear skip val upper
                    either show [change/dup skip tail val -3 '. 3] [val]
                ]
            ]
        ]
    ]

limit function - limit a value within bounds

limit: func [
    "Make sure val falls between lower and upper bounds, inclusive"
    val lower upper
][
    max min val upper lower
]

min-of function

    ;  This returns only the minimum value out of context minimum-of returns the series
    ; at the position of the minimum value found.
    min-of: func [series [series!]] [attempt [first minimum-of series]]
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS