From ad835e095a806c0504dd1ca53611f08c21687876 Mon Sep 17 00:00:00 2001 From: Michael Bleuez Date: Sun, 6 Feb 2022 16:16:43 +0100 Subject: [PATCH] F# support --- CHANGELOG.md | 3 +++ README.md | 1 + doc/FSharp_Original.md | 60 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1f29fa6..99d00b05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v1.2.1 +- F# support + ## v1.2 - Live mode (a @ChristianChiarulli idea and partial realisation) - Lower ressources usage for REPL interpreters diff --git a/README.md b/README.md index 3028da05..ce1a8eb7 100755 --- a/README.md +++ b/README.md @@ -431,6 +431,7 @@ println!("-> {}", alphabet); | C++ | Import | No | | Coffeescript | Bloc | No | | D | Bloc | No | +| F# | Bloc | No, but _could_ \*\* | | Go | Bloc | No | | Haskell | Line | No | | Java | Bloc | No | diff --git a/doc/FSharp_Original.md b/doc/FSharp_Original.md index 4bdc7d06..37592088 100644 --- a/doc/FSharp_Original.md +++ b/doc/FSharp_Original.md @@ -1 +1,61 @@ # This interpreter relies on dotnet fsi being available and on your path + + +The default interpreter command is `dotnet fsi --nologo` but it can be changed via the configuration key + + +``` +require'sniprun'.setup({ + interpreter_options = { + FSharp_fifo = { + interpreter = "...." + } + } + } +}) +``` + + +### REPL (would solve slowness issues) + +For now, REPL is broken due to dotnet fsi being capricious about its stdin. + +I'll explain rapidly how sniprun implement a REPL interpreter around named pipes (FIFOs). + +The first time a fifo-based interpreter receive a run command, it forks to the background and executes `ressources/init_repl.sh`. +There is a lot of thing in that script but to replicate, you just have to: + + + +- `mkfifo pipe_in` + +- create a launcher script: + +```bash +#!/bin/bash +/bin/cat pipe_in | dotnet fsi + +# or replace 'dotnet fsi' by whatever you cant to try +``` + +- launch it in the background: `bash ./launcher.sh &`, (or `bash ./launcher.sh > out.txt & ` to redirect stdout to out.txt like sniprun does) + +- ensure the pipe will stay open: `sleep 3600 > pipe_in &` (cat, exec 3> variations will also work) + +- `echo "printfn \" hey \" " > pipe_in` or `cat hello_world.fsx > pipe_in` + +- normally, the result should be printed in the terminal that ran the launcher, or in the out file. + + + + +#### The issue: + +right now, dotnet fsi looks like it's blocked by the first sleep > pipe_in... but something **has** to keep the pipe open or when it closes, the fsi REPL reading from that will exit. + +I suspect the thing has something to do with interactive mode. + +For example, `python` has a similar problem, but `python -i ` (forced interactive mode, even if no terminal is detected because it runs in the background / its stdin was hijacked) works fine in the above example. + +If you find something to replace dotnet fsi with, that exhibits the same correct behavior as `python -i`, sniprun REPL mode _should_ work. +