lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Dirk Laurie <dirk.laurie@gmail.com> wrote:
> APL has an operator "scan" over arrays so that
> 
>    fct / x
> 
> returns the value of a function that can be coded in Lua as
> 
> function scan(fct,x)
>    result = unit(fct)
>    for _,v in ipairs(x) do result = fct(result,v) end
>    return result
> end

I'm sorry if I'm being dense, but what is `unit` there?


> There may well be som such function in Penlight and Microlight.

As Alex Q. says in another reply, scan looks like a fold/reduce. A number
of utility libraries do provide such a function. Penlight and Underscore
definitely do, for example.

P
-- 
We have not been faced with the need to satisfy someone else's
requirements, and for this freedom we are grateful.
    Dennis Ritchie and Ken Thompson, The UNIX Time-Sharing System