Stream: helpdesk (published)

Topic: Defining the "order" to which to evaluate an expression


view this post on Zulip Davi Sales Barreira (Sep 19 2023 at 18:41):

Suppose that I define two functions using \oplus(x::Int, y::Int) and \otimes(x::Int, y::Int). Is it possible to define an evaluation order for these operations? For example, so that 1 \oplus 2 \otimes 3 equals 1 + 2* 3 .

view this post on Zulip DrChainsaw (Sep 19 2023 at 19:19):

I believe the operator precedence is hard coded: https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity

view this post on Zulip Davi Sales Barreira (Sep 20 2023 at 10:50):

Is the associativity also hard coded? No way to change them?

view this post on Zulip Sukera (Sep 20 2023 at 10:51):

yes

view this post on Zulip Sukera (Sep 20 2023 at 10:52):

imagine you have two packages, both defining an \oplus for their type - the decision for associativity needs to be made before types are known, so how could Julia decide which to use?

view this post on Zulip Davi Sales Barreira (Sep 20 2023 at 10:54):

Makes sense. Thanks @Sukera


Last updated: Nov 06 2024 at 04:40 UTC