-
-
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
Add more unary operators #18139
Comments
I'm confused by the thinking here. Why would we want to make some random set of characters into unary operators? |
There are a couple postfix unary operators, namely To add more, there needs to be an argument that a character has been used as an operator e.g. in some subfield, or that its only reasonable use would be as an operator, etc. It can't just be random characters. |
The sunshine suggestion was fanciful, but there aren't a whole lot of clean unary operators in mathematical notation. Most of them are diacritics or some form of brackets, and neither of those are suitable for Julia. Could we at least get the Hermitian operators † and ⊹? Perhaps that's a different problem, but the way MacroTools handles variables: |
Those are both currently invalid characters in julia, so yes this definitely seems possible. |
|
I think the way is "petition the Unicode committee and hope it gets included in Unicode N+1" ? |
@TotalVerb For what, variables in pattern-matching? I want to build a tree with variables in it, and manipulate the tree. Right now it looks like |
Is there any way to make the dagger operator parsable as a variable name? Right now it's just invalid. |
Yes, definitely, but we would need to decide on its syntax --- i.e. does it parse as an identifier, or some kind of operator? |
Personally, I would use dagger as an identifier (ie part of a variable name). The complex transpose already has a symbol for it so it makes little sense to just have † do the same operation. The exact use case I have is to store the result of something like this: a†a = a'*a |
That seems like a nice usage well aligned with how we already allow superscript integers and such. |
Also, the most sensible meaning for a |
Hi, I didn't know about this issue but I found it after posting on discourse I think it would be really great if people could define their own unary operators. Unary operators aren't so uncommon in mathematics. Perhaps, a special character could be used in conjunction in order to help the parser determine that it is a unary operator. For example, For example factorial would be right-handed as in Not saying that |
@chakravala, the discussion of custom unary operators is very similar to the discussion of custom infix operators — see #16985. It's a bit of a rat's nest when you get into syntax details. |
I would like to add |
Should I just add it at the end of line for primes? (wc >= 0x2032 && wc <= 0x2037) || wc == 0x2057 || wc == 0x2020 || |
FWIW I’d like to have |
The ship has definitely sailed on "keeping the number of operators to a minimum"—I don't think that's ever going to be the stance. I think that if the case can be made for any operator having a standard syntax and precedence that fits in with the way Julia is parsed, we're happy to support it. The issue with unary operators is more that they're a bit weird syntactically than that we don't want more operators. |
I think a postfix unary operator to implement |
@kauesena By the way, we can currently do this: julia> var"'ᵀ"(a) = transpose(a)
julia> [im, 1]'ᵀ
1×2 transpose(::Vector{Complex{Int64}}) with eltype Complex{Int64}:
0+1im 1+0im |
if we're creating a list of desired unary operators, adding the cross matrix as a postfix operator for LinearAlgebra would be nice: |
@Will-Hendrix, see PSA: Julia is not at that stage of development anymore — any operator that is currently parsed as binary (like |
Julia has an impressive list of binary operators, but the unary operators are quite lonely:
(+ - ! ¬ ~ |<:| |>:| √ ∛ ∜)
, and most of them have existing meanings. Having a lot of operators makes it easier to define nice-looking DSLs. I can't think of too many mathematical unary operators, except maybe DAGGER † (can we have post-fix unary operators?) so perhaps we could grab ~random unicode characters (☼💣❖) and call them unary?The text was updated successfully, but these errors were encountered: