-
-
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
feat: implement list->indexOf() #1765
Conversation
Ah OK looks like there is a type error http://travis-ci.oilshell.org/github-jobs/5588/dev-minimal.wwz/_tmp/soil/logs/oil-types.txt Fixing that may clear up these other errors - http://travis-ci.oilshell.org/github-jobs/5588/#job-dev-minimal I try to put all the commands here, including type checking, but let us know on Zulip if you have problems getting it green: |
I really need to get the dev build locally, or I'm gonna abuse the CI hard 😅
The docs at https://github.com/oilshell/oil/wiki/Oil-Dev-Cheat-Sheet#oil-native-c might need a bit of an update Edit: also from https://github.com/oilshell/oil/wiki/Contributing#full-python-build-buildpysh-all:
Is there one "do all steps" command, or would it make sense to add one to get started a bit more easily?
|
Oh I found a comment now in sam@klara:~/git/oil$ build/py.sh all
...
CC benchmarks/time-helper.c
Traceback (most recent call last):
File "/home/sam/git/oil/bin/oils_for_unix.py", line 195, in <module>
sys.exit(main(sys.argv))
File "/home/sam/git/oil/bin/oils_for_unix.py", line 170, in main
return AppBundleMain(argv)
File "/home/sam/git/oil/bin/oils_for_unix.py", line 151, in AppBundleMain
return readlink.main(main_argv)
File "/home/sam/git/oil/tools/readlink.py", line 23, in main
if not arg.f:
AttributeError: '_Attributes' object has no attribute 'f' |
Hm sorry about the outdated commands, I fixed it to say https://github.com/oilshell/oil/wiki/Oil-Dev-Cheat-Sheet Let me fix the re2c thing too I restarted the flaky CI task and it worked (that is either Github or Dreamhost, not us !) |
Yeah sorry this page was out-dated https://github.com/oilshell/oil/wiki/Contributing#full-python-build-buildpysh-all It's now
But since the CI passes you don't necessarily need to do that. I want people to concentrate on the Python parts first Though I guess it can be annoying if you see a whole bunch of failing stuff and don't know why |
FWIW I read the travis logs to see that it was the I'm also interested in the C++ build as I'd like to look into packaging at some point. :) should I squash the commits into one commit? Oh and thanks a lot for updating the docs right away! |
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.
This looks great, thank you !!
spec/ysh-methods.test.sh
Outdated
@@ -99,6 +99,20 @@ setvar is_a_val = "xyz" | |||
(Bool) True | |||
## END | |||
|
|||
#### Lis->indexOf |
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.
typo List
I guess we should write it List => indexOf()
because it's non-mutating
I have this idea that ->
should be mutating and I/O, and =>
should be "transformations" or "accessors"
I'm interested in feedback on that
I know that it's unfamiliar, but I think Python and JS are too loose with the distinctions
This is very confusing:
mystr.strip() # does nothing, it should be mystr = mystr.strip()
mylist.sort()
So for us that would be
mystr => strip() # looks wrong because => is a transformation
setvar mystr = mystr => strip() # right way
call mylist->sort()
So you get a little hint with ->
or =>
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.
That makes total sense!
x->transform
vs x => pure_func
. it also reminds me a bit of the weird haskell chains (though IIRC this goes the other way).
So instead of a method this should become a function then. Let me see what I can do!
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.
nvm it's just syntactic sugar. I genuinly thought =>
is for differently implemented funcs
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.
Oh yes it's just sugar!
So yes you don't have to change the code at all, just the tests.
I'm very happy for this feedback :) :) since it confirms my hunch
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.
but that means something like x => strip => split
would technically work but probably give an unexpected result? or is the idea to enforce one or the other at some point?
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.
x => strip() => split()
should work like you expect? what would be unexpected?
builtin/method_list.py
Outdated
rd.Done() | ||
i = 0 | ||
while i < len(li): | ||
if needle.tag() == li[i].tag() and val_ops.ExactlyEqual(li[i], needle, loc.Missing): |
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.
I'm pretty sure you don't need to check the tag, because ExactlyEqual will check it
Tests should still pass
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.
fair thing. in my tired mind that somehow should've been the replacement for the try/catch
but it doesn't make sense.
Yes that can be an issue. So I guess I would say try the new instructions
I switched to this "wedges" idea back in April, but I got stuck on root vs. non-root I wanted to make it run without root, but as it is you will get stuff in https://github.com/oilshell/oil/wiki/Oil-Dev-Cheat-Sheet says you can
The packaging should generally be done from the official tarballs. It's definitely time to start packaging it soon, though I think JSON support needs to be there for it to work
No I squash on merge!
I should have done that quite awhile ago !! Someone else ran into this :-( Too many docs to juggle! |
fb9927c
to
08f8795
Compare
damn i just saw that my commit messages are wrong and squashed anyway :-| |
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.
Changes look good!
builtin/method_list.py
Outdated
@@ -92,7 +92,7 @@ def Call(self, rd): | |||
rd.Done() | |||
i = 0 | |||
while i < len(li): | |||
if needle.tag() == li[i].tag() and val_ops.ExactlyEqual(li[i], needle, loc.Missing): | |||
if val_ops.ExactlyEqual(li[i], needle, loc.Missing): |
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.
This looks good, can you try this:
$ bin/ysh -c '= [1.0, 2.0] => indexOf(3.14)'
= [1.0, 2.0] => indexOf(3.14)
^
[ -c flag ]:1: fatal: Equality isn't defined on Float
And then try changing loc.Missing to rd.LeftParenToken()
I think it will improve the error
And perhaps add this test case to test/ysh-runtime-errors.sh
It could be in a new function at the end or some existing function
That is how we "eyeball" all the errors to make sure they are decent
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.
I was wondering which var we (currently?) can't compare for equality.
And thanks, I didn't see any other code getting a location from rd
so that's why I went with Missing
. Definitely better with a proper location!
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.
I added the error to the existing test-fat-arrow
func but maybe it's better to have an additional func test-ysh-methods
? But I guess we can change this if more methods require a testcase?
doc/ref/chap-type-method.md
Outdated
### find() | ||
### indexOf() | ||
|
||
Returns -1 if element is not in the index. |
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.
How about
"Returns the first index of the element in the List, or -1 if it's not present."
"element is not in the index" is confusing
Sorry I didn't catch this the first time around
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.
should've been "element is not in the List" but your proposal is probably a bit more clear :)
Great thank you! |
As discussed in Zulip :)