Skip to content
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

Merged
merged 6 commits into from
Dec 17, 2023
Merged

feat: implement list->indexOf() #1765

merged 6 commits into from
Dec 17, 2023

Conversation

Melkor333
Copy link
Collaborator

As discussed in Zulip :)

@andychu
Copy link
Contributor

andychu commented Dec 12, 2023

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:

https://github.com/oilshell/oil/wiki/Oil-Dev-Cheat-Sheet

@Melkor333
Copy link
Collaborator Author

Melkor333 commented Dec 13, 2023

I really need to get the dev build locally, or I'm gonna abuse the CI hard 😅
FWIW:

sam@klara:~/git/oil$ build/cpp.sh all
build/cpp.sh: line 40: all: command not found

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:

sam@klara:~/git/oil$ deps/from-tar.sh download-re2c
deps/from-tar.sh: line 90: download-re2c: command not found

Is there one "do all steps" command, or would it make sense to add one to get started a bit more easily?
AFAIU it's something like the following now:

deps/from-tar.sh configure-python
deps/from-tar.sh build-python
deps/from-tar.sh layer-cpython
...

@Melkor333
Copy link
Collaborator Author

Oh I found a comment now in build/deps.sh... Anyway some more helpful input, I think I ran every of the suggested commands and still get the following error:

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'

@andychu
Copy link
Contributor

andychu commented Dec 13, 2023

Hm sorry about the outdated commands, I fixed it to say build/py.sh all before building C++

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 !)

@andychu
Copy link
Contributor

andychu commented Dec 13, 2023

Yeah sorry this page was out-dated

https://github.com/oilshell/oil/wiki/Contributing#full-python-build-buildpysh-all

It's now

build/deps.sh fetch
build/deps.sh install-wedges

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

@Melkor333
Copy link
Collaborator Author

Melkor333 commented Dec 13, 2023

FWIW I read the travis logs to see that it was the range and try which caused the issue… I just don't like having to go a full CI-circle every time I change something.

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!

Copy link
Contributor

@andychu andychu left a 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 !!

@@ -99,6 +99,20 @@ setvar is_a_val = "xyz"
(Bool) True
## END

#### Lis->indexOf
Copy link
Contributor

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 =>

https://oilshell.zulipchat.com/#narrow/stream/384942-language-design/topic/mutation.20vs.2E.20transformation

Copy link
Collaborator Author

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!

Copy link
Collaborator Author

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

Copy link
Contributor

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

Copy link
Collaborator Author

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?

Copy link
Contributor

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?

rd.Done()
i = 0
while i < len(li):
if needle.tag() == li[i].tag() and val_ops.ExactlyEqual(li[i], needle, loc.Missing):
Copy link
Contributor

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

Copy link
Collaborator Author

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.

@andychu
Copy link
Contributor

andychu commented Dec 13, 2023

FWIW I read the travis logs to see that it was the range and try which caused the issue… I just don't like having to go a full CI-circle every time I change something.

Yes that can be an issue. So I guess I would say try the new instructions

build/deps.sh fetch; build/deps.sh install-wedges

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 /wedge which means you need root

https://github.com/oilshell/oil/wiki/Oil-Dev-Cheat-Sheet says you can rm-oils-crap -- we ONLY put stuff in /wedge and ~/wedge -- that's the idea. So those are the only two dirs you need to know about to clean it up.

I'm also interested in the C++ build as I'd like to look into packaging at some point. :)

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

should I squash the commits into one commit?

No I squash on merge!

Oh and thanks a lot for updating the docs right away!

I should have done that quite awhile ago !! Someone else ran into this :-( Too many docs to juggle!

@Melkor333
Copy link
Collaborator Author

damn i just saw that my commit messages are wrong and squashed anyway :-|

Copy link
Contributor

@andychu andychu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good!

@@ -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):
Copy link
Contributor

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

Copy link
Collaborator Author

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!

Copy link
Collaborator Author

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?

### find()
### indexOf()

Returns -1 if element is not in the index.
Copy link
Contributor

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

Copy link
Collaborator Author

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 :)

@andychu andychu changed the base branch from master to soil-staging December 17, 2023 15:47
@andychu andychu merged commit 092479b into soil-staging Dec 17, 2023
17 checks passed
@andychu
Copy link
Contributor

andychu commented Dec 17, 2023

Great thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants