futhark icon indicating copy to clipboard operation
futhark copied to clipboard

Make it possible to run program from stdin or args

Open Munksgaard opened this issue 4 years ago • 4 comments

In python, you can write python -c 'print(42)' to start an interpreter on the input. Similarly, it would be nice to be able to write futhark run -c 'iota 42' or echo "iota 42" | futhark run - to run the interpreter on some simple input.

Munksgaard avatar Jul 21 '21 07:07 Munksgaard

This should be pretty easy - I'd look at the implementation of futhark repl to see how to type-check and run arbitrary expressions.

athas avatar Jul 22 '21 07:07 athas

Actually, upon further consideration, we should probably not allow the echo "iota 42" | futhark run - form, since standard input is usually used for input to the program being run.

Munksgaard avatar Jul 22 '21 09:07 Munksgaard

Yes. Also, using - for stdin is a relic of (never-existent?) primordial times; we have a word for stdin: /dev/stdin.

athas avatar Jul 22 '21 10:07 athas

But anyway, just -c exp is what we should support (too bad -e is already taken for something else).

athas avatar Jul 22 '21 10:07 athas

[from chat on gitter] since futhark run completely changes behaviour when -c is provided, futhark eval is a possible subcommand this functionality can come under.

razetime avatar Jan 09 '23 01:01 razetime

For this hypothetical futhark eval, I suggest that it optionally takes a file to load before evaluating expressions, and then any number of expressions. Usage examples:

$ futhark eval '2+2'
4
$ futhark eval '2+2' '1+1'
4
2
$ futhark eval -f foo.fut 'some_function_from_foo 2'
1.41421356237

I don't like that futhark eval differs from futhark run and futhark eval (and pretty much every other command) in taking the file as a named option instead of a positional one. Perhaps the file should be positional and the expressions passed as options?

athas avatar Jan 09 '23 06:01 athas

Would it make sense to have a --backend argument to futhark eval?

Munksgaard avatar Jan 09 '23 08:01 Munksgaard

I don't like that futhark eval differs from futhark run and futhark eval (and pretty much every other command) in taking the file as a named option instead of a positional one. Perhaps the file should be positional and the expressions passed as options?

I think in this case it is reasonable enough to take the file as a named option. Surely, passing expressions is the norm, while passing files is the exception?

Munksgaard avatar Jan 09 '23 08:01 Munksgaard

Would it make sense to have a --backend argument to futhark eval?

It uses the interpreter.

Surely, passing expressions is the norm, while passing files is the exception?

Is the norm to use exclusively the builtin prelude? I don't know.

athas avatar Jan 09 '23 09:01 athas

Is the norm to use exclusively the builtin prelude? I don't know.

I'm thinking with respect to futhark eval. The purpose of that function is the take an expression as an argument and evaluate it, right? Then it would seem weird to hide the passing of that expression behind a flag, I think?

Munksgaard avatar Jan 09 '23 09:01 Munksgaard

which flags should futhark eval support?

I am currently assuming it takes arguments of form futhark eval options... <exprs...>. I suggest:

  • --no-warnings, same as futhark run's option
  • --load, load a file before executing the expressions

razetime avatar Jan 12 '23 17:01 razetime

I would prefer --file instead of --load, mostly because the short option can then be -f.

athas avatar Jan 12 '23 17:01 athas