-
-
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
std/lists: Various changes to lists
(RFC #303)
#16536
Conversation
As discussed here. |
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.
append
should not be deprecated IMO, as it looks more natural in code that also uses prepend
.
Yeah, please don't deprecate |
While I'm at it, there are a couple of other functions that would be helpful, such as:
And some unification:
What do you think? Also, is the reference to the list-list |
yes, but all these in another PR so that this PR can be merged sooner rather than later :) notes:
historical baggage and lack of specification / enforcement of https://nim-lang.github.io/Nim/nep1.html, let's discuss this separately
we currently can't do better than what you wrote ( |
@salvipeter please remember to mark as resolved comments you've resolved :) |
proc remove*[T](L: var SinglyLinkedList[T], n: SinglyLinkedNode[T]) =
## ...
=>
proc remove*[T](L: var SinglyLinkedList[T], n: SinglyLinkedNode[T]): bool =
## ...
## Returns true if `n` was found in `L` which is more flexible, eg client code can discard the result if they don't care, of Note that the pre-existing |
var a = [10,11,12,13].toDoublyLinkedList
a.append newSinglyLinkedNode[int](5) (and then would give an error in the wrong place, inside instantiation of instead do this: proc append*[T](a: var (SinglyLinkedList[T] | SinglyLinkedRing[T]), b: SinglyLinkedNode[T] | T) =
## ...
a.add b
proc append*[T](a: var (DoublyLinkedList[T] | DoublyLinkedRing[T]), b: DoublyLinkedNode[T] | T) =
## ...
a.add b I don't think concepts or generics are powerful enough to allow writing this using a single proc (maybe @Araq knows how?), but this would be easy with proc append*[T](a: var SomeLinkedCollection[T]), b: SomeLinkedNode[T] | T) {.enableif: type(a.head) is type(b).} =
a.add b for eg, this fails: type Bar[T] = object
foo: int
proc fn[T](a: Bar[T], b: typeof(a.foo)) = discard # Error: undeclared field: 'foo' |
Yes, this was bothering me, too - it would be nice if it could be written as a single proc, but for the time being I changed it as you recommended. Also added |
As for |
not sure we need; the point of re-adding append after the rename append=>add was to avoid breaking code; but no code ever used appendMoved so no need to introduce this alias |
there's also |
lists
(RFC #303)lists
(RFC #303)
ping @salvipeter |
I'm still alive, just work & family have priority :) I'll do a revision soon though. |
JavaScript compilation seems to break because the |
Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
proc appendMoved*[T: SomeLinkedList](a, b: var T) {.since: (1, 5, 1).} = | ||
## Alias for `a.addMoved(b)`. | ||
## | ||
## See also: | ||
## * `addMoved proc <#addMoved,SinglyLinkedList[T],SinglyLinkedList[T]>`_ | ||
## * `addMoved proc <#addMoved,DoublyLinkedList[T],DoublyLinkedList[T]>`_ | ||
a.addMoved b |
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.
proc appendMoved*[T: SomeLinkedList](a, b: var T) {.since: (1, 5, 1).} = | |
## Alias for `a.addMoved(b)`. | |
## | |
## See also: | |
## * `addMoved proc <#addMoved,SinglyLinkedList[T],SinglyLinkedList[T]>`_ | |
## * `addMoved proc <#addMoved,DoublyLinkedList[T],DoublyLinkedList[T]>`_ | |
a.addMoved b |
refs #16536 (comment)
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.
I think it would be a mistake not to add appendMoved
, especially now that we are not deprecating the append
functions at all. If there is prependMoved
, symmetry asks for appendMoved
. But that's just my 10 cents.
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.
how about removing it in this PR and so that we can move forward with this PR and adding it in another PR so it can be discussed separately without block this?
apart from this point, I think it's ready to go
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.
I'm not that emotionally attached to the idea, just wanted to give you a chance to reconsider :)
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.
I agree with salvipeter, and it should be decided in this PR IMO.
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.
@timotheecour I'm readding it to get on with this and not subject salvipeter to this review ping pong :D
Removing appendMoved
can also be done in a further PR (until the release); but as of now there is no argument to not add it.
EDIT: Let's wait for @Araq to decide.
Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
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.
LGTM, excellent work!
ping ? |
@salvipeter thanks for pinging, don't hesitate to in future, it's easy to forget PR's ; now that this was merged, PR welcome to address remaining points that were discussed here (ideally, breaking down in multiple smaller PR's whenever possible will make reviewing/merging faster) |
) * Various changes to `lists` (RFC nim-lang#303) * Removing a non-element is no-op; better tests * Remove preserves cycles; add appendMove alias; tests. * Return value for (singly linked) `lists.remove` * More test for lists.remove * Moved `lists.append` to the end of the file to see all `add` definitions * Disable testing js for now * Use workaround for swap js bug * Smaller diff * Undo "silent" deprecation of append * Correct typo in changelog Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Remove `appendMoved` Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> * Don't remove appendMoved Co-authored-by: Clyybber <darkmine956@gmail.com> Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
fixes #16771 follow up #16536 Ideally it should be handled in the IR part in the future I have also checked the double evaluation of `swap` in the JS runtime #16779, that might be solved by a copy flag or something. Well, it should be best solved in the IR so that it doesn't bother backends anymore.
No description provided.