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

wish: -str option for ocaml #5232

Closed
vicuna opened this issue Feb 26, 2011 · 15 comments
Closed

wish: -str option for ocaml #5232

vicuna opened this issue Feb 26, 2011 · 15 comments

Comments

@vicuna
Copy link

vicuna commented Feb 26, 2011

Original bug ID: 5232
Reporter: @ygrek
Status: confirmed (set by @gasche on 2013-07-29T05:15:41Z)
Resolution: open
Priority: normal
Severity: feature
Version: 3.12.0
Category: toplevel
Tags: junior_job
Has duplicate: #6631
Related to: #2757 #6071
Monitored by: @gasche @ygrek

Bug description

Sometimes it is useful to be able to run simple oneliner ocaml code without writing the code previously to file. Option -str analoguos to one of camlp4 is wanted.

@vicuna
Copy link
Author

vicuna commented Jul 28, 2013

Comment author: @gasche

I think that this feature doesn't really work:

  • the compilers (ocamlc and ocamlopt) need the filename to be used as a compilation unit name, so simply passing code in -str wouldn't work (except if this is only intended for parsing/typing with option -i?)
  • the toplevel already makes it easy to work with short pieces of code (in particular cat "foo;;" | ocaml), so I'm not sure an -str option to ocaml would make much sense.

ygrek, could you be more specific on the use-cases and semantics you had in mind?

@vicuna
Copy link
Author

vicuna commented Jul 29, 2013

Comment author: @ygrek

yes, this was intended exactly as a shorthand for toplevel, but with the following implied features : be usable as script runner, i.e. no extra toplevel output (prompts and types), stdin available for input (with toplevel it results in End_of_file), no reading of ocamlinit (not sure about this one). The intended use-case - running some automated utility tasks (inside project directory) where the actual code is available in a cma or ml file and one-liner is needed to actually call it or run with specific parameters.

@vicuna
Copy link
Author

vicuna commented Jul 29, 2013

Comment author: @gasche

Thanks for the additional information. That seems reasonable. I think it's also reasonable to not run the .ocamlinit, because the "-stdin" option already doesn't do that. In fact I suspect they should both read .ocamlinit, and have a -noinit option (can be obtained as -init /dev/null right now), but that's question that can be handled independently (in fact it is an existing PR: #6071).

@vicuna
Copy link
Author

vicuna commented Oct 29, 2014

Comment author: kyoDralliam

Seems related to #6631

@vicuna
Copy link
Author

vicuna commented Oct 31, 2014

Comment author: @gasche

Indeed; kyoDralliam, could you repost your patch here, using -str rather than -e?

PS: in case the patch is merged, the name you use in your .patch would be used as attribution information.

@vicuna
Copy link
Author

vicuna commented Dec 13, 2016

Comment author: @mshinwell

@gasche Could you take care of these two issues?

@vicuna
Copy link
Author

vicuna commented Mar 3, 2017

Comment author: @gasche

The patch is not good enough (for example it creates a temporary file but never deletes it, littering the user's filesystem with useless source files) and I had no feedback/return from the contributor. I can't spend time making a better patch right now, so as far as I am concerned the feature request is still standing, and any user's contribution is welcome.

@isaacv-pl
Copy link

isaacv-pl commented Mar 20, 2020

Hi, I think I'm gonna work on this for my first contribution. Where in the toplevel folder would I find what I need to edit to support this option? Also an example of some usage behavior would be nice to clarify what I would need to do. Thanks! Sorry for all the questions.

@github-actions
Copy link

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@github-actions github-actions bot added the Stale label Apr 26, 2021
@gasche gasche removed the Stale label Apr 26, 2021
@gasche
Copy link
Member

gasche commented Apr 26, 2021

@notemaster sorry for not answering this. Here would be an usage example:

# the following currently works
$ echo 'print_endline "Hello World";;' | ocaml -stdin
Hello World

# the following would requires this feature
$ ocaml -str 'print_endline "Hello World";;'
Hello World

@Zett98
Copy link
Contributor

Zett98 commented May 6, 2021

can i pick up this issue?

@dbuenzli
Copy link
Contributor

dbuenzli commented May 6, 2021

Language interpreters usually use -c (e.g. sh, python) or -e (e.g. perl) for that option. Could we maybe use that aswell ?

I can see ocaml -c as being confusing for ocamlc users, but ocaml -e looks fine no ?

@Zett98
Copy link
Contributor

Zett98 commented May 7, 2021

maybe -e, --eval ?

@gasche
Copy link
Member

gasche commented May 7, 2021

I agree that -e is fine.

@Octachron
Copy link
Member

Fixed by #10438 .

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

No branches or pull requests

6 participants