Add ABCL disassembler post.
[blog.git] / unix-lisp.post
1 ;;;;;
2 title: Lisp layered on Unix
3 tags: lisp,unix,emacs
4 date: 2014-11-27 21:21:10
5 format: md
6 ;;;;;
7
8 [This blog post][heart] on LispCast is a pretty good start to get thinking
9 about the intricacies of the interaction between Lisp (Machine) ideas and the
10 current Unix environment.  Of course that includes plan9 on the one side and
11 Emacs on the other.
12
13 [heart]: http://www.lispcast.com/the-heart-of-unix (The Heart of Unix)
14
15 # Lisp shell
16
17 There is [scsh](???), but it's not really what I'm looking for.  Using emacs as
18 login shell (with the `eshell` package) comes closest to it regarding both
19 with existing commands and integration of Lisp-based ones.  However, while
20 pipes work as expected with `eshell`, data is still passed around as
21 (formatted) text.  There doesn't seem to be an easy way to pass around
22 in-memory objects, at least while staying in Emacs itself.  That would of
23 course mean to reimplement some (larger?) parts of that system.
24
25 This all ties in to the idea that unstructured text isn't the best idea to
26 represent data between processes.  Even though Unix pipes are extremely useful,
27 the ecosystem of shell and C conventions means that the obvious way isn't
28 completely correct, meaning that there are edge cases to consider.  The best is
29 something as innocent as `ls | wc -l`, which will break, depending on the shell
30 settings, with some (unlikely) characters in filenames, i.e. newlines.
31
32 # Common formats
33
34 One of the problems is obviously that in order to pass around structured data,
35 i.e. objects, all participants have to understand their format.  Passing
36 references won't work without OS support though.
37
38 Instead of having unstructured streams, use streams of (data) objects.  The
39 distinction here is Plain Old Objects (PODs) instead of objects with an
40 associated behaviour.
41
42 Let's take a look at standard Unix command line tools (I'm using GNU Coreutils
43 here) in order to reproduce the behaviour and/or intent behind them:
44
45 ## Output of entire files
46
47 The first command here is `cat`.  Although GNU `cat` includes additional
48 transformations, this command concatenates files.  Similar to the description,
49 we can image a `CAT` to perform a similar operation on streams of objects.
50
51 It doesn't make much sense to concatenate a HTML document and an MP3 file
52 (hence you won't do it in most cases anyway).  However, since files are
53 unstructured, `cat` can work on them.
54
55 # Registering functionality
56
57 Although you can call commands individually on files, some of them form an
58 ad-hoc service interface already:  The C compiler, along with the toolchain
59 forms one such interface, where you're required to use the same interface if
60 you want to seamlessly replace one part of the toolchain.
61
62 Same goes for the Coreutils:  As long as you honour the interface, programs can
63 be replaced with different implementations.
64
65 # Interactive commands
66
67 Emacs has a special form `interactive` to indicate whether a command can be
68 directly called via the command prompt.  There is also special handling there
69 to accomodate the use of interactive arguments.  This is something that can be
70 generalised to the OS.  An example of where this already happens is the
71 `.mailcap` file and the `.desktop` files from desktop suites.
72
73 # Threading and job control
74
75 Unfortunately getting proper job control to work will be a bit of a problem in
76 any Lisp implementation, since the best way to implement the concurrent jobs is
77 using threads, which are not particularly suited for handling the multitude of
78 signals and other problems associated with them.  Even without job control
79 pipelines implemented in Lisp require shared in-memory communication channels,
80 so something like (object-based) streams, mailboxes, or queues are necessary to
81 move IO between different threads.