
Es: A shell with higher-order functions (1993) - catern
https://wryun.github.io/es-shell/paper.html
======
lolc
Interesting! I keep getting frustrated with the arcane Bourne syntax and its
limitations. I've toyed with a lot of shells. But when it comes down to it, I
don't want to switch because the alternative is not ubiquitous.

~~~
nielsbot
I've switched to using python where possible.. but I guess there are reasons
not to do that?

~~~
claudiawerner
I've switched to Perl (and Perl 6) which seem to be better suited.

------
injinj
The problem with first class functions in a shell is that the main duty of a
shell is to fork processes. Once the shell is forked, the only communication
available are inter process. All of the environment is no longer shared.

For example, in es:

    
    
      ; let (i = 0) { fn hello {echo $i; i = <={%sum $i 1}}}
      ; hello
      0
      ; hello
      1
    

The closure variable i is incremented after every invocation of hello, but if
hello in a subprocess, then i doesn't change:

    
    
      ; hello | wc -c
      2
      ; hello
      2
    

This is because hello is a subprocess of the main shell when it is in a
pipeline. When it is used without the pipe, then it is executed within the
shell environment, not a child.

I have been using a fork of es since Dec, mine has the %sum builtin above,
along with some other things:
[https://github.com/injinj/desh](https://github.com/injinj/desh)

------
TimTheTinker
> We applied concepts from modern functional programming languages, such as
> Scheme and ML, to shells

Note that ML here refers to a functional programming language[0], not machine
learning.

[0]
[https://en.wikipedia.org/wiki/ML_(programming_language)](https://en.wikipedia.org/wiki/ML_\(programming_language\))

------
xelxebar
First order functions and the ability to override builtins. Definitely giving
this a try.

I've tried out several shells as primary drivers---bash, mksh, zsh, fish.
These got me thinking more generally in terms of "userspace tools" instead of
just interfaces with coreutils _etc_ , which made me wonder, can we use our
favorite REPLs in lieu of a standard shell?

I've tried using Haskell's ghci as a "shell" and, fixable ergonomics aside, it
seems doable. We already have interfaces to kernel syscalls, so in principle
it's "just" a libraries problem. File I/O is probably the easiest, and with
/proc and /sys, that's enough to replace several info-gathering system tools,
_e.g._ df, lscpu, mount (just listing).

Really wish I could immerse myself in Haskell for a few years and see if I
could learn enough to take this REPLshell idea somewhere.

------
ErotemeObelus
This is really cool & sweet.

