I've been doing a fair number of RosettaCode tasks lately. And some of them, like this one, would be considerably easier to do if print
didn't always append a line break.
In Mini Micro, you can set text.delimiter = ""
and then print
without line breaks as much as you like. But that's a Mini Micro thing, not a standard MiniScript thing. In standard MiniScript, currently, the best you can do is build up a string or list and then print it out all at once.
Many other languages have two print functions just to deal with this issue, usually called print
and println
. But I hate that. You'd be using println
for the vast majority of cases, and that doesn't meet MiniScript standards of elegance. It's not even readily pronouncable!
Python replaced their print statement with a print function, in part so they could use named parameters, allowing optional named 'end' and 'sep' parameters you can use to control its behavior (if you can remember what these names are — I had to look them up just now). They have to be named parameters because the rest of the parameters are a variable-length list of whatever you want.
MiniScript doesn't have variable-length parameter lists, nor named parameters. We're certainly not going to add them just for this, and we may well not add them ever; those features aren't particularly Mini. But we might want to add them someday; I can't be sure that will never happen.
Ignoring that issue, the obvious solution is to add a second (optional) parameter to print, which is the delimiter to use (thing to print after). This would default to char(13), which means "line break" (whatever that is on the host platform). But you could specify null or "" to avoid the usual line break. Or specify ", " if you want to print a bunch of things separated by commas, or char(9) for a tab, or whatever.
print "Spam, ", null
print "spam, " * 3, null
print "baked beans, and spam!"
The above would all print on one line, because of the null delimiter on the first two print statements.
What do you think?