Re: diff. betw. equal and eq on simbols



Nikola Skoric <nick-news@xxxxxxxx> writes:

> Now, why would eq be more efficient than equal when comparing only
> one symbol?

Eq compares the identity of its arguments, which is typically a single
primitive CPU operation (and thus "efficient"). Equal on the other
hand does different things for different types of arguments. For
example, two lists are equal if all the elements are pairwise equal,
regardless of the identity of the lists. For symbol arguments equal
will return exactly the same result as eq, but equal must first check
what the types of the arguments are, and this type-checking is what
makes equal less efficient than eq. (That is, unless the compiler can
infer at compile-time that at least one of the arguments is a symbol,
in which case equal becomes the same as eq also in terms of
efficiency.)

--
Frode Vatvedt Fjeld
.



Relevant Pages

  • Re: Can a simple a==b hang in and endless loop?
    ... comparing only two 'values'. ... Coming from C or Javascript one would ... over all elements of the lists. ... 'is' does the C, Javascript job when comparing lists, but I mean it fails to give fully predictable results when applied to elements of lists in case there exist duplicate objects with same 'value' i.e. e.g. there are two different objects storing the integer value 1, what I mean can happen when there is enough other code between the Python code lines assigning the integer value 1 to a list element or any other identifier. ...
    (comp.lang.python)
  • Re: expandable test if token-lists consist of the same set of tokens?
    ... \detokenize-ation of the two lists are the same, ... Check if it is possible to strip off surrounding braces (a ... I think you can test this by comparing \detokenize ... Otherwise terminate with \@secondoftwo. ...
    (comp.text.tex)
  • Compare two datasets and extract unique records from each
    ... compare two lists with single columns, but I need a very basic guide ... There are no duplicate records within each dataset, ... so it's not a matter of comparing Row 1 to Row 1 and so on. ... One (or a way to highlight these records). ...
    (microsoft.public.excel.worksheet.functions)
  • RE: Compare two datasets and extract unique records from each
    ... Have you tried Advanced Filter Unique Records? ... compare two lists with single columns, but I need a very basic guide ... so it's not a matter of comparing Row 1 to Row 1 and so on. ... One (or a way to highlight these records). ...
    (microsoft.public.excel.worksheet.functions)
  • Re: List Flatten
    ... Removing them (we expand lists only) we obtan the short ... In may book all three versions (Alex Martelli's yours and mine) use the ... _same_ flattening algorithm with _different_ methods to test for atomicity. ... somebody thought that comparing them was a good idea :-), but again, it ...
    (comp.lang.python)