lua-users home
lua-l archive

Re: paving cowpaths with libraries (was Re: Upstream is not the last word (was Re: [ANN] Lua 5.1.5 (rc1) now available))

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


Op 14 februari 2012 06:11 schreef Miles Bader <miles@gnu.org> het volgende:
Sean Conner <sean@conman.org> writes:
>> Given an array, produce a "set". local s={}; for _,v in ipairs(a) do
>> s[v]=true done end return s.
>
>   I don't see the reason for this.  The only two values that evaluate to
> false are false and nil.

It's actually pretty useful, because it allows a nice syntax for
writing fast table-based predicates.

Isn't it even more useful to use not a bare`true` but something active?
E.g. a function to be called?

Personally I prefer a multiset aka histogram: instead of `s[v]=true`,
   s[v] = (s[v] or 0) + 1



 

AltStyle によって変換されたページ (->オリジナル) /