4 ms·
I guess that depends on whether you consider write(2) to have side effects. No, really, I've been in the room when people debated whether that was pure enough.
by kstrauser 3y ago
I guess that depends on whether you consider write(2) to have side effects. No, really, I've been in the room when people debated whether that was pure enough. It's an interesting exercise to talk through, at least.
- mrkeen 3y agoEven taking write as an effect (which I do), that doesn't stop it from being a trivial attachment to an otherwise pure artifact. IO in -> pure stuff of interest -> IO out The purity is in no way compromised by being IO-adjacent.
- JonChesterfield 3y agoI think that's an aliasing question. If write is sending bytes to somewhere else, it's pure. In exactly the same way that returning a value type from a function is pure, or passing a value type to some other function is pure. Since they're all the same thing. A unix process is a function in a literal sense. If you've aliased read and write to the same thing then mutation is back with us and sorrows return. Vaguely tangential, it's totally possible to write a program that uses read() to copy all of stdin to its own address space allocated with brk(), does whatever maths it wants, then sends some of the result back out with write(). Three syscalls, useful userspace program, no libc involved.