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

say vs print vs show #204

Open
trans opened this issue Apr 25, 2018 · 11 comments
Open

say vs print vs show #204

trans opened this issue Apr 25, 2018 · 11 comments

Comments

@trans
Copy link

trans commented Apr 25, 2018

Could you explain the the difference between say, print and show?

@Camto
Copy link

Camto commented Apr 25, 2018

say outputs a string with a newline appended. print doesn't add a newline. show takes something and returns it as a string without outputting it.

@trans
Copy link
Author

trans commented Apr 25, 2018

Thanks. show confused me. The name doesn't seem very intuitive -- I was expecting it would output something.

@sullyj3
Copy link

sullyj3 commented Apr 25, 2018

The name "show" is probably derived from Haskell, where it has the same functionality of just returning a string representation.

@evincarofautumn
Copy link
Owner

Yeah, show was borrowed from Haskell. (Incidentally, say is from Perl.) If anyone has other name ideas, I’m open to suggestions. This area isn’t very thought out.

Ideally I think show should be split into two traits: one for debug output (show, debug, repr, ugly?), and one (or more) for pretty-printing (pretty, human, show?), which is meant for producing nice human-readable output in a user interface. The debug trait should be derived automatically, produce a valid Kitten expression, show the full structure of a value, and have an inverse trait (read, parse?) for debug input. The pretty-printing trait might return plain text, or some other value representing a graphical structure that can be rendered in a terminal (for the interactive mode) or otherwise (hypothetically, something like Jupyter/IPython notebooks).

@brendanzab
Copy link

Rust has fmt::Debug and fmt::Display if you're looking for prior art. I'd probably recommend print and println for printing without/with newlines.

@brendanzab
Copy link

ugly is kinda cute though!

@trans
Copy link
Author

trans commented Apr 26, 2018

ln could just be a separate word for sending a newline to standard out. Then print ln is equivalent to say (and println in other languages). Also has the advantage of simplifying "" say just to print a newline.

If show is to get a canonical string representation, how does that generally fit into type representation conversion in general. eg, how does one take a string and turn it into an integer? Almost seems like an operator makes sense, ~> String, or something.

Maybe log for debug trait?

For pretty-print trait, maybe pp like in Ruby.

@sullyj3
Copy link

sullyj3 commented Apr 27, 2018

That's very cute.

@evincarofautumn
Copy link
Owner

The trouble with display is the same as with show: it sounds like it outputs something. Maybe something nominal rather than verbal like str or text would be better.

I don’t think there should be a general trait for “converting” things beyond casting (thoughts: #181), since different applications have different expectations for conversions.

I really like the compositionality of print ln and log ln, but while both ln and log are great names, sadly they conflict with logarithms—yeah, less commonly used, but also more fundamental in a way. Of course the alternative would be to toss them in a math vocab.

There is newline already for just printing a newline, which was a compromise between “there should be a word for that” and “CR (from Forth) is too short, and not all newlines are represented by carriage returns”. Also line is probably too common as an identifier, especially in beginner programs.

I do like ugly vs. pretty. Kitten’s aesthetic is definitely cute-biased, so I’m seriously considering this.

@trans
Copy link
Author

trans commented May 20, 2018

Had a thought about this. Perhaps a bad one, but nonetheless it is an idea. Instead of ln use a pseudo-symbol <-', alternately one can use the Unicode symbol .

@sts-q
Copy link

sts-q commented May 20, 2018

Personaly i am using "lf" since quite a lot of years.

It works in OCaml:
print_name name = lf(); print "name: "; print name; lf();;

Better in lisp/scheme:
(define print-name( name ) (lf) (display "name: ") (display name) (lf))

And best in concatenative style:
print-name {name -- } "name: " lf print print lf

lf does print ascii character lf or linefeed, which is chr 10 / 0a.

Best Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants