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

Replace in by #316

Closed
eschnett opened this issue Oct 8, 2020 · 8 comments · Fixed by #653
Closed

Replace in by #316

eschnett opened this issue Oct 8, 2020 · 8 comments · Fixed by #653
Labels
enhancement New feature or request

Comments

@eschnett
Copy link
Contributor

eschnett commented Oct 8, 2020

It would be nice to replace in by (typed \in). Julia accepts this for the regular operators as well as in for statements.

@domluna domluna added the enhancement New feature or request label Oct 8, 2020
@domluna
Copy link
Owner

domluna commented Oct 8, 2020

😄 i knew someone would ask for this at some point

@StefanKarpinski
Copy link
Contributor

Note that as an operator is just a binding, so it's not generally safe to replace in with or vice versa. In the for syntax, it is safe because it's syntactic.

domluna added a commit that referenced this issue Mar 7, 2021
@domluna
Copy link
Owner

domluna commented Mar 7, 2021

Would something like this make sense #380 ?

@eschnett
Copy link
Contributor Author

eschnett commented Mar 7, 2021

This looks fine. It's more general than necessary since the only three options are i = 1:10, i in 1:10, and i ∈ 1:10. Are you expecting to allow setting in_replacement to =?

There's also a question of spacing. in requires spaces on the left and right, the other two don't.

@domluna
Copy link
Owner

domluna commented Mar 7, 2021

Either way it would add another option so at least in_replacement is more general than just \in. Spaces would be added like they are for =

domluna added a commit that referenced this issue Mar 7, 2021
Adds an option `for_in_replacement` which allows "in" to be replaced with
another operator such as "∈" `\in` or "=" when `always_for_in` is
enabled.
@domluna
Copy link
Owner

domluna commented Mar 7, 2021

Ok I've named this for_in_replacement. I'm not 100% sold on that name if you folks can think of something better I'm all ears.

@domluna
Copy link
Owner

domluna commented Mar 14, 2021

There's no way to include \in as part of variable name right?

julia> foo(always_for_in::Bool) = 10
foo (generic function with 1 method)

julia> bar(always_for_∈::Bool) = 10
ERROR: syntax: "(always_for_ ∈ ::Bool)" is not a valid function argument name around REPL[31]:1

@eschnett
Copy link
Contributor Author

No, \in is an operator, similar to +. x+ also wouldn't be allowed, as it parses as two tokens (x, +).

exaexa pushed a commit to exaexa/JuliaFormatter.jl that referenced this issue Nov 3, 2022
exaexa pushed a commit to exaexa/JuliaFormatter.jl that referenced this issue Nov 3, 2022
Adds an option `for_in_replacement` which allows "in" to be replaced with
another operator such as "∈" `\in` or "=" when `always_for_in` is
enabled.
domluna added a commit that referenced this issue Nov 11, 2022
* possible solution to #316

* fix always_for_in options in the case of filter/flatten

* Solve #316

Adds an option `for_in_replacement` which allows "in" to be replaced with
another operator such as "∈" `\in` or "=" when `always_for_in` is
enabled.

* fmt

* typo

* make `valid_for_in_op` simpler

* post-rebase fixups

* fix a forgotten `end`

* add validation for `for_in_replacement`

* simplify if/else structure in `eq_to_in_normalization!`

* get tests to pass - only transform binary op if it's a valid 'in' op

* format

* add warning log about for_in_replacement, and return the input text

* spelling

* tests

* Docs

Co-authored-by: Dominique Luna <dluna132@gmail.com>
Co-authored-by: iblis17 <iblis.dif01@nctu.edu.tw>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants