X Tutup
Skip to content

Simplify take-last#75

Closed
ghosthamlet wants to merge 2 commits intoclojure:masterfrom
ghosthamlet:patch-1
Closed

Simplify take-last#75
ghosthamlet wants to merge 2 commits intoclojure:masterfrom
ghosthamlet:patch-1

Conversation

@ghosthamlet
Copy link
Copy Markdown

Why take-last used more complex implement? Just for better performence?

Why take-last used more complex implement? Just for better performence?
@vendethiel
Copy link
Copy Markdown

Hello! Clojure does not accept pull requests. You can find more information on the Clojure contribution process at https://clojure.org/community/contributing.

Your implementation seems wasteful, even if you wanted to use drop + count, why not substract the number to keep to the count, which avoids an extra temporary collection.

@ghosthamlet
Copy link
Copy Markdown
Author

Thanks.
Yes,this is better: (drop (- (count coll) n) coll).
Don't know why no people did change many this like codes in Clojure core since 1.0.

@jafingerhut
Copy link
Copy Markdown
Contributor

In this particular case, I believe that (count coll) will scan linearly through the coll one time, then (drop coll) will scan linearly through the coll a second time. The existing implementation appears like it will only do a linear scan through the coll one time. Performance is often a significant concern in the implementation of Clojure's core functions.

@ghosthamlet
Copy link
Copy Markdown
Author

Thanks, agree with you .

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

Successfully merging this pull request may close these issues.

3 participants

X Tutup