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

make from an operator #14241

Merged
merged 3 commits into from
May 8, 2020
Merged

make from an operator #14241

merged 3 commits into from
May 8, 2020

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented May 6, 2020

Just extra syntax (for DSLs and macros) to use. I don't see any downsides to this.

There are other keywords that work fine when made operators, but may be limited to infix only. for, if, else, when, while with precedence 1 can be used for list comprehensions (though you have to do a if b for c in d unlike python) or postfix conditionals, and using is just an English word that sounds normal when used as a using b.

@Araq
Copy link
Member

Araq commented May 6, 2020

Needs an update of the manual and a changelog entry.

@metagn metagn changed the title silently make from an operator make from an operator May 6, 2020
@metagn
Copy link
Collaborator Author

metagn commented May 6, 2020

Docs CI failures seem to stem from b8e6ea7

@timotheecour
Copy link
Member

timotheecour commented May 7, 2020

out of curiosity, what are use cases for from as an operator?
as noted in nim-lang/RFCs#84 (comment), from is already usable in UFCS/MCS, eg: str.from "12"

The situation with math operators such as and is different because and returns a value so can be pipelined, eg a and b or c, whereas the use cases I have in mind for from (void return type, as in nim-lang/RFCs#84 (comment)) by definition can't be pipelined since they return void:

var ret: string
ret.from "12" # returns void

it may be confusing if operators returns void or non-void depending on the overload.

@metagn
Copy link
Collaborator Author

metagn commented May 7, 2020

  1. Manual proposes it for a future syntax in Nim itself
  2. Syntax flexibility for DSLs, I'm having trouble thinking of examples but from is too natural a word to not be able to use in freeform. I wanted to add more keywords that have uses in DSLs/macros (let odds = x if x mod 2 == 0 for x in @[1'u8, 2, 3, 4, 5] using newSeq, check OP these are compatible with current Nim) but those would be too much at a time, so I thought from was an acceptable start

@timotheecour
Copy link
Member

both 1 and 2 are good enough reasons, thanks! (and I'd be forever grateful if you could turn alias into a keyword :-) )

@Araq Araq added the merge_when_passes_CI mergeable once green label May 7, 2020
@narimiran narimiran merged commit de27910 into nim-lang:devel May 8, 2020
EchoPouet pushed a commit to EchoPouet/Nim that referenced this pull request Jun 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge_when_passes_CI mergeable once green
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants