samer@3: function Y=diffwith(F,X) samer@3: % diffwith - Generalised diff using argbitrary binary function samer@3: % samer@3: % diffwith :: (A,A->B), seq A -> seq B. samer@3: % samer@3: % The given function gets called with the current value as the samer@3: % first arguments and the previous value as the second. samer@3: samer@23: Y=mapaccum(@diffst,head(X),next(X)); samer@3: function [y,s]=diffst(x,s) samer@3: y=F(x,s); samer@3: s=x; samer@3: end samer@3: end samer@3: