Open leonardschneider opened 2 years ago
I don't think an attribute is the right way to do this. What about a :string
command that prints the result of the expression as a string literal (if it has an appropriate type)?
That could probably also be useful in futhark literate.
Yeah, now that I think about it, maybe a general :format
command that accepts a printf
-style format string would be better. The same machinery could be used for futhark literate
.
You're right. I've played with a prototype and a command makes more sense.
Instead of printf
style, I think the most elegant option would be something similar to Pythons formatted string literals. They are similar to printf
strings, but instead of being positional, you put the name (or eventually, expression) of what you want to print:
> let str = "foo"
> :print "as array: {str}"
as array: [102u8, 111u8, 111u8]
> :print "as string: {str:s}"
as string: foo
With no specifier it will print in the default manner for the type, but with a specifier we can force e.g. arrays to be interpreted as UTF-8 strings.
I like the Futhark repl, but I'm missing formatting while printing the values. I propose adding some basic formatting, which can come handy while debugging a program, by adding expression attributes that will be interpreted by the repl to display expressions.
Here are some examples I'd like to have.