Future of Literals. Are they going to be removed?

As a very interesting question for myself, we can see literal types in many of the AOT-compiled languages out there. But in Mojo, because of its goal to be more Pythonic, are we going to eventually deprecate literals? For example to have only one single 'string' type in the future?
9 Replies
Melody Daniel
Melody Daniel5mo ago
Python documentation
2. Lexical analysis
A Python program is read by a parser. Input to the parser is a stream of tokens, generated by the lexical analyzer. This chapter describes how the lexical analyzer breaks a file into tokens. Python...
Arvin_David
Arvin_David5mo ago
I understand but at the moment, we have some string methods that we don't have in string literal. My question is whether string literal should eventually replicate all methods implemented for string or it will be removed in the future without any need for extra copy-pasting to make them compatible. Also as another example, when the builtin type function got implemented in Mojo, should we get the result of 'type("Hello World!")' as string literal or string? From the Pythonic aspect and without knowing what's going on under the hood, we simply identify that as a "string" in Python so it's questionable how is this going to be like in Mojo. I hope these explanations can clarify why I asked this question. 😄 For instance, maybe literals get identified and handled only by the compiler itself and not be definable explicitly by the user anymore? Something like what Python does? So then only one 'string' struct is what is needed to get written/used in all codes?
Ryulord
Ryulord5mo ago
string literals will eventually be implicitly converted to ordinary strings so you can do things like 'Hello, World!'.split(' '). I don't recall where this was mentioned though
Maxim
Maxim5mo ago
I think you don’t want to remove String literal as a type as it has multiple beneficial properties like it’s immutable, known at compile time, has static lifetime. What would be nice is a compiler based auto conversion to a String when you start using it as a String.
Melody Daniel
Melody Daniel5mo ago
Extensions will allow defining methods that work on both in one place. Though I should think that StringLiteral will eventually materialize to string
Arvin_David
Arvin_David5mo ago
Thanks guys. These explanations are exactly what I wanted to hear.
Nick!
Nick!5mo ago
@Maxim You can also have an immutable String with a static lifetime that is known at compile-time. That’s basically what alias does. I don’t think StringLiteral helps with that.
Maxim
Maxim5mo ago
Strings are mutable though 🤷‍♂️. Not sure what will happen with an alias which will be mutated at compiled time and then at the runtime. It sounds like a mess.
Nick!
Nick!5mo ago
Strings stored in alias variables are not mutable
Want results from more Discord servers?
Add your server