-
Notifications
You must be signed in to change notification settings - Fork 35
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
Bash-style variable interpolation in strings #169
Comments
So What I really like are the new python 3.6 From there on it does not matter how you handle the f-string such as |
So...string formatting is fairly different between bash commands and strings because of... ...ehm... ....me :) I initially implemented strings similar to Go's string formatting, so you could do Now, I don't disdain python's f-strings at all, but having used javascript heavily I've also got fond of what JS calls template literals:
I think we could have a combination of f-strings and template literals to make interpolation easier:
But this is not possible as backticks are interpreted as system commands:
I don't think I'd be against interpolation by
What do you folks think? The only downside here is that if we change interpolation just like this we'd need a major release since this would be a breaking change. |
I think we should be careful about changing existing functionality in string interpolation and definitely avoid breaking changes. This means that we should have lexically distinct string modes that explicity provide different forms of conversion. And, yes, we have run out of quote characters, so this is why I favor the python approach to string mode modifiers such as |
I like the idea of having interpolation by default in strings. Python, JS and Scala couldn't do it because they were already too popular to break things by the time the idea came up, but I think abs is still young enough that we can afford it. But I think we should use the same syntax in both strings and shell interpolation. |
Another thing I'd like to say is, bash actually has 2 syntactic forms for variable interpolation:
This is really useful when you want to interpolate inside e.g. a word. So, if you implement |
I think we're early enough to do a BC break, and be upfront about it. Users will understand. I also like how go managed their versioning -- they had 11/12 releases of V1 and prepared for V2 in background, with features that would break BC. With this in mind I'm strongly in favour of having the same interpolation in commands as well as strings, else it'll be awkward to do My gut feeling is that we should probably simply implement simple interpolation ($var) in strings, and do a minor release (it's a feature and doesn't really break things around unless very, very, very special cases eg While we do so, we can then decide whether we'd like f strings -- I'm personally on the fence as they don't feel super immediate and I'm not aware of any other mainstream language going in this direction besides python (lmk if you have other examples). Then there's a discussion on V2, where we could simply use the js way of interpolating any kind of statement with something like I'd suggest, as Rick mentioned before, we also take advantage of the documentation, but in sort of a different way: we could warn users that using I anyhow think that having Long story short: very much on the fence :) I'm happy to hear your view. I believe I made a mistake, initially, when implementing interpolation as I should have reserved |
Since the strength of abs is seamless integration with the shell, I would second the initial proposal of having the same interpolation as in the shell, ie |
👍
…On Sat, Jul 27, 2019 at 12:44 AM kmptkp ***@***.***> wrote:
Since the strength of abs is seamless integration with the shell, I would
second the initial proposal of having the same interpolation as in the
shell, ie echo("The sum of [$ip] is a large number, $total."). This
minimises mental context switches while writing abs code, and minimising
cognitive overhead is a big win!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#169?email_source=notifications&email_token=AACQFZB6GDIUNEIMSN7QAADQBNOZ3A5CNFSM4GUYA5JKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD25VLLQ#issuecomment-515593646>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AACQFZFY74XYLW77LV2P34TQBNOZ3ANCNFSM4GUYA5JA>
.
|
Now you can embed variables inside strings by prefixing them with `$`. Literal `$` simply need a `\`. This aligns the string interpolation syntax with commands, and makes it easier to switch between running a command (`` `$some $command` ``) and echoing it (`echo("$some $command")`).
Now you can embed variables inside strings by prefixing them with `$`. Literal `$` simply need a `\`. This aligns the string interpolation syntax with commands, and makes it easier to switch between running a command (`` `$some $command` ``) and echoing it (`echo("$some $command")`).
Going to be released in 1.8. |
Abs has bash-style variable interpolation inside "shell interpolation" (i.e. inside
$()
). It would be nice if we could use that syntax in the rest of the code as well.Then things like this:
could be written as:
The text was updated successfully, but these errors were encountered: