The “Unix way” stands on the shoulders of stdin, stdout, pipe, and fork.
And the shells make that a first class concept. Breaking up the command line and linking processes together is the #1 job of a shell, everything else is gravy.
The scheme and lisp shell takes fail here, just because you have to go through the gymnastics of syntax.
My fantasy would be to have something like this:
(! ls | (myfunc) | sort -r -n | >list)
(“100 x.txt” “200 y.txt”)
Piping system commands into my own functions within the environment.Sure, I could do:
ls | myfunc.scm | sort -r -n
But then I can do that with anything, not just scheme (there’s that Unix superpower again).I would be something like this,
(->
ls
myfunc
sort -r -n
(> list))
Followed by "Select => Execute" with the mouse, or "Execute last form" with keyboard shorcut. $ txr
This is the TXR Lisp interactive listener of TXR 299.
Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
Poke a few holes in TXR with a fork before heating in the microwave.
1> (flow (glob "/proc/*") (take 10))
("/proc/1" "/proc/10" "/proc/101" "/proc/102" "/proc/103" "/proc/104"
"/proc/107" "/proc/1074" "/proc/1086" "/proc/11")
2> (flow (glob "/proc/*") (take 10) (map (op trim-left "/proc/")))
("1" "10" "101" "102" "103" "104" "107" "1074" "1086" "11")
3> (flow (glob "/proc/*") (take 10) (map (op trim-left "/proc/")) (sort @1 : toint))
("1" "10" "11" "101" "102" "103" "104" "107" "1074" "1086")
4> (flow (glob "/proc/*") (take 10) (map (op trim-left "/proc/")) (sort @1 greater toint))
("1086" "1074" "107" "104" "103" "102" "101" "11" "10" "1")
How about we parse digit sequences out of the path names and combine them with the originals, then sort on those digit sequences turned into integers: 5> (defun get-nums (str)
(flow str (tok #/\d+/) (map toint)))
get-nums
6> (flow (glob "/proc/*") (take 20) (csort @1 greater get-nums))
("/proc/11170" "/proc/11169" "/proc/1222" "/proc/1199" "/proc/1198"
"/proc/1194" "/proc/1133" "/proc/1104" "/proc/1086" "/proc/1074"
"/proc/117" "/proc/107" "/proc/104" "/proc/103" "/proc/102" "/proc/101"
"/proc/12" "/proc/11" "/proc/10" "/proc/1")
csort is caching sort: it caches the result of the key function through which the elements are projected to form the argument of the comparison.
In other words, so we don't wastefully call get-nums multiple times for the same path.One that strove to do both WOULD have to do all the things you suggested as well (job management, stdout/stderr redirection etc.) So options like oil shell, nushell, fish etc.
I was just talking about "a commandline tooling language" in general, as far as use-cases. And for that, Lua (and Moonscript, which compiles to Lua but is way nicer and has been featured on HN a few times over the years) seems to fit the bill (1-based indexing aside, ugh)