Open trans opened 6 years ago
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.
Thanks. show
confused me. The name doesn't seem very intuitive -- I was expecting it would output something.
The name "show" is probably derived from Haskell, where it has the same functionality of just returning a string representation.
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).
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.
ugly
is kinda cute though!
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.
That's very cute.
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.
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 ↵
.
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
Could you explain the the difference between
say
,print
andshow
?