-
-
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
Customizable Ternary Operators #39353
Comments
Who has the high priorities if someone also defines |
Currently,
The same should hold for ternary operators: |
I might have gotten your question wrong. I think it would be best to prevent situations where it's unclear whether to call a binary or a ternary operator. If the call syntax should look like However, this would still disallow most symbols to be used here. I think ternary operators might be the most fun in combination with #39355. Though, if the call syntax should look like |
I think this is fully subsumed by #39355. If we had that, you could just declare an operator ternary when it is defined. In the other direction, it would be weird to only allow defining custom ternary operators but not binary operators. As for the specific case here, is |
The condition of two random variables to be independent, Disclaimer: I'm "only" a graduate maths student and I've been a tutor in a Bayesian Networks course this semester. |
TIL: you can use operators as identifiers.
If we now use |
I agree. That one is just a much heavier lift. So I thought this one might have a bigger chance of being implemented. However, it is not a low hanging fruit either. Closing with a solution for the function cond_indep(A, B, C)
@info "testing $A indep $B given $C"
true
end
macro ci(ex::Expr)
indep, A, ex2 = ex.args
@assert indep == :⟂
given, B, C = ex2.args
@assert given == :|
quote
cond_indep($A, $B, $C)
end
end
|
Is there an idiomatic way to create ternary operators?
I assume with some experience in macros, one could make
@ci A ⫫ B | C
work. This doesn't feel like a "native solution", though. Maybe we could maintain a list of ternary operators, similar to the binary operators in julia-parser.scm, which users could eventually define/overwrite like this:Usage would then look like
A ⫫ B | C
(conditional independence) orx ≡ y | n
.This would only work for ternary operators whose parts consist of a single character. Another problem might arise if parts of it are a binary operator already (e.g.
|
from above).Update: #39355 mentions an alternate syntax to define ternary operators that lifts the restriction of "single character parts". It also mentions a new calling syntax that lifts the problem of "reused parts":
@(A ⫫ B | C)
could describe a single n-ary operator call (currently invalid syntax).Update 2: Here is that macro mentioned above (using
⟂
instead of⫫
, has the same operator preference):Update 3: yet another macro doing the job:
The text was updated successfully, but these errors were encountered: