-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arbitrary Infix Operators #39355
Comments
Somewhat related (albeit with a broader scope) is: #16985 This would be a very large change as it would no longer make parsing canonical. Parsing itself would become stateful — and that's something that I know Jeff is very reticent to do. |
Just so; there is a lot of complexity here since not only does parsing become stateful but there are new scoping issues, i.e. there needs to be a way to import/export syntax from a package vs. keeping it local. |
As it's already possible to use binary operators as identifiers,
could this be handled the same as exporting functions? module Foo
@infix :comparison compare comp
compare(_, _) = 42
export compare # only allows `compare(x, y)`
export comp # only allows `x comp y`
export compare, comp # allows both
@infix :comparison _comp_
_comp_(_, _) = 21
export _comp_ # allows both `_comp_(x, y)` and `x _comp_ y`
end |
Rather than an The macro could also (somehow) take keyword arguments to convey the precedence and associativity of the infix-ed functions. |
Any progress on this? |
Sometimes it's useful to have more verbose infix operators (e.g.
isa
). I would like to suggest adding a way to declare arbitrary identifiers<op>
to be infix operators. Please consider the following syntax as a placeholder for the underlying idea.<precedence>
would correspond to the currently existing listsprec-comparison
,prec-plus
,prec-times
, etc. inside julia-parser.scm. Hence, allowed values should be predefined/limited.<function>
is the function to be executed.<op>
is the identifier of the new infix operator. This might be considered optional.Example: Divisibility
This syntax would also allow creating new infix operators from Unicode symbols, such that things like #39350 could just be done by a package. To simplify that workflow, it would be nice to define "tab completions" in a similar fashion.
Example: Independence (probability theory)
Extension to n-ary operators
The distinction between
<function>
and<op>
allows this syntax to be extended to custom ternary operators.Example: Conditional Independence
The latter usage is currently invalid syntax.
Discussions concerning ternary operators (e.g. how to deal with precedence) might be better located in #39353.
The text was updated successfully, but these errors were encountered: