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

[stdlib] Add bin() builtin function #2603

Closed
wants to merge 1 commit into from
Closed

Conversation

bgreni
Copy link

@bgreni bgreni commented May 10, 2024

Fixes #2604

Implements the bin() builtin function from Python for converting integral values to a binary string representation.

Leaving this as a draft for now as Python dictates that any type that implements __index__ can be passed into this function, and #2384 introduces an Indexer trait for that method. Which is also blocking the Bool specialization since implementing fn bin(b: Bool) allows SIMD values of size > 1 to be implicitly converted.

Copy link
Collaborator

@JoeLoser JoeLoser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, thank you for the contribution! I'd recommend un-drafting this and not coupling it to #2384. We can come back through once #2384 makes it through. Thoughts, @laszlokindrat?

stdlib/test/builtin/test_bin.mojo Outdated Show resolved Hide resolved
stdlib/test/builtin/test_bin.mojo Outdated Show resolved Hide resolved
stdlib/src/builtin/bin.mojo Show resolved Hide resolved
@bgreni bgreni marked this pull request as ready for review May 16, 2024 05:14
@bgreni bgreni requested a review from a team as a code owner May 16, 2024 05:14
@laszlokindrat
Copy link
Contributor

Generally looks good, thank you for the contribution! I'd recommend un-drafting this and not coupling it to #2384. We can come back through once #2384 makes it through. Thoughts, @laszlokindrat?

In #2384 I suggested to split up the patch into two: one that delivers Indexer and a second one that updates __getitem__ and friends. Given that using that trait this patch would simplify dramatically, I would recommend waiting for Indexer instead of having to come back and delete/move a bunch of code.

@laszlokindrat
Copy link
Contributor

Indexer will be available in the next nightly, please rebase when that comes out.

Signed-off-by: Brian Grenier <grenierb96@gmail.com>
Copy link
Contributor

@laszlokindrat laszlokindrat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thank you!

@laszlokindrat laszlokindrat added the imported-internally Signals that a given pull request has been imported internally. label May 17, 2024
@modularbot
Copy link
Collaborator

✅🟣 This contribution has been merged 🟣✅

Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the nightly branch during the next Mojo nightly release, typically within the next 24-48 hours.

We use Copybara to merge external contributions, click here to learn more.

@modularbot modularbot added the merged-internally Indicates that this pull request has been merged internally label May 17, 2024
@modularbot
Copy link
Collaborator

Landed in d652195! Thank you for your contribution 🎉

@modularbot modularbot added the merged-externally Merged externally in public mojo repo label May 18, 2024
modularbot pushed a commit that referenced this pull request May 18, 2024
[External] [stdlib] Add `bin()` builtin function

Fixes #2604

Implements the `bin()` builtin function from Python for converting
integral values to a binary string representation.

Co-authored-by: bgreni <42788181+bgreni@users.noreply.github.com>
Closes #2603
MODULAR_ORIG_COMMIT_REV_ID: 96515ed124867bcac5a49781d57a92fae6bc480b
@modularbot modularbot closed this May 18, 2024
msaelices pushed a commit to msaelices/mojo that referenced this pull request May 18, 2024
[External] [stdlib] Add `bin()` builtin function

Fixes modularml#2604

Implements the `bin()` builtin function from Python for converting
integral values to a binary string representation.

Co-authored-by: bgreni <42788181+bgreni@users.noreply.github.com>
Closes modularml#2603
MODULAR_ORIG_COMMIT_REV_ID: 96515ed124867bcac5a49781d57a92fae6bc480b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imported-internally Signals that a given pull request has been imported internally. merged-externally Merged externally in public mojo repo merged-internally Indicates that this pull request has been merged internally
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants