Skip to content
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

Deprecate $ as bitwise exclusive or to free ascii-char $ for more useful purpose #18696

Closed
davidavdav opened this issue Sep 27, 2016 · 25 comments

Comments

@davidavdav
Copy link
Contributor

davidavdav commented Sep 27, 2016

As I tried to discuss here I believe that $ is a waste of single ascii character operator space. xor() would probably read just as easy. (Unfortunately, the discussion quickly derailed towards the concatenation operator * for strings).

I think in the mean time $ is dispatched for more types than just (Bool, Bool), which is rather unfortunate. For Bool types, the operator could be replaced by ^. (Currently x::Bool ^ y::Bool has the semantics of "y implies x", which was not intended IMHO). [@jiahao: edited from discussion below; ^ is exponentiation]

It would be great to have $ free/deprecated before julia-0.6/1.0 is finalised. My personal favourite is that x$y is, somehow, interpreted as x[:y]. See also the the discussion at #1974 .

@stevengj
Copy link
Member

stevengj commented Sep 27, 2016

If we want x.y overloading (I do!), we should just implement that. (Note that you really want something like x[Val{:y}] so that it can be dispatched at compile-time.)

I don't think it would be a good idea to use ^ for both xor and exponentiation.

That being said, I'm inclined to agree that xor is uncommon enough that there's no need to define an ASCII binary operator for it. We could just use xor(a,b), and maybe const ⊻ = xor (\veebar<tab>).

@JeffBezanson
Copy link
Sponsor Member

I agree this is a waste of an ASCII operator. I might even extend the argument to | and & as well.

x::Bool ^ y::Bool is exponentiation. For 0 and 1 arguments ^ happens to have the same truth table as "implies".

@carnaval
Copy link
Contributor

For 0 and 1 arguments ^ happens to have the same truth table as "implies".

(not a coincidence, this is Curry-Howard :-))

@Sacha0
Copy link
Member

Sacha0 commented Sep 27, 2016

I agree this is a waste of an ASCII operator. I might even extend the argument to | and & as well.

+1, and in event of consensus I would lend a hand in the deprecation effort. Ref. #5187 and #5238.

@stevengj
Copy link
Member

| and & are really useful as non short-circuit boolean operators, so I would prefer to leave them as-is.

@tkelman
Copy link
Contributor

tkelman commented Sep 27, 2016

not entirely as is, we should deprecate the vectorized | and & now that dot operators are becoming more widespread and will be part of the syntax. $ is used for a few too many things and wouldn't be missed quite as much in infix. a unicode version would do fine.

@TotalVerb
Copy link
Contributor

👎 to using ^ for Bool types. It would be incredibly confusing to have different semantics of ^ for Bool and Int.

@davidavdav
Copy link
Contributor Author

x::Bool ^ y::Bool is exponentiation

I figured that, I just thought that false ^ false referring to 0^0 would be undefined. But I see now that 0^0==1 for all numeric types. But anyway, let's not discuss using ^ for xor() any further, that was probably a bad idea.

@jiahao
Copy link
Member

jiahao commented Sep 27, 2016

Did someone say Unicode? is not defined...

I edited the OP to reflect the discussion of ^ being exponentiation.

@StefanKarpinski
Copy link
Sponsor Member

Here's my position:

  • I'm all for getting rid of $ as infix xor. We can just have a function called xor.
  • Unless we have an equally intuitive meaning for & and | I don't see much point in getting rid of their current meanings, since the other usage would just be more confusing.
  • Bool^Bool cannot mean xor since that's operator punning which is the most basic no-no.

@JeffBezanson
Copy link
Sponsor Member

Sounds like it is resolved to deprecate $ to xor.

@davidavdav
Copy link
Contributor Author

Great! Will anyone pick this up or should I dig into the code and try to submit a PR?

@omus
Copy link
Member

omus commented Oct 12, 2016

I'd like to maintain having infix operators for all bitwise operations. Using a unicode operator such as ⊻ or ⊕ (\oplustab) would be fine for this purpose.

@omus
Copy link
Member

omus commented Oct 12, 2016

Alternatively, since bitwise operators aren't used very frequently we could always use a macro and stick to the traditional C bitwise operators.

@bitwise a ^ b  # XOR
a ^ b  # Exponentiation

I could also see this leading to confusion. Just a thought.

@TotalVerb
Copy link
Contributor

TotalVerb commented Oct 12, 2016

I'm ok with ⊻ (\veebar), but ⊕ is too useful for other stuff to be used for XOR, IMO.

@stevengj
Copy link
Member

Yes, is literally defined by Unicode as xor, whereas has other uses.

@BobPortmann
Copy link
Contributor

+100 to the use of $ to make x$y be interpreted as x[:y]. If x is a {Symbol,Any} dict (or custom Associative type) and it holds an array then x$y[i,:,j] is much nicer than x[:y][i,:,j] (the gain is larger if there are multiple levels of dicts).

@StefanKarpinski
Copy link
Sponsor Member

The reason you're getting some thumbs down is that people would prefer to have x.y meaning x[:y] and use the $ for something else altogether, which I have to confess I agree with.

@BobPortmann
Copy link
Contributor

I originally wanted x.y to mean x[:y] as well and would still be happy with it. But x$y would avoid some of the negatives of dot overloading, e.g.
-having to use something like x..y for true member access
-people abusing it to make julia look like a OO language

@davidavdav
Copy link
Contributor Author

So, then Base would define something along the lines of

getfield(t, member) = t..member
getfield(dict::Associative{Symbol}, key::Symbol) = dict[key]
getfield(dict::Associative{String}, key::Symbol) = dict[string(key)]

if . would translate to getfield() and .. would be the current .?

@stevengj
Copy link
Member

@davidavdav, see the discussion in #1974 and the attempted implementation in #5848; further discussion of getfield overloading should happen in #1974.

davidavdav added a commit to davidavdav/julia that referenced this issue Oct 16, 2016
This includes:
 - occurrances of $ (as operator) and $= in base
 - occurances of $ in test
 - the definition in the manual
 - the entry in REPL help
This patch passes `make test`.
davidavdav added a commit to davidavdav/julia that referenced this issue Oct 24, 2016
This includes:
 - occurrances of $ (as infix operator) and $= in base
 - occurances of $ in test
 - the definition in the manual
 - the entry in REPL help

This commit does not introduce an alternative,
that will happen in the next commit.
davidavdav added a commit to davidavdav/julia that referenced this issue Oct 30, 2016
This includes:
 - occurrances of $ (as infix operator) and $= in base
 - occurances of $ in test
 - the definition in the manual
 - the entry in REPL help

This commit does not introduce an alternative,
that will happen in the next commit.
davidavdav added a commit to davidavdav/julia that referenced this issue Nov 8, 2016
This includes:
 - occurrances of $ (as infix operator) and $= in base
 - occurances of $ in test
 - the definition in the manual
 - the entry in REPL help

This commit does not introduce an alternative,
that will happen in the next commit.
davidavdav added a commit to davidavdav/julia that referenced this issue Nov 11, 2016
This includes:
 - occurrances of $ (as infix operator) and $= in base
 - occurances of $ in test
 - the definition in the manual
 - the entry in REPL help

This commit does not introduce an alternative,
that will happen in the next commit.
simonbyrne pushed a commit that referenced this issue Nov 14, 2016
#18977)

* Deprecate $ for xor() (#18696)

This includes:
 - occurrances of $ (as infix operator) and $= in base
 - occurances of $ in test
 - the definition in the manual
 - the entry in REPL help

This commit does not introduce an alternative,
that will happen in the next commit.

* Add ⊻ as alternative to xor, and `⊻=` as alternative to `$=`.

Please note that `⊻=` is in the add-dots group in the parser, preparing for `.⊻=`.
However, this commit does not implement `.⊻` yet, this should happen in
a separate commit with `.&` and `.|` together.

* Add deprecation comment in show.jl and deprecation item in NEWS.md
fcard pushed a commit to fcard/julia that referenced this issue Feb 28, 2017
…Lang#18696 (JuliaLang#18977)

* Deprecate $ for xor() (JuliaLang#18696)

This includes:
 - occurrances of $ (as infix operator) and $= in base
 - occurances of $ in test
 - the definition in the manual
 - the entry in REPL help

This commit does not introduce an alternative,
that will happen in the next commit.

* Add ⊻ as alternative to xor, and `⊻=` as alternative to `$=`.

Please note that `⊻=` is in the add-dots group in the parser, preparing for `.⊻=`.
However, this commit does not implement `.⊻` yet, this should happen in
a separate commit with `.&` and `.|` together.

* Add deprecation comment in show.jl and deprecation item in NEWS.md
@LaszloHars
Copy link

LaszloHars commented Aug 22, 2018

I know, I am late in the party... Still, a standardized (extended) ASCII character for infix bitwise and Boolean XOR would be nice. The reasons:

  • In Windows, REPL does not show \veebar with the default font, and in most other monospace fonts. The couple fonts, which show it makes the terminal almost unreadable
  • The same is true for many code editors
  • Sometimes we must save our code as a pure ASCII file, and avoid any Unicode characters. xor(A,...) looks ugly and harder to comprehend than infix notations. Coding and crypto algorithms contain long XOR chains, and converting them to functional notations makes the expressions look very different than in other programming languages
  • If programmers define their own infix XOR symbol, others will have difficulty to understand the logic of the code

I tried to use the currency symbol for XOR: ¤. Other good candidates could be ¢, ¥, §, ©, ®, ¶...

@stevengj
Copy link
Member

stevengj commented Aug 22, 2018

None of the characters you propose are ASCII; I guess you mean Latin1?

The world in which you can use Latin1 but not Unicode is quickly becoming a memory...

@LaszloHars
Copy link

LaszloHars commented Aug 22, 2018

This is what I meant with "extended" ASCII. I don't know, if multiple code pages have identical symbols. If anything is common, we might be able to use that.
50 Years ago I designed a programming language, where all the bitwise logic operations were denoted by 2-character infix codes: \/, /\, >< and <>. Could we use >< for XOR?

@stevengj
Copy link
Member

stevengj commented Aug 22, 2018

Unicode turned the whole concept of "code pages" into a relic. Only one "code page" is allowed for Julia code, and that is UTF-8.

I agree that the shortcomings of the default Windows terminal (inadequate fonts being the least of them) is a persistent problem. It may be that we will simply have to bundle a better terminal on Windows; see #7267.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests