3 ms·
Whenever I think of Lisp for scripts, or even a login shell, I drift towards an elegant handling of pipes. Mostly because for 99% of what I do, it involves pipe
by whartung 3y ago
Whenever I think of Lisp for scripts, or even a login shell, I drift towards an elegant handling of pipes. Mostly because for 99% of what I do, it involves pipes.
Scsh did a lot of work with this but it’s still (as I recall) ungainly. Not to mention the idea of mixing process calls with native functions.
Something like this would be nice:
(| ‘ls’ (myfunc) ‘uniq’ (out-to “afile”))
- matheusmoreira 3y agoUntyped syntax is a defining chracteristic of shells. This answer by Jörg W Mittag is very convincing: https://stackoverflow.com/a/3640403/512904 https://stackoverflow.com/a/3640403/512904 This table in particular is very illuminating: | Ruby | Bash ----------------------------------------- number | 123 | 123 string | '123' | 123 regexp | /123/ | 123 file | File.open('123') | 123 file descriptor | IO.open('123') | 123 URI | URI.parse('123') | 123 command | `123` | 123 Here's a similar table with add your example's syntatic elements: | Lisp | Bash ----------------------------------------- command | `ls` | ls function | (myfunc) | myfunc string | "afile" | afile redirection | (out-to "afile") | >afile
- amno 3y agoIndeed. However you can achieve things like that in an ordinary Lisp via unevaled (special) forms, with other words, macros. In Emacs Lisp eshell does it too, though they have extra advantage since Emacs has built-in text editor and text processing extensions. Eshell implements both Bash and Lisp syntax. I am not sure if "sharp lisp" does anything special for scripting than any other Lisp, but it is possible to do.
- matheusmoreira 3y agoThat's true but when you do that it's not really lisp anymore it's another language you just created and implemented as a lisp macro.
- amno 3y agoIndeed; that is my objection to the loop and format in CL. But on the pragmatic side, if you want to interop with shell, or some other language/runtime, isn't it sometimes easier and less typing and noise if a program can be expressed in DSL or as a mix of Lisp and a DSL than if everything is written in pure s-expressions?
- adrian_b 3y ago"scsh" (Scheme Shell) has something like this and many other features that make it a good alternative to bash scripts. https://scsh.net/about/what.html https://scsh.net/about/what.html It certainly is much more convenient than Python for writing scripts that must execute other programs. Many years ago, I have written quite a large amount of big scripts in scsh, and it was much easier to avoid bugs and to maintain them than in a traditional UNIX shell, without being so verbose as something like Python. Unfortunately, nowadays scsh is quite ancient and it would need some serious work to bring it up-to-date, to be able to work without limitations on modern computers. It would probably be necessary to port it to a more recent Scheme interpreter than Scheme 48 (which is an old 32-bit program).