News for hackers. Stuff that matters.
Re:Common Lisp for Shell Scripting by vindarel on Thursday May 23, 2024 @11:28AM (#40455902)
Nice article, I learned a couple tricks.

A first gotcha:

> you could just replace it with… #!/usr/bin/sbcl –load /home/youruser/.sbclrc –script

this doesn't work, since a shebang only accepts one argument.

---

There are 2 main caveats to the described approach: starting SBCL like this from sources and not from a binary takes a little time. And you don’t have batteries included. Want a HTTP client, a CSV parser? You have to quickload them and this adds up in the startup time.

We can rely on long-running images in the editor and run stuff from there, bypassing the terminal altogether, or build binaries, or try other approaches (Lish shell, a lisp server https://notabug.org/quasus/lserver/)

But that’s why I started CIEL, CL with batteries included. You can get a binary and run scripts that start fast and can do common tasks. It’s also a superset of useful libraries that you can quickload or use with a core image (for a fast startup in your editor).

https://github.com/ciel-lang/CIEL/

http://ciel-lang.org/

It’s in beta, polishing phase.

Re:Common Lisp for Shell Scripting by latexr on Thursday May 23, 2024 @11:57AM (#40456340)
> a shebang only accepts one argument.

I don’t think that’s right. I regularly use `#!/usr/bin/osascript -l JavaScript` as a shebang on macOS and it works as expected. It’s also good practice to use `/bin/zsh --no-rcs` so the script does not load `~/.zshenv`.

Re:Common Lisp for Shell Scripting by bananskalhalk on Thursday May 23, 2024 @12:29PM (#40456729)
It isn't defined in posix. Some bsd:s did split but doesn't anymore, other (which?) does still split. macOS does, linux doesn't. Sun probably did.
Re:Common Lisp for Shell Scripting by phlakaton on Thursday May 23, 2024 @12:15PM (#40456574)
Perhaps this is because osascript can handle '-l JavaScript' as a single arg? The single-arg limitation is a well-known "feature" (ha) of UNIX shebangs.
Re:Common Lisp for Shell Scripting by Xophmeister on Thursday May 23, 2024 @12:18PM (#40456604)
It's true on Linux.
Re:Common Lisp for Shell Scripting by sneed_chucker on Thursday May 23, 2024 @11:32AM (#40455977)
I feel like I've written this comment a million times but here it is again.

Shell scripts are mainly written in order to automate subprocess-heavy tasks or to take advantage of the general availability of bash or bourne-compatible shells on most modern Unix based systems.

If you want things like reasonable variable scoping, real functions, loops, libraries for path and string manipulation, or a sane separation between what is and isn't a string, then Python is the obvious choice.

Yes, Python's subprocess module is less convenient than doing a subprocess call in Unix shell, but you can replace grep, sed, awk, find, and similar common subprocess calls in shell scripts with library and built-in functions in Python. The end result tends to be more a readable, maintainable, and testable script.

Python 3 also gets installed by default on nearly all non-minimal Linux distros these days. SBCL gets installed by default nowhere.

Re:Common Lisp for Shell Scripting by neilyio on Thursday May 23, 2024 @11:54AM (#40456299)
I use shell scripts left and right for all kinds of things in my regular dev workflow. Running tests with various configurations. Complex tmux layouts. Syncing non-got data. I could go on and on. Common Lisp would be an incredible asset for this, as Babashka already is in the Clojure world. The REPL alone makes writing/maintaining these scripts very efficient. Why do you feel like Python must be the choice for everyone?
Re:Common Lisp for Shell Scripting by Jtsummers on Thursday May 23, 2024 @11:55AM (#40456314)
> Python 3 also gets installed by default on nearly all non-minimal Linux distros these days. SBCL gets installed by default nowhere.

By that rationale we should only use languages which are installed by default on most systems. That's a severe reduction in the number of languages available for people to use.

Re:Common Lisp for Shell Scripting by phlakaton on Thursday May 23, 2024 @12:11PM (#40456529)
laughing in m4
Re:Common Lisp for Shell Scripting by hatmatrix on Thursday May 23, 2024 @11:48AM (#40456205)
The downside of this is that Python is not a Lisp.
Re:Common Lisp for Shell Scripting by vindarel on Thursday May 23, 2024 @11:46AM (#40456177)
> SBCL gets installed by default nowhere.

for this, it's easy to build a binary.

Re:Common Lisp for Shell Scripting by p_l on Thursday May 23, 2024 @11:53AM (#40456285)
The way I see it, the last time I could rely on Python being reasonably available, the version was 2.4
Re:Common Lisp for Shell Scripting by anotherhue on Thursday May 23, 2024 @11:33AM (#40455984)
Related: Clojure for shell scripting:

https://github.com/babashka/babashka

Re:Common Lisp for Shell Scripting by perihelions on Thursday May 23, 2024 @12:10PM (#40456516)
If you insist on doing this, you would want to built a custom SBCL core for the purpose. SBCL startup time is ~80 milliseconds on my machine, which is not only unpleasantly noticeable by itself, it's a total show-stopper if you're doing some `find | xargs` type shell pattern and you're multiplying that 80ms by ten thousand. An executable core file brings that down to 3 ms.

You'd want to pre-load all the packages you expect to typically use, in your scripting Lisp, so they go straight into RAM memory without any delay. And you'd want to turn off core compression entirely, to wring out those last milliseconds.