Re: x < y < z
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: x < y < z
- From: Dirk Laurie <dirk.laurie@...>
- Date: 2015年7月17日 16:58:08 +0200
2015年07月17日 16:02 GMT+02:00 Peter Aronoff <telemachus@arpinum.org>:
> 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?
If u = unit(fct), then fct(u,x)=x for all x.
E.g. unit(__add) = 0, unit(__mul) = 1, unit(__min) = Inf, etc.
It is only really needed when x is empty, but simplifies the coding.