Question

As an offshot of a discussion in the comments on this question. I wanted to ask about the relationship between side effects and esoteric functions. specifficaly:

1) could you access the gpu (and cause graphics side effects) using ook/brainfuck ?

2) could you make a system call using whitespace ?

3) essentially it boils down to, can you cause all common side effects using any turing complete language ?

4)bonus question: if it is possible, can you provide a link to a working example/code ?

Was it helpful?

Solution

bmargulies's comment is spot on with regards to the general question. Turing-complete technically means that the language can be used to simulate a single-taped Turing machine. Practically that means that you could simulate any calculation on Turing-complete language X on Turing-complete language Y. However, all the things you're talking about aren't calculations -- they're system interfaces. To do specific things in a specific system, you need to have an interface. These languages don't provide a generic interface; they provide a few system calls, as we'll see below.

Let's use a weak analogy. Consider the space shuttle. Every calculation in the space shuttle could be done with your iPhone (perhaps not in a timely fashion); but it would take a special-purpose system to actually fire rockets and disconnect boosters. You could write an app for the iPhone whose output is instructions for astronauts, like "Fire starboard rocket for 10 seconds!" and fly the space shuttle that way. But you couldn't just plug in your iPhone to the space shuttle's dock.

So, as you might expect, the answer to all of your questions are, respectively:

  1. "No. But you could, if you want to hack it."
  2. "No. But you could, if you want to hack it."
  3. "No. But you could, if you want to hack them."
  4. "Go hack it!"

whitespace is an interpreted language, and the language does not provide any system integration besides reading and writing characters to the console. (Nor does it produce traditional assembly code that you could readily integrate into a C program per that original question. You'd need to use a system call to run the interpreter from your C program and return the output to your process. The very height of efficiency!) The language and interpreter are open source, so technically you could modify the language to support generic OS calls via the interpreter.

Brainfuck actually compiles, so in theory you could more easily include it in other programs if you're feeling saucy. Like whitespace, it only supports reading and writing characters. It would be interesting (and perhaps worthy of a thesis) to modify Brainfuck to support full system calls.

Here's the compiler's source. Have at it:

Hope that helps!

OTHER TIPS

You could always write a wrapper that interprets the ook / brainfuck / whitespace / etc. program's output as commands to access the gpu / make system calls / brew coffee / whatever.

But no, there is no built-in mechanism to do any of those things in brainfuck, and I don't believe any of the other languages you mention have one either. Being "Turing-complete" just means that the language can, in theory, compute anything that a normal computer can compute. It doesn't mean that the language necessarily provides a mechanism to do any of the non-computational things the computer might also be capable of, like drawing graphics, playing sound or, indeed, brewing coffee.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top