Skip to content

String to int conversion in ASR #2554

Open

Description

@certik

Figure out a clean way to represent and implement string to int conversions in ASR.

Then figure out how to hook it up in LPython.

Discussed at https://lfortran.zulipchat.com/#narrow/stream/311866-LPython/topic/String.20to.20Int.20conversion.

Activity

  1. ubaidsk commented on Mar 17, 2024

    @ubaidsk
    Collaborator

    It looks like we already have some support for string to int conversion.

    % cat examples/expr2.py 
    def main():
        x: str = "123"
        print(int(x))
    
    main()
    % python examples/expr2.py         
    123
    % lpython_in_main examples/expr2.py
    123
  2. ubaidsk commented on Mar 17, 2024

    @ubaidsk
    Collaborator

    I think we just need to polish the existing support.

  3. kmr-srbh commented on Mar 25, 2024

    @kmr-srbh
    Contributor

    @Shaikh-Ubaid I think we should support the conversion mechanism which intrinsic_int uses, for all the integer types we have. My main concern is that doing i32(int("12345")) is counterintuitive.

  4. kmr-srbh commented on Mar 25, 2024

    @kmr-srbh
    Contributor

    The conversion mechanism for int needs to be improved too. It currently relies on std::stoi() and fails for anything larger than that. We only have to improve the BigInt library we already have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions