Here, the compiler recognizes > as a function name and picks out the appropriate implementation using contextual type information.
However, it seems that in the case of operator names, this magic occurs solely in the context of function calls. General expressions cannot reference operator names, even when the relevant types are fully specified. For example, the following does not work:
let comparator: (Int, Int) -> Bool = >
A non-operator function name would work fine here; only operators seem to cause confusion.
I know it's possible to work around this limitation by wrapping operators in closures or by running them through a function that accepts them as a parameter. But these both seem like hacks. Is there a more direct way to refer to specific operator implementations?
It's not really relevant, but the specific use case is that I'd like to test an implementation with multiple comparator functions - ideally, something simple like
for comparator in [ <, <=, >, >= ] {
....
}
(Of course, the driver table might need to specify different expected results for those different comparison operators. And this specific example doesn't provide the type information necessary to disambiguate the operator functions.)
Unknown, captain. But I'd imagine Discourse has its own syntax highlighting engine and doesn't use the Clang-based parser. Bare operators as function names are kind of an oddball case.
Egad, you're right. I didn't fix above since that would make the past discussion not make sense, but here is that code again with the language annotation:
Actually, the thing that seems to fix my original formatting is not the explicit "swift" designation but the use of triple backticks (```) to set off the quoted code. Here it is again with the backticks but without the explicit "swift":
But evidently, Discourse highlights for a different language in this context, even though the main default might already be set to Swift.
Really, the underlying issue here is that there's no guidance about how to format code shown in the Compose window. No link to a full markdown reference, no format-as-code icon, no links to formatting help of any kind. In fact, that information doesn't seem to exist anywhere on the site.
Yes ... this is a bug, I will get it fixed, can you report it on meat.discourse.org so it does not get lost? (also where are my emojis :bust_in_silhouette:)