[erlang-questions] Trouble with Erlang's lenient comparisons

Gordon Guthrie gordon@REDACTED
Thu Apr 14 11:20:29 CEST 2011


Björn

> Did you read the note in the documentation for is_record/2?

I did, but in my defence I was confused by Kostis and in a fluster :(

I have re-read it now understand it properly. is_record/2 does what I
always assumed it did (without reading the documentation) and I stand
by my suggestion at the top of this thread.

Gordon


2011/4/14 Björn Gustavsson <bgustavsson@REDACTED>:
> On Wed, Apr 13, 2011 at 4:36 PM, Gordon Guthrie <gordon@REDACTED> wrote:
>> Kostis
>>
>> I have never read the documentation on is_record/2 before (didn't even
>> know there was is_record/3)
>>
>> I *assumed* that the is_record guard checked that it indeed was a
>> record - it would appear it doesn't.
>>
>> The documentation also explictly says to use is_record/2
>>
>>> Note!
>>> This BIF is documented for completeness. In most cases is_record/2 should be used.
>>
>> If you shouldn't use it then the documentation should probably say so.
>>
>> I presume you are saying that using #rec{} in the function call is
>> correctly expanded by the preprocessor to {rec, _, _, } and is
>> therefore a better specification of the contract than is_record/2
>> which just says 'it is a tuple with first element of this atom'
>
> Did you read the note in the documentation for is_record/2?
> As long as the RecordTag argument is a literal atom, the
> compiler will essentially rewrite it to a call to is_record/3,
> which will check the size too.
>
> Therefore, we still recommend that you use is_record/2,
> if you are going to use is_record() at all.
>
> Historically, only is_record/2 existed and it was not a
> BIF, but specially treated by the compiler. We added the
> BIF versions so that it would be possible to use apply on
> them, and for consistency with match specs. In most
> circumstances, the BIFs will not be called as the compiler
> tries to convert calls to is_record/{2,3} to pattern matching
> and inline most of the remaining calls.
>
> --
> Björn Gustavsson, Erlang/OTP, Ericsson AB
>



-- 
Gordon Guthrie
CEO hypernumbers

http://hypernumbers.com
t: hypernumbers
+44 7776 251669



More information about the erlang-questions mailing list