abs icon indicating copy to clipboard operation
abs copied to clipboard

echo() always prints new line

Open odino opened this issue 4 years ago • 7 comments

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.

odino avatar May 24 '20 15:05 odino

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.

gromgit avatar Jul 29 '20 03:07 gromgit

We already have n args to echo eg. echo("%s %s", "hi", "mark") so this would be hard to support

odino avatar Aug 05 '20 19:08 odino

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

gromgit avatar Aug 06 '20 05:08 gromgit

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?

Bad3r avatar Apr 21 '21 19:04 Bad3r

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...

odino avatar Apr 28 '21 20:04 odino

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

chapmanjacobd avatar Nov 27 '21 06:11 chapmanjacobd

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

s5unty avatar Dec 18 '21 15:12 s5unty