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
In Python, there's a useful little feature that allows writing something like the following:
foo="bar"print(f"{foo=}")
which prints:
foo = 'bar'
Notice how it preserved the spaces before and after the equals sign as written in the f-string.
I think this feature would be a very nice addition to Yuescript, although it may need some simplification. In Python, the code actually translates to printing the repr of foo, not the string conversion; an equivalent would be to write print("foo = " + repr(foo)). But of course that doesn't exist in Lua. My suggestion would be to either just print the value's tostring(), or maybe using a library function to pretty print it. While Yuescript seems to generally prefer inlining things to prevent being dependent on any libraries, I believe it would be fine here, because this is a pure development/debugging feature, so it's pretty safe to expect someone to have Yuescript installed if their code makes use of it.
The text was updated successfully, but these errors were encountered:
So you suggest that we can make some pretty print function code inlined, so that we can do it without importing extra libs?
No that's not what I meant. I talked about pretty printing a little too much at the end of my post so I probably should have made it more clear that that wasn't the focus. Instead, the important take away was actually the logging syntax for string interpolation. I didn't know that Yuescript already has a pretty printing function in its library, so I didn't mention it originally.
The thing I was talking about would be this:
foo ="bar"print"#{foo = }"
which would compile to something like this:
_pretty_0 =require("yue").p
local foo ="bar"print("foo = ".. _pretty_0(foo))
In Python, there's a useful little feature that allows writing something like the following:
which prints:
Notice how it preserved the spaces before and after the equals sign as written in the f-string.
I think this feature would be a very nice addition to Yuescript, although it may need some simplification. In Python, the code actually translates to printing the repr of
foo
, not the string conversion; an equivalent would be to writeprint("foo = " + repr(foo))
. But of course that doesn't exist in Lua. My suggestion would be to either just print the value'stostring()
, or maybe using a library function to pretty print it. While Yuescript seems to generally prefer inlining things to prevent being dependent on any libraries, I believe it would be fine here, because this is a pure development/debugging feature, so it's pretty safe to expect someone to have Yuescript installed if their code makes use of it.The text was updated successfully, but these errors were encountered: