Skip to content

Add to_str method for Bool, List, Dict, and universal types#8786

Closed
codegod100 wants to merge 1 commit intoroc-lang:mainfrom
codegod100:pr/to-str-methods
Closed

Add to_str method for Bool, List, Dict, and universal types#8786
codegod100 wants to merge 1 commit intoroc-lang:mainfrom
codegod100:pr/to-str-methods

Conversation

@codegod100
Copy link
Contributor

Summary

Adds to_str methods for converting values to string representation.

Changes

  • Add Bool.to_str method
  • Add List.to_str method with interpreter support
  • Add Dict.to_str method with interpreter support
  • Add universal to_str method for all types via Check.zig and ModuleEnv

Testing

  • Added snapshot test test/snapshots/to_str_methods.md

List.fold(list, Item.default(), |acc, elem| acc + elem)
}

to_str : List(U8) -> Try(Str, [BadUtf8({ index: U64, problem: Str.Utf8Problem }), ..others])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think List.to_str should be List(a) -> Str where { a.to_str() -> Str }. Utf8 to string should be in Str.

@lukewilliamboswell
Copy link
Collaborator

@codegod100 I think we should raise a topic in #ideas to discuss the design of these builtins. We have the Str.inspect helper.

- Add Bool.to_str method
- Add List.to_str method with interpreter support
- Add Dict.to_str method with interpreter support
- Add universal to_str method for all types via Check.zig and ModuleEnv
@lukewilliamboswell
Copy link
Collaborator

I don't think these builtin methods are planned -- we have Str.inspect for debugging values. Closing until we discuss this further to avoid confusion.

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