Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expression attribute for repl display #1567

Open
leonardschneider opened this issue Jan 17, 2022 · 5 comments
Open

Add expression attribute for repl display #1567

leonardschneider opened this issue Jan 17, 2022 · 5 comments

Comments

@leonardschneider
Copy link

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.

> #[char] 97u8 -- display a character
'a'
> #[utf8] "Hello, world!" -- display a string in utf8 encoding
"Hello, world"
> #[raw] "Hello, world!" -- direct display for extensibility
Hello, world! 
@athas
Copy link
Member

athas commented Jan 19, 2022

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)?

@FluxusMagna
Copy link

That could probably also be useful in futhark literate.

@athas
Copy link
Member

athas commented Jan 20, 2022

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.

@leonardschneider
Copy link
Author

You're right. I've played with a prototype and a command makes more sense.

@athas
Copy link
Member

athas commented Jan 24, 2022

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.

dominicmkennedy added a commit to dominicmkennedy/futhark that referenced this issue Sep 16, 2023
athas pushed a commit that referenced this issue Sep 19, 2023
First draft of print command for REPL #1567
CKuke pushed a commit to CKuke/futhark-seq that referenced this issue Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants