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
Should print be enhanced to allow substitution from the scope, e.g. in the expression parser x = 7; print('x is precisely $x') would produce the singleton ResultSet with 'x is precisely 7'?
There is an idiosyncrasy with $-interpolation: if the value of a is an array, and you want say the element at index 2, you must write print('a second: $a.2', {a: [0,1]}). You cannot write $a[2]. Should we enhance this so any valid accessor expression can occur immediately after the $ ? Moreover, a.2 is not normally a valid accessor expression; in the mathjs expression language (which continues to need a name, like "MEL" say), a.2 is implicit multiplication of a by 0.2. So should print be modified to not allow this $a.2?
It's already a bit like javascript string template interpolation. Should this similarity be extended so that $-expressions may have optional braces, and if so, the entire contents of the braces are evaluated as a mathjs expression in the current scope enhanced with the bindings of the second argument, if any, so that math.print('a and b sum to ${a+b}', {a: 2, b:2}) would evaluate to 'a and b sum to 4'? If we adopted this change, then print would be very similar to javascript string template interpolation, just with the extension that the braces are optional if the expression happens to be just a single variable or accessor expression. That would be very comfortable, at least to me.
I think there is an expressivity gap with print. Suppose that a is two, and you want to interpolate it into a string so that the result will come out literally like so: 'Interpolate $a2' where the 2 is from the interpolation. I don't think there is a way to do it: print('Interpolate $a$a', {a: 2}) of course comes out to 'Interpolate 22' and print('Interpolate $$a$a', {a: 2}) comes out to 'Interpolate $22' and print('Interpolate \$a$a', {a: 2}) is a syntax error with a bad escape character \$ and print('Interpolate \\$a$a', {a: 2}) comes out 'Interpolate \\22' (where in this case the \\ represents a single \ character in the actual string result). Should a syntax to allow this be added, e.g. $$ in the template results in a single $ in the output, or \$ becomes allowed as an escaped $ that won't trigger interpolation, or something else along these lines?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Should
print
be enhanced to allow substitution from the scope, e.g. in the expression parserx = 7; print('x is precisely $x')
would produce the singleton ResultSet with'x is precisely 7'
?There is an idiosyncrasy with $-interpolation: if the value of a is an array, and you want say the element at index 2, you must write
print('a second: $a.2', {a: [0,1]})
. You cannot write$a[2]
. Should we enhance this so any valid accessor expression can occur immediately after the $ ? Moreover,a.2
is not normally a valid accessor expression; in the mathjs expression language (which continues to need a name, like "MEL" say),a.2
is implicit multiplication ofa
by 0.2. So should print be modified to not allow this$a.2
?It's already a bit like javascript string template interpolation. Should this similarity be extended so that $-expressions may have optional braces, and if so, the entire contents of the braces are evaluated as a mathjs expression in the current scope enhanced with the bindings of the second argument, if any, so that
math.print('a and b sum to ${a+b}', {a: 2, b:2})
would evaluate to'a and b sum to 4'
? If we adopted this change, then print would be very similar to javascript string template interpolation, just with the extension that the braces are optional if the expression happens to be just a single variable or accessor expression. That would be very comfortable, at least to me.I think there is an expressivity gap with print. Suppose that
a
is two, and you want to interpolate it into a string so that the result will come out literally like so:'Interpolate $a2'
where the 2 is from the interpolation. I don't think there is a way to do it:print('Interpolate $a$a', {a: 2})
of course comes out to'Interpolate 22'
andprint('Interpolate $$a$a', {a: 2})
comes out to'Interpolate $22'
andprint('Interpolate \$a$a', {a: 2})
is a syntax error with a bad escape character\$
andprint('Interpolate \\$a$a', {a: 2})
comes out'Interpolate \\22'
(where in this case the\\
represents a single\
character in the actual string result). Should a syntax to allow this be added, e.g.$$
in the template results in a single$
in the output, or\$
becomes allowed as an escaped $ that won't trigger interpolation, or something else along these lines?Beta Was this translation helpful? Give feedback.
All reactions