[erlang-questions] Guards syntax for multiple values

Loïc Hoguin essen@REDACTED
Tue Mar 26 09:08:31 CET 2019


On 26/03/2019 08:53, Björn Gustavsson wrote:
> On Mon, Mar 25, 2019 at 7:03 PM Jesper Louis Andersen
> <jesper.louis.andersen@REDACTED> wrote:
>> Thinking out loud, I think it might be beneficial to look at two additions:
>>
>> lists:member - because length(..) is in the set of Valid GuardSeqs and is O(n)
> 
> lists:member/2 has always been problematic because it's O(n). The way
> guard and guard BIFs are implemented (for efficiency), guard BIFs
> can't yield during execution.
> 
> In OTP 22 we finally fixed that issue by implementing special
> instructions for executing length/1:
> 
> https://github.com/erlang/otp/pull/2053
> 
> Because of the effort required to make length/1 yielding, it is
> unlikely that we will ever introduce another guard BIF with O(n) or
> worse complexity.

What about compiler trickery, as mentioned earlier in the thread? Either 
allowing 'lists:member(Var, <list literal>)' or 'Var in <list literal>' 
and rewriting this at compile time as a more verbose series of =:= tests 
and/or separate clauses? This would fit a lot of use cases.

-- 
Loïc Hoguin
https://ninenines.eu



More information about the erlang-questions mailing list