For a gnerally binary operator I would personally do something like

x = 1:5
f = +
map(f,x[1:end-1],x[2:end])

This pattern has obvious generalizations to the n-ary case. In clojure data 
analysis you see a lot composition of the map and partition/partitionby/etc 
functions (the partition* functions in clojure break up sequences into a 
sequence of windows). I know julia is not clojure but I think the window 
and map pattern accurately reflects the way many scientific programmers 
think about this type of operation, which is relatively common across a 
number of domains. As such I think it would be nice to establish some kind 
of terse but idiomatic way of writing these thing in julia (@Evan thanks 
for the question!). 

Leaving implementation details aside I'll start the discussion by 
advocating for something like

mapnwise{N,T}(f::Function,n::Int,x::AbstractArray{N,T}) = ...

There could also be an argument for other windowing schemes, but this would 
be a start.

where the signature of f is 
On Saturday, February 7, 2015 at 1:19:39 PM UTC+1, Evan Pu wrote:
>
> say I want to compute a pair-wise diff for all the elements in the array.
> input:        [1, 2, 4, 7, 8]
> output:        [1, 2, 3, 1]
>
> is there some kind of "beautiful" way of doing it? i.e. w/o using a for 
> loop nor using explicit indecies
>

Reply via email to