-
-
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
[osh] Return the placeholder type for ${a@a}
and ${a[0]@A}
#2208
Conversation
OK I played with the tests, and this change is good, since it makes OSH more compatible However I am confused by the word "string placeholder". Is that word used in bash? I have not heard of it I think we should mention this in the |
I guess I am sorta confused by these definitions, even though I can see this change makes OSH more compatible
I guess the second definition is OK -- necessarily I guess it is repeating the implementation of bash ! the "string placeholder" I think could use more clarification |
No, I'm sorry that I confused you. I invented that word just to explain the idea. I chose that word because I didn't know how to describe it in other words. Anyway, the word "string placeholder" is only used in the above description and unused in the actual changes of this PR.
Do you have a better suggestion for describing "string placeholder"? I wanted to say "a scalar variable" or "an array element" that holds a string. If we use "variable placeholder" or "variable cell", it means the scalar variable or an entire array, so they do not seem to suit the current situation well to me. edit: I might try to describe it without using any specific words. Let me think. |
Ah OK, maybe we can just define some arbitrary terms, like
And then the variable can be We could also call it "ff_value" to be more distinct or something, or "z-value" if you want to be more arbitrary IMO there is no real logic to this other than bash's implementation ... it is not necessarily intuitive But we have to describe it, so it is useful to make up some terms |
The oils reference could also say something like: "The behavior of ${!ref} when combined with operations like ${x@a} is designed to be compatible with bash. These definitions are useful to trace the evaluation:
We don't have to explain the whole algorithm, but giving hints can be useful I find it useful to document things for myself to remember later! And doing it outside the code encourages a fresh look at it |
I added a version of doc, which doesn't use specific words, in commit 13491ca. I'll think about f-value, o-value, or something. To me, they seem similar to the |
OK the docs look pretty good I would say the main thing is to come up with a name for If it doesn't have a clear meaning, then I think a more arbitrary term like "f-value" or "z-value" is better Although the docs do mention "obtained value" -- I think that is not quite clear -- what it is obtained from? The way I think of it, there are many rules for evaluation, and you get a sequence of values along the way e.g. if you evaluate Similarly with |
bc908c3 I decided to call it h-value (holder) and r-value (result) since "holder" fits my feeling about the concept well. I chose r-value because the concept is similar to rvalue in C++, though our r-value stands for resulting value while C++ rvalue comes from the right-hand side. |
bc908c3
to
a17ddcf
Compare
Hm I tried to rewrite the doc as a table, because I made this thing https://oils.pub/release/0.25.0/doc/ul-table.html But I ran into this difference when testing it:
Should we make it consistent? Also please look at f84a65d and check if it matches your intention I think we might only need "h value" -- I am not sure we need "r value". The "r value" You can see the rendered doc in: https://op.oilshell.org/uuu/github-jobs/8820/ ovm-tarball -> Docs -> Oils reference -> doc/ref/chap-word-lang.html |
Also it occurs to me that maybe "h-value" is just "the container that held the value" ? i.e. we are giving the flag |
Also this is the quickest way to preview the doc
It's a little annoying, you have to remember to pass We could improve that RENDERED |
I guess my table is also leaving out this difference:
I am not sure if the "h-value" is precisely defined enough to capture that Sometimes the only way to describe bash is to enumerate what it does in EVERY case! But bash itself may not do that ... |
Also I am OK if we don't fix this until later -- we could add a FAILING spec test, that is OK. I often do that to "make a note for later" I don't want to get too distracted from SparseArray, if this is not necessary for that work I guess just check if the table form of the doc seems acceptable |
This is exactly the one that the next PR(b) fixes.
I've checked it. I think it matches my intention. |
Yes, if that explanation works fine for you. I tried to clarify which container it represents because you pointed out that there are multiple processes in the evaluation of |
I believe yes, because ${!ref[@]} is evaluated in this way: 1) first |
As I've written, these are going to be fixed in PR(b) (the next PR). I now rebased it on top of this PR and confirmed that the OSH behavior becomes consistent with Bash after PR(b): $ bin/osh -c 'arr=(1 2 3); ref=arr[@]; echo ${!ref@a}'
a a a
$ bin/osh -c 'arr=(1 2 3); ref=arr; echo ${!ref[@]@a}'
a
$ |
Co-authored-by: Koichi Murase <[email protected]>
OK great, thanks! |
This corresponds to "PR(c)" explained in #2201. I'll submit the changes for PR(b) after settling this change.
I noticed that the behavior for
${a[0]@a}
is different from Bash:a
andA
are used to mark the nature of a string placeholder (i.e., either a scalar variable or an array element), so${a[0]@a}
generatesa
andA
for indexed and associative arrays, respectively.a
andA
are used to mark the type of an obtained value (e.g., an empty string for a scalar variables, anda
orA
for word lists originating from indexed and associative arrays), so${a[0]@a}
generates a empty string becausea[0]
is not an entire array.I think the existing code comments in the osh codebase imply that the difference is intentional. Nevertheless, I think the function of
@a
should be the same as Bash. Maybe one wants to have a way to get the type of the obtained value, but I think that should be implemented as a distinct operator.