You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As continuation of to-string story, now we have means to implement a way to convert structure into a string summary for many languages. However, what we end up having now is pretty basic:
It's ugly (and thus hard to read, hard to write, and generally error-prone). Syntax highlight kind of helps, but there are still not too many options to have good syntax highlighting for KS expression language.
It's very limited. It's really hard to get rich formatting capabilities: hex/oct/bin representations, padding, etc.
Most modern languages solve this with interpolated / format strings. WebIDE actually got ahead and implemented a simple version of this with -webide-representation. One can use:
head {foo} tail to interpolate value of foo into the string
it can do integers; default representation of integers is hex
it can do floating points
it can do enums (as string values)
it can do strings
it can do byte arrays (as [1, 2, 128])
it can do true arrays (with , separator — e.g. foo, bar, baz)
it can do other structs (cascading into other -webide-representation definitions)
{foo:dec}, {foo:hex} enforce either decimal or hexadecimal formatting
{foo:sep=*} dumps arrays of with custom separator (e.g. as foo*bar*baz)
Other modern languages have something similar:
Python has f-strings since v3.6 with both execution of code within the interpolated strings, formatting and conversion capabilities:
Ruby has interpolation in double-quoted strings with code execution delimited in #{ and }. There are no quick formatting options, but one can chain to_s and rjust to achieve similar effect:
So, ultimately, looks like 2 options: either code execution only, or code execution + formatting.
Proposal
Let's implement KS expression language formatting strings which will more or less match subset of Python (as we're already borrowing quite a lot from Python syntax):
As continuation of
to-string
story, now we have means to implement a way to convert structure into a string summary for many languages. However, what we end up having now is pretty basic:Two problems with it:
Most modern languages solve this with interpolated / format strings. WebIDE actually got ahead and implemented a simple version of this with -webide-representation. One can use:
head {foo} tail
to interpolate value offoo
into the string[1, 2, 128]
),
separator — e.g.foo, bar, baz
)-webide-representation
definitions){foo:dec}
,{foo:hex}
enforce either decimal or hexadecimal formatting{foo:sep=*}
dumps arrays of with custom separator (e.g. asfoo*bar*baz
)Other modern languages have something similar:
Python has f-strings since v3.6 with both execution of code within the interpolated strings, formatting and conversion capabilities:
Ruby has interpolation in double-quoted strings with code execution delimited in
#{
and}
. There are no quick formatting options, but one can chainto_s
andrjust
to achieve similar effect:Scala has s-strings and f-strings:
JavaScript has backtick strings with
${foo}
syntax, but only with code execution, no special terse formatting:C# has dollar strings + curly brackets with both code execution and formatting:
So, ultimately, looks like 2 options: either code execution only, or code execution + formatting.
Proposal
Let's implement KS expression language formatting strings which will more or less match subset of Python (as we're already borrowing quite a lot from Python syntax):
So, syntax-wise, it will be:
f"
and"
to border new type of string literal with interpolation{
and}
inside the new string literal to delimit portions of the string which will be interpreted as code and format:
with "format"length
— digits forming a number for width of the field; if starts with "0", it's zero-paddedformat letter
— we'll support:d
for integer decimalx
for hexo
for octalb
for binary and that's itExecution
Can be done in 2 steps:
a.to_s + b.to_s + c.to_s + ...
and render it in target language.:
and subsequent stuff).The text was updated successfully, but these errors were encountered: