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

echo() always prints new line #374

Open
odino opened this issue May 24, 2020 · 7 comments
Open

echo() always prints new line #374

odino opened this issue May 24, 2020 · 7 comments
Labels
bug Something isn't working
Milestone

Comments

@odino
Copy link
Collaborator

odino commented May 24, 2020

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 odino added the bug Something isn't working label May 24, 2020
@odino odino added this to the cauldron milestone May 24, 2020
@gromgit
Copy link
Contributor

gromgit commented Jul 29, 2020

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.

@odino
Copy link
Collaborator Author

odino commented Aug 5, 2020

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

@gromgit
Copy link
Contributor

gromgit commented Aug 6, 2020

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

@Bad3r
Copy link
Contributor

Bad3r commented Apr 21, 2021

hey @gryffyn, sorry for missing this one out! 😮

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?

@odino
Copy link
Collaborator Author

odino commented Apr 28, 2021

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

@chapmanjacobd
Copy link
Contributor

chapmanjacobd commented Nov 27, 2021

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

@s5unty
Copy link
Contributor

s5unty commented Dec 18, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants