Hi…
He’s on my ignore list and I still can’t help myself :(.
Logic is lines of program code while data is groups of variables. Code is not data, therefore variables are not logic. Data may be transformed, processed or manipulated by logic, but it is not part of that logic.
Every 18 year old CS student knows that this is bogus. Code and data are completely interchangeable.
Code is data when it’s not being interpreted. Data is code if it will be acted upon. The obvious examples are interpreters, compilers, configuration files, declarative languages, queries, bytecode, refactoring tools, blah, blah.
The turing machine makes no distinction between code and data and neither does lambda calculus. Linux makes a distinction (code, data, stack segments) for kernel security and optimisation purposes, but all the PHP code we write will end up in either the data segment or the stack.
As a bit of fun, here is the code for a list structure:
function empty_list() {
return function () { return false; };
}
function cons($head, $tail) {
return function ($op) use ($head, $tail) {
return $op($head, $tail);
};
}
function head($list) {
return $list(function ($head, $tail) { return $head; });
}
function tail($list) {
return $list(function ($head, $tail) { return $tail; });
}
The code above does not assign a single variable.
The cons() function creates a list by prefixing an existing list with an item. So to create an single item list:
$list = cons('hello', empty_list());
A two item list would be:
$list = cons('hello', cons('world', empty_list()));
You can verify that this works by plucking out the second item:
print head(tail($list));
You can even write a function to display the list like so…
function show_list($list) {
if (head($list)) {
print head($list) . ' ';
show_list(tail($list));
}
}
So you can now go:
show_list(cons('hello', cons('world', empty_list())));
Where is the data? You could compile the above line of code on Linux without ever using malloc().
Funky eh?
yours, Marcus
p.s. The example comes courtesy of Alonzo Church.