ID:1134500
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
Currently, (as far as I can tell), using < > <= or >= to compare two atoms atom/A and atom/B will always return the first atom in the comparison.

i.e. A < B will return A
or B < A will return B

Would it be difficult to make it so that comparing atoms in this way would actually compare A.name and B.name?

Such a change would make creating custom sorting procs much simpler and elegant as special cases wouldn't be required for sorting lists of atoms by name (a pretty common task).

Just an idea. Could survive without it.


What's so difficult about writing a few more words?

A.name != B.name
B.name != A.name

I don't understand how would this help sorting lists.
Also, why compare the name variable? What If I want to compare the loc of both atoms? Or what If I am using a /datum, which does not have a 'name' variable?
>, <, >=, <=
All mention:
If A and B are text strings, a case sensitive comparison is performed (like sorttextEx()).

The operators aren't supposed to return anything besides 1, or 0 (or -1, when using sorttext/Ex) when used properly.

So, you can do A.name > B.name, but just not A > B for their names.

I understand what you're requesting, but, it doesn't seem like it'd work how you want to (at least not without the developers digging deep into the core and breaking fundamental operators)
god damnit this site hates Opera. Lost my reply.

@Fushimi, I have no idea what you are trying to get at with "What's so difficult about writing a few more words?". I want to sort a list of atoms by their name variable because that's a common task for interfaces and such.

I have a bunch of procs which sort lists of numbers and text just fine, using the < and > operators. If I want to sort a list of atoms, I need to either copypaste that code and make it work by comparing the name variables of those atoms. Or alternatively use a custom proc for every comparison:
//compare A and B, they can be any datum/text/number (but must be the same)
//returns 1 for A < B (ascending)
//returns -1 for A > B (descending)
//returns 0 otherwise (A == B, or error)
/proc/compare(datum/A, datum/B, varname="name")
        if(istype(A))
                A = A.vars[varname]
        if(istype(B))
                B = B.vars[varname]
        if(A < B)    return 1
        if(B < A)    return -1
        return 0

When sorting large lists, there can be a large number of comparisons. So this proc gets called a vast number of times (in the range of O(nlogn) to O(n^2) depending on the algorithm being used.

I would preferably like to avoid both scenarios by having atom comparison do something intuitive, other than return the first atom in the comparison....which is a bit weird.Much like SuperSaiyan points out that textA < textB will work intuitively using similar behavior to sorttextEx

@SuperSaiyanX, "The operators aren't supposed to return anything besides 1, or 0" hence why I'd like atom comparison to act intuitively.

All that being said, even if the devs said it's a horrible/stupid idea but explained why it behaves that way (curious) - I'd be a happy bunny.

P.S. sorry I can never remember the forum tags for posting code snippets.
I always wanted control over operators...

mob
Add(right_hand_side)
if(isnum(right_hand_side))
src.hp += right_hand_side

mob/proc/give_health(n as num)
src += n //this calls src.Add(n)


Probably not the greatest example, but you get what I mean.
Well, that's kinda different to this request, seen as this regards name-based ordering for datums, which would be a non-overloadable built-in.