compound context seq fn: smap


smap:
    description:
        smap[min, max, op] seq
        smap(min, max, op) seq
        partition seq into ngrams of size ranging from min to max, then apply op to those ngrams
        in the background, we have a variable that keeps track of the current position in the sequence:
        the |smap pos>
        NB: the indexing for the smap position starts from 1 not 0.

    examples:
        -- just an abstract test:
        bracket (*) #=> |[> _ smerge[", "] |__self> _ |]>
        print-bracket (*) #=> print bracket |__self>
        print-smap-bracket (*) #=> print (the |smap pos> _ |:> __ bracket |__self>)

        -- the constant parameter version:
        smap[1, 4, print-smap-bracket] ssplit |abcdef>
            1: [a]
            2: [b]
            3: [c]
            4: [d]
            5: [e]
            6: [f]
            2: [a, b]
            3: [b, c]
            4: [c, d]
            5: [d, e]
            6: [e, f]
            3: [a, b, c]
            4: [b, c, d]
            5: [c, d, e]
            6: [d, e, f]
            4: [a, b, c, d]
            5: [b, c, d, e]
            6: [c, d, e, f]

        -- the variable parameter version:
        -- probably a little slower, but more flexible
        smap(|1>, |4>, |op: print-smap-bracket>) ssplit |abcdef>

    see also:

Home