-
Notifications
You must be signed in to change notification settings - Fork 1.2k
-init is now taken into account when -e is used #14190
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
base: trunk
Are you sure you want to change the base?
Conversation
This also fixes |
What happens with
You could have a first commit that just move the code around, and then a commit for the change. Note: I notice that |
Another issue I have not been able to untangle this afternoon is that |
The above also means that |
This is because the arguments after the file are expected to be the ones given to the script you're calling:
However, annoyingly it isn't very well documented either. The man page only shows the following syntax:
I think it should probably be something like
similar to the syntax from the |
I pushed a commit that makes it so initialisation file lookup is disabled on scripts (including -stdin and -e). Passing -init still works in that commit. And another commit that introduces -yesinit that allows to still lookup initialization files even when running scripts. |
My intuition is that the semantics of Regardless, the name doesn't work - the opposite of "no" is not "yes" here (the opposite of the instruction "process no init files" is not "process yes init files", if you see what I mean). Not sure what it ought to be, but perhaps something more like |
This is not the main thing this PR aims to solve. I included it for the sake of completeness, but I'm happy to remove it.
I am aware, I did not find anything better, and I thought it was understandable enough and at least a little funny. I thought the proper name would have been -init which is taken. -with-init is good. |
cc @dbuenzli : you have experience running script through the toplevel, and may have valuable feedback on the desirable semantics with respect to initialization files. |
When you run scripts you generally want to be able to invoke it regardless of your
It is mostly what
|
Do we have some sort of consensus that this can be merged when @dbuenzli suggestion include more stuff, but that can be in another PR |
For me, yes - in removing |
5580908
to
bd210a7
Compare
f4e9aab
to
720f3cc
Compare
I have removed -yesinit, simplified the implementation according to @dra27 's comment and rebased on trunk. |
720f3cc
to
a75c02f
Compare
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.
You could do something cute with Option.fold
(and so share the code for the ~some
case), but that's certainly not compulsory!
Tweak to the man page, but this looks ok to me - however, can it have another pair of eyes ack it, just because toplevel startup is subtle, and (possibly I/)we've broken it in the past.
toplevel/toploop.ml
Outdated
begin match !Clflags.init_file with | ||
| Some f -> | ||
if Sys.file_exists f then ignore (use_silently ppf (File f) ) | ||
else fprintf ppf "Init file not found: \"%s\".@." f |
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 fail here, not just print
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 thought this, too - but I think the current interpretation for an interactive toplevel doesn’t either?
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.
No it doesn't, I copy pasted the code from the toplevel part.
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.
yes, and it is unexpected^Wbug
inb4 https://xkcd.com/1172/
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.
It’s been that way for a long time (since it was added in 2005 in df6f81e) - at the very least, it’s a separate issue (doesn’t look to me like @damiendoligez did that by mistake, although FWIW I wouldn’t have!)
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 agree completely this should be changed, but I think it should be done in another PR so that this one changes less things and is easier to merge. I will factor the code so that this line appears only once and make a PR that changes it.
Co-authored-by: David Allsopp <[email protected]>
Co-authored-by: David Allsopp <[email protected]>
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.
LGTM (suggestion depends on how much one likes using Option
functions - the other could be shortened if we had CCOption.or_lazy
...)
Co-authored-by: David Allsopp <[email protected]>
Right now, with init.ml
Running ocaml -init init.ml works; it launches a toplevel where print_endline a works as expected.
However running
ocaml -init init.ml -e "print_endline a;;"
giveUnbound value a
.And
ocaml -init doesnotexist.ml -e "print_endline a;;"
also givesUnbound value a
and no other error.This PR fixes that behaviour by reading the init argument before running a script.
It is a one line change, but code order is changed in order for the extra function to be available.