[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-dev] what should string-compare accept as arguments?



> I’m happy to do that if we can agree on what it should accept. Once that’s done we should make sure to clearly document it. The very vague documentation of things often makes it very hard to tell what things are accidents and what are intentional.

Definition of String-compare: "Returns a -1, 0, or 1 depending on whether the receiver should be sorted before the argument, is equal to the argument or should be sorted after the argument. This is a case sensitive compare.”

so it is both used to check equality (“hell” == “hello” is false) and sorting [“cda”, “abc”, \test, 99].sort

Just for the context, the question came up because the original implementation of string-compare (in the primitive) was so liberal that it would cover to possible errors. The new implementation is strict, and we should discuss what it should accept in order not to be overly strict. Being overly strict leads to a lot of conversions and extra methods that programmers need to implement as “work arounds”.

An example is “a string”.replace(x, y); where x and y are characters : should this work, or should we have to convert to string explicitly: “a string”.replace(x.asString, y.asString);

here is a first list of possibly important cases:

compare(nil, nil)
compare(“hello”, nil)
compare(“hello”, \hello)
compare(\hello, \hello)
compare(“g”, $g)
compare([$a, $b, $c], “abc”)

I do think that if compare(a, b) is valid, then compare(b, a) should be also valid, and compare(a, b) == neg(compare(b, a)) in all valid cases.



_______________________________________________
sc-dev mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-dev/
search: https://listarc.bham.ac.uk/lists/sc-dev/search/