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
FIX: Correctly handle the case in Proc args binding when both typed positional varargs and block arg are present #1894
base: master
Are you sure you want to change the base?
Conversation
…ositional varargs and block arg are present
OK cool, the tests ran! http://travis-ci.oilshell.org/github-jobs/6593/ There are some failures, let me look at it a bit later I can help interpret Thanks for the PR! |
I added a new spec test in spec/ysh-proc.test.sh but I'm not sure how should I inspect the information from a block. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this ! This looks very promising
I need to clone the branch and look at the before/after a little, but here are a couple comments
for i, k, v in (c) { | ||
echo "$i - $k - $v" | ||
} | ||
# TODO : figure out how to inspect blocks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have pp line (x)
, which is meant to print value x
in a deterministic way that won't change, specifically for spec tests (unlike the =
operator)
$ pp line (^(echo hi))
(Command) <Command 0x7f39428c1870>
Although maybe this address 0x7 ... causes problems? That isn't stable
I guess you could use sed
to remove it for now, hmm
@@ -369,15 +351,31 @@ def _BindTyped( | |||
if rest: | |||
lval = LeftName(rest.name, rest.blame_tok) | |||
|
|||
rest_val = value.List(pos_args[num_params:]) | |||
mem.SetLocalName(lval, rest_val) | |||
rest_val = pos_args[num_params:-1] if block_param else pos_args[num_params:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm why move if block_param
after the rest
section?
Wouldn't keeping it before that simplify this condition?
else: | ||
if num_args > num_params: | ||
if num_args > num_params + (1 if block_param else 0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise can we remove if block_param
by handling it first?
I might have missed something
OK I played with it a bit more ... I do see the problem, and I see the logic behind your fix - thank you I wonder if there are any other problems here, let me see I guess I'm thinking about the larger issue
I think my logic was:
looks nicer than
But isn't that just cosmetic? Why shouldn't it be
? Is that more consistent and easier to remember for users? |
Also I'm thinking about our docs: https://www.oilshell.org/release/0.21.0/doc/proc-func.html
Clearly I did not think this through! I think the design is a little weird |
I think this came about in unifying
But yeah now I wonder if it should be
for consistency. I don't think this occurs much in real code. It's only for testing and metaprogramming and so forth. There are also builtins like Another option is to change the signature ??? We could try to make it so there are 3 sections, not 4
Hm |
It does still make sense, just that logically the block is the last passed typed arg rather than the first. That's why I need to switch the binding order. Block & typed positional args are still unified and code like this works:
|
I don't really understand the |
So
which is like Python's
We only have a single operator I think the argument for How do you wrap any proc?Suppose you have:
How do you wrap it, like Python's I think you need
This is more consistent than:
@bar-g ran into this bug, and may have opinions He wanted I think I think it's nice because the signature matches the call site Thoughts? |
I am not sure of the exact fallout of changing it, but I would like a PR that does Thanks for doing this -- it's very helpful in clarifying our design |
I think it makes sense to have different treatment for different cases
This PR doesn't conflict with those so it's no harm to merge them. |
sorry, only found this now, will take a day or two to answer |
I am going to write something about this. I think we want to make call site and def site consistent and we have two options in that case
OR
Either of these consistent. But neither the OLD behavior or this NEW behavior is consistent. We still have a problem, even with the PR I believe that an argument for the first style is
should work consistently It shouldn't be
in other words I think that works, but it's kinda crazy !! |
Yeah I think that is the core argument
is way too complex. We are appending one element to a list, and then splatting it
is more understandable It's equivalent to
(nevermind that cd doesn't take typed args now, it's just an example) |
Sorry, different from said, I will only be able to look at this next week. |
Hm I played around with the other option -- We still have So right now I think this works -- the main reason it would change is because of one of our 16-17 use cases from the blog/Zulip. We are trying to encode many idioms in this reflective interface |
Continuation of #1893. Fixes #1892, maybe fixes #1849 .