by lispm · 10y ago · 0 comments
The version with small functions, similar to the Haskell version:
(subseq
(remove-if
(complement #'numberp)
(butlast list 3))
0 5)
In above Common Lisp code, we use four different functions which do one task: * subseq sequence start &optional end => subsequence
* remove-if test sequence => result-sequence
* complement function => complement-function
* butlast list &optional n => result-list
For different approaches see Common Lisp libraries like Series or Iterate... Iterate is LOOP on steroids.https://common-lisp.net/project/iterate/
> This is known as composability, or the UNIX philosophy. In Lisp a procedure tends to accept many options which configure its behaviour.
Check out the UNIX man for tail, grep, ... to see how strange above quote about 'unix philosophy' is. In reality Unix commands are programs with obscene amount of configuration options, sometimes piping data as text around, sometimes glued together by strange shell languages...
I wish someone would take that hoary old meme out behind the barn and put it out of our collective misery.
Function composition via types is a much more satisfying take on this problem. It's too bad Unix is regarded as the holy grail of this technique when it barely provides a passable implementation of it.
Text just isn't a great medium for IPC.
> Text just isn't a great medium for IPC.
Yes, in retrospect Unix's determination to know about nothing but binary or plaintext blobs and streams looks like an adolescent rebellion against the (apparently - I haven't used them) clunky record structures of '60s operating systems.
It's also pretty hard to pass a function to a Unix command. Either your command supports its own syntax (grep, find), or you make do writing a loop or a temporary file.
>Text just isn't a great medium for IPC.
Yeah, text does suck for IPC. The problem is, everything else sucks even more.
POSIX itself is a huge PCB of bodge-wires due to legacy compliance. On the upside for systemd haters, they can appeal to the 2004 ISO standard as init.d being the "right way". But if you read the rationale behind a bunch of utilities especially in Section B, you'll see why it's so crusty. "This ..worked in SysV so we're going to keep it". The Linux Standard Base specification isn't much better.
The whole argument as to 'what is UNIX' is so contrived at this point, but anyone making the argument that GNU coreutils are about composibility are correct (see page 230 of https://www.gnu.org/software/coreutils/manual/coreutils.pdf). They assert that the Bell Labs UNIX philosophy was effectively "one tool to do one thing well, orthogonal to other tools, to facilitate composibility" (the authors even dedicate an entire proceeding section to demonstrate it) but that's without any direct references to previous specifications.
Anyways, I'm with you, and apparently the GNU guys claim the Bell Labs guys were with you as well.
UNIX is more than just a trademark, more importantly it is the test suite you have to pass to be allowed to use the trademark. And the trademark doesn't belong to SCO, it belongs to The Open Group, a not-for-profit industry consortium (successor to X/Open and the Open Software Foundation.)
Does it matter that much? I'm sure it makes it easier to port a package to a certified UNIX, since you know a certain collection of APIs must be there (putting aside the fact that some parts of the UNIX standard are optional)
It says something about the state of software if Unix is the thing that "taught us about composability". Laughable.
Also, the way the article uses `remove-if-not` is all wrong. The `:start` argument to `remove-if-not` doesn't mean it starts taking elements after the third one, rather it means it starts filtering after it. So
(remove-if-not #'evenp '(1 2 3 4 5 6) :start 3)
doesn't produce (4 6) as the article assumes. It produces (1 2 3 4 6).And the `:count` argument doesn't mean it returns 5 elements, rather it means it removes 5 elements. So
(remove-if-not #'evenp '(1 2 3 4 5 6) :count 1)
returns (2 3 4 5 6).The "UNIX philosophy" is good, it's just that UNIX doesn't really follow it.
The C and shell programs that make up UNIX commands are actually UNIX's own little programming language, complete with ad-hoc data types.
Look at `cat` for example. It might as well be `str + str...`. Or look at `grep`, it's basically `filter` or `reduce` at heart. But it has to do this per-line, and it has no metadata about the line, it literally just works on string contents. The `head` and `tail` commands aren't much different than `take` and `drop`. Heck there's even a `sort` command.
That's why shells that actually use a programming language (e.g. eshell) don't seem so crazy to me. To be honest, I use eshell way more than I use bash, and half the functions I use there are written in lisp rather than bash or C.
It never did, beyond some examples in beginner books.
> Look at `cat` for example. It might as well be `str + str...`. Or look at `grep`, it's basically `filter` or `reduce` at heart.
Then look at the options of `cat`. On my Linux system cat has a -n option, which numbers the output lines. If it were following the 'UNIX philosophy', this option would not exist.
The UNIX composition is only a novelty for those that never saw other OSes that surfaced at the same time. After all UNIX just adopted the idea from MULTICS.
Gnu's not Unix. "The GNU coreutils version of this on my Linux box behaves this way" is not a good way of getting at finer points of what is or is not Unix-y.
That said, -n exists in BSD cat as well. It's not required by POSIX, though.
http://git.suckless.org/sbase/tree/cat.c
http://plan9.bell-labs.com/sources/plan9/sys/src/cmd/cat.c
Not only "Gnu's not Unix", it's also not that much interested in following "Unix philosophy". Which isn't that bad, from a user perspective: users want more capable tools, even if it impedes composability a bit.Well you know what they say. Talk is cheap. Ideas are basically free. Following through is hard.
Having an abstract ideal is worthless if you are just going to squirm and excuse yourself when you don't follow through on them. Which is basically what Unix does when you question whether it follows what it preaches.
I think a lot of that is due to the untyped nature of unix. Everything is text, so you constantly have to specify details about what the actual input is.
Not sure if that applies to lisp or not.
Granted, that's not the only reason.