Closed lontivero closed 2 years ago
I created an executable script called fsx
:
dotnet fsi --exec "$@"
And I have added it to the PATH. This works because panda adds then the .fsx
extension to the file. But it feels somehow wrong to me.
I guess this is due to an old Microsoft convention to define the file type according to its file extension. On Unix/Linux, the file type is given by the file content which is way simpler.
Panda has a very bad heuristic to guess the appropriate extension that may only work for cmd.exe
(the extension is the name of the interpretor without its extension (cmd.exe
-> .cmd
).
I can change this "heuristic" by an easier one. For diagrams, the image extension can be explicitly given in the command (e.g. %o.png
).
Then it would be possible to write {.fsx cmd="dotnet fsi %s.fsi" }
(%s.fsi
would be the name of a temporary file with the extension .fsi
).
Yes! I like that idea. FTR: F# inherited these conventions from OCaml so, this time is not MS.
Update: ocaml scripts work okay regardless of the extension so, it is MS
I pushed a small update with explicit extension in the command line and a few predefined extensions.
{cmd=python}
is equivalent to {cmd="python %s"}
and {cmd="python %s.py"}
Some extensions are predefined too for Python, Lua, shell scripts, cmd for Windows and F#.
I.e. {cmd="dotnet fsi"}
is equivalent to {cmd="dotnet fsi %s"}
and {cmd="dotnet fsi %s.fs"}
.
Tested. Just a clarification: the extension for f# scripts is .fsx
(.fs
is also a f# extension but for files that are part of a project) so, i think it would be better to change. Anyway, this is much better now and this works excellently:
```{.fsx icmd="dotnet fsi --exec %s.fsx" } open System Console.WriteLine("Thank you @CDSoft!"); ```
Ok, I'll fix the .fsx extension.
For some absurd/historical reason the F# interactive console for scripts requires the name of the script files to end the extension .fsx. That means that something that should work perfectly well like this:
Simply doesn't work. Instead I get the following error:
I don't see any obvious way to make panda to save the script with a given extension.
Just to prove the problem is the script file extension, if I hardcode th extension
.fsx
in therun_script
function as follow:It works: