> In addition, there is the question of how user-defined literals would > get turned into constants within the code.
So, I'm just brainstorming here, but how about the following approach: - Whenever a compiler sees `abc"def"`, it creates a constant of the type `ud_literal` with fields `.prefix="abc"`, `.content="def"`. - When it compiles a function then instead of `LOAD_CONST n` op it would emit `LOAD_UD_CONST n` op. - This new op first checks whether its argument is a "ud_literal", and if so calls the '.resolve()` method on that argument. The method should call the prefix with the content, producing an object that the LOAD_UD_CONST op stores back in the `co_consts` storage of the function. It is a TypeError for the resolve method to return another ud_literal. - Subsequent calls to the LOAD_UD_CONST op will see that the argument is no longer a ud-literal, and will return it as-is. This system would allow each constant to be evaluated only once and subsequently memoized, and only compute those constants that will actually be used. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/JMLDHB4W44TZP5I72KQC55VIEJ56A5RW/ Code of Conduct: http://python.org/psf/codeofconduct/