64 points · by behnamoh · 3y ago · 40 comments
Or scsh, for the old school: https://scsh.net
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”))This answer by Jörg W Mittag is very convincing:
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") | >afilehttps://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).
What you get extra is a really good debugger (edebug), and text processing library extensions so you don't need to start extra processes (grep, awk, tr & co) just to extract some text from one output and send it to another.
They also have really, really good integration with system, almost on par with Bash. So despite Lisp being more verbose than a DSL like Bash script, you win tons by just having a debugger. Completion and Emacs auto-typing features (snippets, abbrevs, autoinsert etc) compensate for the verbosty.
If you want multiline, you can always type the paren yourself.
To remind the user, make the default prompt `( `
Also consider using brackets [] instead of parens to be really wrist friendly.
Anyway, it is possible to do, for example M-x in Emacs does it. They do it by means of restricting repl to execute only functions, and they limit that to special function with so-called "interactive" form, whose job is to provide function arguments.
CL-USER 18 > + 1 2
3
CL-USER 19 > first (list 1 2 3)
1I have no experience with LispWorks whatsoever, but I am curious, how did they implemented it if you know? I mean, how do they differ between calling first as a value or first as a function? In your example first could be a defvared to have some value, and then I might have called a function to produce some unrelated output. I mean it is a contrived example, and probably nobody types in a repl like that, but the language does not forbid it since white spaces are insignificant.
If they just treat the first token as operator always, than they could call any function with any arguments:
CL-USER> op arg1 arg2 ... argN
but then they would have to eval all values at the start of repl by calling (symbol-function arg), instead of just type arg to examine a value. I don't think it would be a bad think in itself tbh; but I am not sure the win is big enough to introduce a new concept.By the way, I think I have stumbled on some mailing list comment somewhere once, where they said, that Hemlock can use commands named more "english like", i.e. they can have names with spaces in it, not just the hyphenated function name as in Emacs. Do you know more about it, or how they have implemented it? I am just curious; seen your comments on Reddit, and if you are the same person, I understand you are well experienced and familiar with various Lisps and implementations; hope you don't mind asking. :)