Welcome! Please see the About page for a little more info on how this works.

+2 votes
ago in Records and Types by

Following on from a very interesting article about tagged literals: https://buttondown.com/tensegritics-curiosities/archive/when-you-run-out-of-types/ I noticed that the implementing class checks for value equality before checking for tag equality.

if (form != null ? !form.equals(that.form) : that.form != null) return false;
if (tag != null ? !tag.equals(that.tag) : that.tag != null) return false;

This leads to the following type of comparison that could be answered immediately but instead takes over a second:

impl=> (time (= (tagged-literal 'foo (seq (range 1e7))) (tagged-literal 'bar (butlast (seq (range 1e7))))))
"Elapsed time: 1911.677375 msecs"
false

it checks if these huge seqs are equal and then compares the associated symbols. Swapping this seems identical semantically but with less computation.

Please log in or register to answer this question.

...