Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file: -- http://anggtwu.net/LUA/Fold1.lua.html -- http://anggtwu.net/LUA/Fold1.lua -- (find-angg "LUA/Fold1.lua") -- Author: Eduardo Ochs <eduardoochs@gmail.com> -- Based on: -- (find-angg "LUA/ELpeg1.lua" "folds") -- -- (defun e () (interactive) (find-angg "LUA/Fold1.lua")) -- (find-angg "LUA/ELpeg1.lua" "folds") -- (find-angg "LUA/lua50init.lua" "fold") Fold = Class { type = "Fold", __index = { l = function (fold, f) local A,o = fold.A, fold.A[1] for i=2,#A do local b=A[i]; o=f(o,b) end return o end, r = function (fold, f) local A,o = fold.A, fold.A[#fold.A] for i=#A-1,1,-1 do local a=A[i]; o=f(a,o) end return o end, l2 = function (fold, f) local A,o = fold.A, fold.A[1] for i=3,#A,2 do local b,c=A[i-1],A[i]; o=f(o,b,c) end return o end, r2 = function (fold, f) local A,o = fold.A, fold.A[#fold.A] for i=#A-2,1,-2 do local a,b=A[i],A[i+1]; o=f(a,b,o) end return o end, }, } --[[ * (eepitch-lua51) * (eepitch-kill) * (eepitch-lua51) dofile "Fold1.lua" A = {10, 20, 30, 40, 50, 60, 70} F = Fold {A=A} f2 = function(a,b) return format("(%s.%s)", a,b) end f3 = function(a,b,c) return format("(%s.%s.%s)", a,b,c) end = F:l(f2) = F:r(f2) = F:l2(f3) = F:r2(f3) --]] -- Local Variables: -- coding: utf-8-unix -- End: