Replies: 4 comments
-
In my opinion, there are many benefits to working on a feature like this incrementally (as opposed to waterfall). We should start small in scope, iterate on the design until it suits our needs, and go from there. |
Beta Was this translation helpful? Give feedback.
-
For the interpolation bit, we might also want to consider using the slightly more general mechanism of quotations and antiquotations, used for instance in SML/NJ and Moscow ML. It subsumes string interpolation and can be used to construct arbitrary data from fragments of strings and quoted values. It's a bit hard to find good references for this feature, but many theorem provers use it to splice computed values into contexts (parsed from) strings. The description of the feature in SML/NJ (without any examples). An overview of implementation techniques (sketchy) https://prism.ucalgary.ca/server/api/core/bitstreams/3c150ee9-1dce-4716-8fcc-e31e50e603e8/content A formalization for SML. https://smlfamily.github.io/successor-ml/OldSuccessorMLWiki/Quoting_and_anti-quoting.html Stack overflow answer showing how to use this specifically for string interpolation. https://stackoverflow.com/questions/70735887/how-to-write-multiline-strings-in-sml |
Beta Was this translation helpful? Give feedback.
-
i agree, huge benefits. But being cautious is good. But i also consider at least think adding at the beginning just boolean coersion in logical context or triggered by logical operators such as && || ! (i.e let var = ''; let str = |
Beta Was this translation helpful? Give feedback.
-
See #3995 |
Beta Was this translation helpful? Give feedback.
-
Benefits of this language feature:
Proposed implementation:
The proposed implementation would use either a back tick
`
or double single quotes''
to start the multi-line text string. Here's an example:In the example above, we have used the back tick delimiter to create a multi-line string that includes string interpolation. The variables name and age are inserted directly into the string using the ${} syntax. We have also included an expression (
age + 5
) inside the string, which is evaluated and included in the final string.This feature can be scaled up to include more complex expressions and even functions, making the code more powerful and flexible.
Overall, the addition of multi-line text strings with string interpolation would be a useful feature for Motoko programmers, allowing them to write more readable and maintainable code, simplify their code, and increase the flexibility of their programs.
Open Questions
Should this feature be rolled out in stages? We could imagine starting with only supporting already-declared variables of type
Text
.In the future, we may want to have an equivalent of
debug_show
which would have more consistent behavior for transforming complex types into text strings, so they can be more dynamically inserted. This could be automatically evaluated on values interpolated into strings for convenience. This would allow this type of code:Without the need for manually transforming the
Nat
intoText
.Beta Was this translation helpful? Give feedback.
All reactions