← Back to context

Comment by QuadmasterXLII

1 month ago

Unsupervised, in a language where arrays and functions could be called with the same syntax, one would be tempted to do

    def slice(array, start, end):
        def new_array(index):
            return array(index - start)
        return new_array

Or, more elegantly, if you had some sort of infix composition operator (say @, by analogy to matrix multiplication) you would slice an array inline via

    sliced_array = array @ lambda x: x - start

I think what this really clarifies is that it's quite important that arrays expose their lengths, which there isn't one clear way to do if arrays and functions are interchanged freely.