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

automatically promote primitive types to objects when necessary #8

Open
zxul767 opened this issue Nov 6, 2022 · 1 comment
Open
Labels
enhancement New feature or request p1

Comments

@zxul767
Copy link
Owner

zxul767 commented Nov 6, 2022

Currently there is a difference between primitive types (i.e., numbers, booleans and strings) and objects, as far as their representation goes. this prevents primitive types from having methods (e.g., we cannot say "string".length())

while it is desirable to keep primitives as lightweight as possible (e.g., to avoid costly overhead when holding collections of them), it is also quite convenient to be able to write expressions such as "string".ends_with("ing") instead of string__ends_with("string", "ing").

we should explore the possibility of having an expression such as:

"string".starts_with("str")

be equivalent to:

str("string").starts_with("str")

where str(.) is the cast operator (or alternatively, the str class constructor overloaded for various types) that returns an object.

while it might also be desirable to do something similar for numbers and booleans, the need is much less clear (e.g., writing 12.sin() or (-12).abs() adds no more clarity than their usual counterparts sin(12) and abs(-12); on the contrary, they are arguably less clear.)

@zxul767 zxul767 changed the title automatically cast primitive types to objects when necessary automatically promote primitive types to objects when necessary Nov 6, 2022
@zxul767 zxul767 added the enhancement New feature or request label Nov 11, 2022
@zxul767
Copy link
Owner Author

zxul767 commented Dec 6, 2022

the implementation for string literals is now in main for jlox (clox needs to catch up right after the PR for adding list is done)

@zxul767 zxul767 added the p1 label Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p1
Projects
None yet
Development

No branches or pull requests

1 participant