qi(1)
: Syntax
#152
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Taking some inspiration from Drew Devault’s
rc(1)
seems like an interesting way to go here as it has a lot of similar properties to what we wanted in #8.I've been asked to submit my grumblings about POSIX shell quoting to this issue. I am lacking sufficient energy to write eloquently (or at all) about this so here's an example.
Originally posted by @silt in #8 (comment)
Plan 9's rc(1) doubles quote runes to escape them:
Which I've always felt is quite nice.
The reason sh(1p)'s quotes are fucked is because not only is the backslash used to escape quotes in
"
-wrapped strings but it's also used for regular escape sequences. For example:POSIX shell quoting is abhorrent and the worst part about shell scripting by far. Escape sequences shouldn't be supported except by a theoretical format(1) (printf(1p) but Bonsai and improved).
Drew Devault's rc(1) bastardization (it is probably nice in practice) seems consistent but still as overcomplicated as shell is.
I'd like Plan 9 rc(1) quotes/escapes without a difference between
"
- and'
-wrapped strings and no escape sequences besides""
or''
, but I think this is better rather than good. I'm not sure what good would look like. Probably something to do with ASV.Originally posted by @trinity in #8 (comment)
The way POSIX shell does variable assignment is awful.
Shell variable assignment isn't consistent with most syntax and really finnicky about whitespace. I propose a better way:
set
would need to be a shell builtin to change the local environment; it would have the usageset [variables...] [value]
to facilitate setting multiple variables at the same time:POSIX shell already has a
set
builtin for modifying"$@"
and its components (as well as configuring the behavior of the shell itself); we should rethink the functionality offered by POSIXset
(reserved shell variables for configuration, for example).Originally posted by @trinity in #8 (comment)
I like this, but could we use
let
instead?Originally posted by @emma in #8 (comment)
I have further thoughts on shell quoting.
When I think of program execution I think of the
exec
function family in C's<unistd.h>
:Or
subprocess.run
in Python:Or Rust's
std::process::Command
:What these all have in common is that they have clear distinction between arguments, and if one wanted to use a variable as an argument it would be easy:
Meanwhile POSIX shell wants you to die:
No wonder people are desperate to use any interpreted programming language as a shell, asking if Python is a good fit and actually using Common Lisp. That being said, quoting every shell argument is at best inconvenient, with the example
"mm" "-i" "a b"
being 4 extra keypresses to type and up to 8 including the shift key.I think we should start by mandating some useful rules that are already often followed by cautious scribes:
I don't think this will be very controversial. While escapes are convenient (an easy way to avoid navigating back to the beginning of the line, adding a quote, and then going back to the end just for one or two spaces) they're easy to mess up catastrophically:
This also seems non-controversial. I have more to say but am out of time to write so will comment this right now.
Originally posted by @trinity in #8 (comment)
Alright, this is the continuation of my last comment.
The behavior of the traditional POSIX shell with regards to unquoted variable expansion is useful, sometimes, but usually unwanted and a pain to deal with. In Python if I wanted that behavior I'd use str.split:
The C standard library has no such helper function (the functionality offered by
str.split
could be replicated though) and Rust is as of now beyond me.Originally posted by @trinity in #8 (comment)
alright i haven't slept in a few days and have important things to be doing rn, what better idea than to propose shell syntax. this is poorly thought-out and full of holes. have fun deciphering and feel free to harass me if that takes too long
i haven't read through like any of the posts here so i might repeat or redefine things that've been discussed already
i will be using words here. maybe (read: probably) even misusing words. here's a best-effort explanation of my nonsense:
editor's note: i simplified this quite a bit, only one word remains standing. you're welcome.
emma and i were discussing variable assignment and the potential usage of a
let
term, which is used to define terms. some pseudoishcode snippets from the conversation to elucidate on that a bit:some important observations from this that i've already made on your behalf:
let
itself can be redefined. also, spaces symbols are valid.#
can be redefined.let
does this.hru
(we have anhru
?) also does this. let's call these argument-taking terms "operator terms", or maybe just "operators", and their arguments "operands".#
as an operator that takes all subsequent terms as its operands and does nothinglet
's operands, they're just terms. they may be taken literally, but they may also be operator terms.so we have operators, which operate on and consume the terms to their right. these terms may be operators themselves, but they may also just be literals. do you smell it yet? i smell it. it's the smell of polish notation. alright so what if we did polish notation in more places.
suppose there was a
pn(1)
utility, serving as the prefix version ofrpn(1)
:as the reader it is now your job to come up with a more exciting example than that bc that's as far as my thoughts are willing to go at this time of night.
there are issues with this. the main one that jumps out is that in your typical pn language, the interpreter is aware of how many terms will be consumed as operands by a given operator. however, when an operator can be an arbitrary executable, the number of terms consumed is completely ambiguous. there is a fix, which is to let the programmer define those bounds themselves:
oops. we should probably not do this.
realized that about halfway through typing out this textwall but was told to post it anyways so here ya go
Originally posted by @silt in #8 (comment)
The rest of the comments in #8 are the discussion of a system of variable expansion that does not distinguish between plaintext and variable names. This syntax has been verbally discussed by @trinity and I and we have agreed that it is ill-advised.
Some thoughts on dereferencing.
[var]
would be simple but ugly. I have the same opinion of any paired symbols for this purpose.*
, to which I'm partial, but this might interfere with user expectations for globbing.$
, which has accumulated a fair bit of precedent. I haven't made up my mind about this.%
would work?