Xah Talk Show 2026-01-21 Ep748 emacs lisp, write command to eval selection, fsharp, JavaScript.
Video Summary (Generated by AI, Edited by Human.)
Write an Emacs Lisp command to evaluate selected regions of code, specifically for fsharp.
- Demo JavaScript Eval Region (0:52).
- Intro the Problem: fsharp Eval Region (4:19)
- Code Copying and Modification (5:37). involves changing the command name and identifying necessary adjustments for fsharp.
- learning dotnet fsi (6:40): how to execute fsharp scripts, specifically using the dotnet fsi command.
- The challenge lies in passing fsharp expressions as standard input rather than as files.
- Exploring Command Line Options and Documentation (10:00): look into the help documentation for the dotnet command, discussing the complexities of command-line arguments, especially when dealing with various programming languages and their execution environments.
- Discussion on File vs. Standard Input (17:08): A detailed explanation is provided about the benefits of piping code to standard input versus writing to and reading from temporary files, emphasizing performance and avoiding file management overhead.
- Seeking AI Assistance (30:19): The presenter uses an AI tool to inquire about how dotnet fsi accepts fsharp expressions from standard input, confirming that piping directly to it is the intended method.
- Testing and Initial Results (36:15): The newly modified fsharp evaluation command is tested.
- While it successfully executes the fsharp code, it also outputs extraneous copyright and interactive shell information, which needs to be addressed.
- Acknowledging Remaining Issues and Future Steps (37:54): The video concludes with the presenter acknowledging that the output needs to be refined and that further investigation into the dotnet fsi command-line options is required to suppress the unwanted output.
- The presenter also shares the Emacs Lisp code developed during the show.
- the job is to write a
xah-fsharp-eval-region - we already have
xah-js-eval-region
- how to get
dotnet fsito accept a fsharp expression from stdin - answer: just pipe to
dotnet fsi --quiet
console.log( 3 + 4 )
let x = 3 printfn "%i" (x+4) printfn "%i" (3+4 )
(defun xah-fsharp-eval-region (Begin End &optional zinsert-output zadd-print) "Eval the current region in dotnet fsi, print result in buffer *xah fsharp output*. If there is no text selection, eval current text block. If `universal-argument' is called first, insert result below the region. Require the external command dotnet. Created: 2026-01-21 Version: 2026-01-21" (interactive (let (xbeg xend) (if (region-active-p) (setq xbeg (region-beginning) xend (region-end)) (let ((xp (point))) (save-excursion (setq xbeg (if (re-search-backward "\n[ \t]*\n" nil 1) (match-end 0) (point))) (goto-char xp) (setq xend (if (re-search-forward "\n[ \t]*\n" nil 1) (match-beginning 0) (point)))))) (list xbeg xend current-prefix-arg))) (let ((xoutbuf (get-buffer-create "*xah fsharp output*"))) (with-current-buffer xoutbuf (erase-buffer)) (call-process-region Begin End "dotnet" nil xoutbuf t "fsi" "--quiet") (if zinsert-output (progn (goto-char End) (insert "\n") (insert-buffer-substring xoutbuf)) (progn (display-buffer xoutbuf)))))