Code is data....

Started by
30 comments, last by DerPhill 18 years, 3 months ago
Quote:Original post by King of Men
Perhaps I phrased it awkwardly, but the point I was actually trying to make is the same one as yours : It depends on context. But I think I disagree with you on the 'executable syntax' bit : Any random set of numbers is code as far as I'm concerned.

Well, I couldn't disagree with that statement even if I wanted to, as you expressed it as your personal opinion! ;)
Quote:
What makes it code is the context of being supplied to the CPU as instructions.

That's not so clear, although I do agree. For example, C++ source code is not a direct set of instructions to a CPU, but indirectly it is, via the compiler. It's the C++ Standard (and the rules of the compiler) which give the C++ the executable semantics.
Advertisement
Quote:Original post by Alpha_ProgDes
OK. This is code:
struct People {   int age = 16;   string name = "John Smith";   float height = 70; // this is in inches   Gender sex = MALE; // this is an enum} Person;

but isn't this data as well? (A lisp example [and comparison] would be nice.)

Let me take a stab at this.

I've never used lisp, but I have programmed in Scheme which should be close enough. In Scheme, the main data structures are atoms and lists. A Scheme PROGRAM is itself a list of atoms. For instance:

(+ 2 4)


Is a program and it's a list containing a function and to numbers. You can use it however you please.

In C++, this would be equivalent to being able to create an array and execute it. Of course, this doesn't work, because an array does not have any inherent execution. You must declare the array and manipulate it with loops and such. An array is DATA--the loops are PROGRAM.

In lisp-like languages this distinction does not exist. Every data definition can be a program, and every program is a data definition--in the same context.

****************
Disclaimer
****************
For the veteran lisp programmers, I'm not attempting to give a 100% precise explanation--so save the nit picking for someone else. The above has been generalized considerably.

This topic is closed to new replies.

Advertisement