More Literal Types... #6945
Replies: 5 comments 22 replies
-
While the backtick for expression syntax and likely regex will need special handling anyway, as for the date-time literals, I'd suggest to consider what Scala does: essentially allowing to define a 'special function' for handling string literals (there it's main usage is string interpolation, but that is another topic). So one can define Essentially the idea is to allow users to define custom string literals, identified by their prefix - i.e. I'm not 100% convinced this is right for Enso as it may make the code less readable if we have 100s of literals, so maybe just the few provided for date-time are enough for us. But I thought it may be at least worth considering as it offers some flexibility. |
Beta Was this translation helpful? Give feedback.
-
@jdunkerley how these literals are better than writing
We can even make it more special and return a correct type based on the string, like:
TBH I really hate prefixes to literals like |
Beta Was this translation helpful? Give feedback.
-
Regex is usually problematic because of all the escape characters it needs and that clash with escape characters used by C-like languages.
Why don't you type the
Enso already provides support for |
Beta Was this translation helpful? Give feedback.
-
The motivation behind this is to make user experience trivial. Let's just consider the user wanting to enter a date constant. I imagine them going to the plus button and then choosing a "Date literal" from the list. This should insert something like The thoughts around having a literal like The same experience is also needed for the other literal types. If I am entering a regex, I would love the regexr style experience where it syntaxes highlights and helps explain. As @JaroslavTulach, we can us the functional language style for this but would need to think clearly how this was widget-able. This is also very true for Vector, Map and Table literals which again really need nice UI experiences. |
Beta Was this translation helpful? Give feedback.
-
So to summarise. We will add a new literal syntax for Regex (for example, The IDE will recognise One area we may want to examine again later is string interpolation but that is another topic. |
Beta Was this translation helpful? Give feedback.
-
We currently have literal support for Number and Text.
We have previously spoken about adding ``` (backtick) to be identified as an expression (so we can make it explicit rather than implied).
Following a discussion with @GregoryTravis and @radeusgd, it would be very useful to follow JavaScript's lead and support a regex literal. They use
/
to identify this. We can then retire all of theuse_regex
options as we would get aRegex.Pattern
. It can also then be used to do syntax highlighting within the IDE (as would also be the case with backticks above).Additionally, a literal format for date and time objects would be a great addition to a data product. I appreciate not many general purpose languages allow this but for our use case this would be fantastic. Something like:
d'2021-03-02'
==> Datet'12:00:00'
==> Time_Of_Daydt'2021-03-02 12:00:00'
==> Date_Time(Any Enso supported literal Date/Time format (ISO+))
cc: @sylwiabr @wdanilo @JaroslavTulach @hubertp
Beta Was this translation helpful? Give feedback.
All reactions