Repository navigation
Conversation
|
I reviewed this and played with it a bit. Looks good. The only possible issue is that We also need more comprehensive unit tests for setting vars but that's probably better handled in a separate change. Thanks for adding a basic test. Finally, is this really necessary? You can get the same result today by just doing |
|
Well, this was discussed thoroughly in #565 and I was interested in this case because I had some trouble with it myself (#3323). In my opinion, the main reason to include this flag is:
Also, the example given in this comment shows how useful it can be to set function variables in a list. |
I thought the ideal solution would be to behave as a |
Yes, but the arguments near the end to add a flag seemed weak. The only thing universally agreed to in that issue is that the scoping rules should be changed and
Okay, that's at least a concrete example that shows how |
|
I understand that these arguments don't seem strong enough to you, a single use case isn't enough reason to add a flag. But I insist that the main reason for this is consistency, if a scoping rule is present somehow (in this case, only when a variable doesn't already exist in any scope) it should also be allowed to be used at will of the user (read: with a flag). |
|
@chamini2: First of all, thanks for your work. There is some weirdness in function t
set -qg PATH; and echo "PATH is global"
set -qf PATH; and echo "PATH is function-scoped"
set -ql PATH; and echo "PATH is local"
set -f foo bar
set -qf foo; and echo "foo is function-scoped"
set -ql foo; and echo "foo is local"
set -qg foo; and echo "foo is global"
endhere, $PATH is both global and function-scoped, while $foo is both local and function-scoped, at least as far as The latter might be okay - it's defined in the current block after all, but the former is just plain weird. Now, personally, I'd rather allow something like Also, I'd assume that people would make the connection more between function-scoped and local (at least I did, and I like assuming that people are like me), so it's probably less confusing if Either that or throw an error - you know if you're in a function or not. However, I think we want to encourage using "-f", so if we can make it "safe", so that people just use it when they don't need anything special, that'd be great (mkay). Erroring out means people need to think about using it, which means they won't as much - people don't like to think (see above). @krader1961: I know I've wanted this. One example is using function foo
if bar # where bar is a complicated condition that can't just be inlined later
set -f baz
end
if set -qf baz
# Yay, the test before succeeded!
else
# Oh noes, bar is closed!
end
end |
|
I think your example, @faho, is a bit contrived but I do agree, upon further reflection, that we want an explicit flag so that a) we gain some experience with how things will work if we make it the default behavior, and b) until such time as we can make it the default there is an easy way for people to get that behavior without having to remember that My testing verified that the variable had the expected value for various combinations of |
|
Ok, read your comments and I will make it so |
4f2975a to
4692b83
Compare
|
Hey, I pushed some more tests, please review them and let me know if they reflect the expected behaviour. The tests don't pass yet, but I want to make sure this is what we should get before actually working on it. |
I'm ambivalent. I agree that throwing errors is not friendly. On the other hand letting people shoot themselves in the foot is also not friendly. The I'm inclined to say that before merging this, or any similar, change we should have a discussion in the original issue that resolves all these questions (including those earlier today on Gitter). Preferably via concrete code examples that enumerate the various permutations and the expected output (which then become the basis for unit tests). |
|
Completely agree. |
|
I'm going to close this since there are fundamental questions about the behavior that need to be answered in issue #565. Thank you very much, @chamini2, for providing a concrete implementation to drive the discussion forward. But it's pretty clear that this tentative implementation won't be merged. I'm hoping we can reach consensus in issue #565 regarding the unresolved questions and you'll create a new PR that addresses them. |
Related to #565 (last comment).