-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
[arith] Support empty arith. #725
Conversation
Hm does any program need I'm also confused about I suppose it's equivalent to |
I think this falls under the common subset principle: https://github.com/oilshell/oil/wiki/Language-Design-Principles If there is a trivial rewrite (that may improve your program), it may be OK to disagree with other shells. Generally speaking I think existing shells accept too much code without failing. (That's why there are many |
Thank you for comments! I don't think people will directly write something like let() { eval "(($*))"; }
## @fn process [param]
process() { let "$1"; }
process Or, ## @fn func [extra_count]
func() {
local -a extra_words=(1 2 3 4)
eval "joined=\"abc\${extra_words[*]::$1}\""
}
func I encountered a similar (but not exactly the same) case while testing Another thing is that it may be more consistent with the treatment of empty variables in arithmetic expressions. The empty variables will be evaluated as 0 in arithmetic expressions. $ osh -c 'var=; echo $((var))'
0
$ osh -c 'var=; echo $(($var))'
0
$ osh -c 'shopt -s eval_unsafe_arith; var=; echo $(($var))'
0 But I can understand this is too permissive in the view point of the language design. That is the reason that I wrote the following sentence in the first post.
Maybe we can support it under |
I added |
Hm I'd rather wait until we have evidence that people need it. It sounds like you don't need it right now. This is similar to the (BTW in general I'm interested in what the next thing is to make some tests pass in ble.sh. I guess you hit the FUNCNAME bug while testing? And I still want to add basic coverage support so we can see how many lines are hit when tests pass. If we can get 100 or 1000 lines passing that will be nice.) But I think the rewrites to avoid empty arithmetic are always improvements. Keep in mind that you wrote one of the biggest shell programs in the world, so your knowledge of bash far exceeds the average user. Oil is supposed to be for the average user, not the most sophisticated user! :-) I'm also trying to keep the code small, which is why I count lines on every release. And We're trying to avoid more global options too: https://github.com/oilshell/oil/wiki/Language-Design-Principles |
OK! Thank you! |
57b464e
to
2c1b487
Compare
The the missing length is interpreted as zero. Even though - It appears undocumented - zsh doesn't agree This came up on PR #725 a few years ago, for ble.sh Discussion: https://oilshell.zulipchat.com/#narrow/stream/121540-oil-discuss/topic/.24.7Barr.5B.40.5D.3A.3A.7D.20in.20bash.20-.20is.20it.20documented.3F
The the missing length is interpreted as zero. Even though - It appears undocumented - zsh doesn't agree This came up on PR #725 a few years ago, for ble.sh Discussion: https://oilshell.zulipchat.com/#narrow/stream/121540-oil-discuss/topic/.24.7Barr.5B.40.5D.3A.3A.7D.20in.20bash.20-.20is.20it.20documented.3F
This fixes the following problem.
${arr[@]::}
"Actually this was a N-I feature rather than a bug. It is related to an empty string in arithmetic context. I'm not sure if Oil should support this by default or not, but this is a patch to support empty strings in arithmetic context.
In this implementation, I derived a class
ArithParser
fromTdopParser
to add a special rule for empty arithmetic expressions.