Show HN: A Lisp Interpreter for Shell Scripting

(github.com)

78 points | by quintussss 3 days ago

10 comments

  • vindarel 3 hours ago
    > writing your shell scripts in Lisp instead of Bash.

    in a Lisp ;)

    Related, for Common Lisp:

    - unix in lisp https://github.com/PuellaeMagicae/unix-in-lispMount Unix system into Common Lisp image.

    - kiln https://github.com/ruricolist/kiln - an infrastructure (managing a hidden multicall binary) to make Lisp scripting efficient and ergonomic.

    - CIEL https://github.com/ciel-lang/CIEL/ - CIEL Is an Extended Lisp is a collection of dozens of libraries useful for mundane tasks (HTTP, JSON, regexps…). It also comes as a binary that is able to run scripts from sources. Scripts that use the built-in libraries start fast without a compilation step. [project of mine]

    - discussed here: https://news.ycombinator.com/item?id=41401415

    - Lish https://github.com/nibbula/lish - maybe someday a Lisp shell

    - SHCL https://github.com/bradleyjensen/shcl - a POSIX shell in CL (stalling)

    - lserver https://notabug.org/quasus/lserver/ - live-coding remote function calls for the shell. Write a command in the REPL, and run it instantly in the shell.

    I use CIEL ;)

    And, built-in: use the --load flag or build a self-contained binary, compiled to machine code with SBCL. It can contain your web assets (html, js etc). A compressed binary weights ±30MB and starts fast. A stripped off binary with LispWork$ (no compiler, no debugger etc) is ±5MB. There's ECL too.

  • esrh 7 hours ago
    awesome! I have wanted something like this for a long time. Currently I use a janet fork <https://github.com/eshrh/matsurika> with some trivial additions, the most important of which is a `$` macro that does what the `sh` does here. I have two questions:

    - I see that `sh` does not take in strings but instead lisp forms. How do you distinguish between variables that need to be substituted and commands? In my fork, the way to do variable substitution involves quasiquoting/unquoting. - Almost all of the features that make your language good for shell scripting are essentially syntactic features that can easily be implemented as a macro library for say, scheme. Why'd you choose to write in C++? Surely performance is not an important factor here. (I'm interested because I am currently working on a scheme-based shell scripting language).

    • em-bee 1 hour ago
      can you give an example of how variable substitution in your language looks like?

      one of the things i think a lisp for shell should have, and i agree that this may not be easy, but unix commands should be first class functions, as in, you should not need a $ or sh macro to make them work. the other thing is that strings should not be quoted, and so you need something else to designate variables like $path or ($ path)

  • tanelso2 1 hour ago
    Very nice! A similar tool is [babashka](https://github.com/babashka/babashka) for Clojure
  • em-bee 2 hours ago
    this made me wonder why guile isn't designed for shell scripting too. i mean, wouldn't that make sense? if you want guile to be the designated extension language for gnu applications, why not also make it the designated language for shell scripts?
  • sshine 5 hours ago
    Related: Schemesh — A Unix shell and Lisp REPL, fused together

    https://github.com/cosmos72/schemesh

    https://news.ycombinator.com/item?id=43061183 (7 months ago, 177 upvotes)

  • rcarmo 2 hours ago
  • shorden 4 hours ago
    For a blend between Lisp and a more traditional POSIX shell, I enjoy Emacs' [eshell](https://www.masteringemacs.org/article/complete-guide-master...).
  • ctenb 6 hours ago
    Very nice! I've often wondered how close you could get to a POSIX-like syntax with something like this while maintaining a LISP semantics as much as possible. Especially pipelines are much easier to read with the | and > operators. I guess you need some sort of LISP dialect that supports infix operators
    • sshine 5 hours ago
      You can have regular shell infix pipes combined with Lisp/Scheme macros as control flow. I think the tradeoff that Schemesh is nice, even though it does sacrifice POSIX:

      The best of both worlds of shell and Lisp is quick ability to run and pipe processes, and full programming functionality without the shell scripting shenanigans like obscure semantics and lack of good data structures.

    • lycopodiopsida 5 hours ago
      Would take threading macros over pipelines every other day of the week.
    • cess11 3 hours ago
      Unless someone has already provided a library for it, write some wrappers around pipes and forks and use OCaml utop.

      It's not a Lisp but close enough, I'd say. If I didn't have the rather extensive background of using Picolisp and some other REPL-like tools as a form of shell I'd probably have settled for utop, at least until I reached my iex era.

  • antics9 6 hours ago
    This looks good! I've seen other tries of shell scripting with lisp dialects but Redstart syntax looks more intuitive (from a shell scripting standpoint) and easy to read.
  • sakesun 5 hours ago
    If you don't mind .NET, BraidLang is another interesting project.