abs
abs copied to clipboard
echo() always prints new line
We have 2 choices:
- introduce a new print function that doesn't print new lines
- change echo, and never print a new lin by default
I'm leaning towards a print fn.
Since ABS is in some sense "a better Bash", how about adding a flag to echo
instead?
echo(str[, suppress_newlines?])
where suppress_newlines?
is treated as a boolean.
We already have n args to echo eg. echo("%s %s", "hi", "mark")
so this would be hard to support
Ah, missed that, still mulling over improvements to https://www.abs-lang.org/types/function.
I still stand by my recommendation, and further recommend that the printf
-like functionality in echo()
:
⧐ echo ("Hello %d", 5.0)
Hello %!d(string=5)
be carved out into a separate fmt()
function, which can be expanded to full printf
functionality for maximum utility:
s = fmt("Hello %d times, %s", 6, "world")
echo(s) # print with newline
echo (s, true) # print without newline
hey @gryffyn, sorry for missing this one out! :open_mouth:
I think a completely separate function is a bit annoying, I could be open to maybe having a default named argument such as
echo("%string", "s", newline=false)
. What do you think?
Can you elaborate on why adding another function is annoying? Imo a named argument is not the best option. I think something like
echo()
echoln()
Might be a good option.
Another options is thatecho()
does not print a new line by default and the user must add \n
to the end of the string.
What do you think?
I'm aligned with your other option, but I'm skeptical that we should have a different function as I don't think it's a good DX. The problem with not printing new lines by default is that it would have to be a major release...
python has print(end="")
I feel like most people are expecting a new line, especially with a command that shares the same name in BASH. It would be good to have the same default behavior I would think...
would something like this be possible?
echo(".") # ".\n"
echo(".".fmt()) # "."
I guess everything is string type so maybe this wouldn't really be possible to differentiate within the echo function.....
it should probably be a separate function if ABS doesn't have keyword arguments
If the parameter is one, a newline is automatically appended. If the parameter is more than one, no newline is added by default.
echo("foo") # `foo\n` // a newline
echo("%s".fmt("foo")) # `foo\n` // a newline
echo("%s", "%s".fmt("foo")) # `foo` // no newline
echo("%s", "foo") # `foo` // no newline