What does it mean to both append and prepend a value to a variable? #8523
-
Per the fish shell documentation:
In quotidian English, append means to add, and prepend means to add at the beginning. Clearly, these meanings don't apply to fish (or to computers in general?), for it's redundant to say that we can both add x to y while also adding x to the beginning of y. If we can do the latter, then we can do the former. That is to say, by doing the latter, we do the former. If it's senseless to say that I am both running a race from the starting line and also running a race, then it's senseless to say that I am both prepending some data and also appending that data. So, what do these terms mean to fish (or in the world of software development)? What are the implications for doing one over the other? And what does it mean to explicitly do both? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This question can be deleted. I know the answer now. And the question is useless since it arises from my own confusion. |
Beta Was this translation helpful? Give feedback.
-
The simplest way to figure this out is to just try it: > set foo middle
> set --append --prepend foo 1 2 3
> echo $foo
1 2 3 middle 1 2 3 So it simply takes the values it is supposed to add, adds them to the beginning and adds the same values, in the same order, to the end. This is equivalent to set foo 1 2 3 $foo 1 2 3 Is this super useful? Probably not. But there was no real reason to forbid it, it's consistent, so it's allowed. I prefer to answer the question instead of letting it stay around or deleting it - https://xkcd.com/979/. |
Beta Was this translation helpful? Give feedback.
The simplest way to figure this out is to just try it:
So it simply takes the values it is supposed to add, adds them to the beginning and adds the same values, in the same order, to the end.
This is equivalent to
Is this super useful? Probably not. But there was no real reason to forbid it, it's consistent, so it's allowed.
I prefer to answer the question instead of letting it stay around or deleting it - https://xkcd.com/979/.