-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
new outplace operator: doAssert @[2,1,3].>sort() == @[1,2,3]
#13309
Conversation
Nice, is the reason you are not using If so, I think we generally should change operator precedence of things starting with one dot. WDYT? |
Personally I'd rather just use the function. The function isn't used enough to merit it's own operator |
Agree, not a fan of adding linenoise. I’d rather wait and see if a convention evolves and then copy it. Also, you have a typo in your doAssert message. |
that's because it got recently introduced, and more importantly,
not clear what you mean by adding linenoise. the noisier convention so far has been to add an overload with prefix
fixed
not sure I understand your comment. I am implementing |
@timotheecour I meant to ask why |
mostly "and stuff": I needed to "rotate" the AST to make it work. template `.@`*(lhs, rhs): untyped = outplace(lhs, rhs) on the unittest examples and you'll see the problem. |
2 ways to do the same are bad, we should only have |
@Araq "outplace" is quite a bit more descriptive than |
PTAL:
proc bar(x: int, ret: var int) = ret += x
doAssert 3.@bar(4, _) == 3 + 4 # use placeholder `_` to specify a position > 0 see tests |
019ea11
to
093a070
Compare
I like it but we could have some bike-shedding session about the operator symbol to use. |
This is a very bold claim. I'll repeat my comments from IRC: My concern is that
I know it is really a How about |
While I like this operator, I am not so sure about the choice of It kind of steals the special notation for sequences in Nim. So while I don't quite like |
I already mentioned on IRC that I like However, I do see the issue about confusing people. Given that Nim shouldn't become a "heres a
|
Its not really related to seqs, so |
Here is my current opinion: Let's move it to a new module, var a = @[1, 2, 3, 4, 5, 6, 7, 8, 9]
doAssert a./sort() == sorted(a)
#Chaining:
var aCopy = a
aCopy.insert(10)
doAssert a./insert(10)./sort() == sorted(aCopy)
doAssert @[1,3,2]./sort()./sort(order = SortOrder.Descending) == @[3,2,1] |
093a070
to
5ab8678
Compare
With #13332 we can get rid of the AST "rotating". |
alternative symbolThe other suggestion i had was:
I suppose we can still merge this and update code if/when yours gets merged |
@Araq PTAL
|
I also liked |
I think |
@timotheecour Now you just need to edit this PR's title 😁 Thanks for working on this feature! |
doAssert @[2,1,3].@sort() == @[1,2,3]
doAssert @[2,1,3].>sort() == @[1,2,3]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is now in a separate module, can't we check how popular this is as a nimble package first? Then decide whether to include it in the stdlib or not?
We need less of these tiny modules that only 1% of our already small user base are using. It's unrealistic for us to maintain.
## Outplace operator: turns an `in-place`:idx: algorithm into one that works on | ||
## a copy and returns this copy. A placeholder `_` can optionally be used to | ||
## specify an output parameter of position > 0. | ||
## **Since**: Version 1.2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Paragraphs! Please add empty line above this, otherwise it'll render poorly in the doc gen.
Also, you need to add this file to the docgen config IIRC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add empty line above this
done
Also, you need to add this file to the docgen config IIRC.
I believe I've fixed this in a general way in #13221
I fail to see see how it's unrealistic to maintain this, let's not blow things out of proportion or use FUD. see note from @Araq https://irclogs.nim-lang.org/23-01-2020.html#13:43:07
that's to ensure uniformity instead of alternatives where you'd have
currently we have a rather arbitrary mix (and that's just for stdlib):
After this PR the new guidelines are simple:
|
please do not merge yet |
Is there any way this could optimize consecutive uses of the operator, to prevent spurious intermediate copies from being made? |
@Varriount They will be optimized to moves anyways, but yeah. Timothee is working on exactly that. |
If you're after honest numbers there is no way to measure it but to include it into the core and declare it to be "experimental". And then later on you can see how often if it's used or not. People avoid dependencies like the plague and even moreso for "tiny syntactic improvements". I wouldn't use |
actually they won't be optimized away, it's easy to check by inserting |
sorry there was a misunderstanding, yes i agree with Araq for simple sugar, but not for complicated like pattern matching: not sure where does this feature fall into |
to follow a not-always-but-often observed convention that module name use plural; I'd be ok with |
Only 30/84 of the modules at the top level of |
Plural doesn`t make sense in this case IMO. |
I am looking forward to seeing this merged. @Araq the only resolution needed here is now |
Depends on nim-lang/RFCs#192 |
FWIW, |
Outdated PR, nim-lang/RFCs#192 is shipping. |
note
i was previously using
.@