Hacker News new | ask | show | jobs
by thedigitalengel 4728 days ago
Representing self is actually not that difficult or mind-bending; you just need a representation that is isomorphic to the program source. For instance, you could store the ASCII symbols in an integer array:

  int array = { ... } // holds the source code,
                      //  except its own representation

  int array_index; // The index in the source code
                   // (where the actual integers in
                   // array interpreted as source appear)

  for i = 0 to array_index:
    print (array[i] as an ASCII character)

  for i = 0 to array_length:
    print (array[i] as integer ++ ", ")

  for i = array_index + 1 to array_length:
    print (array[i] as an ASCII character)
The core idea is that you can interpret `array` in two ways, as an array of integers or an array of ascii characters representing the program source. The only difficult part is adjusting array_index. With a little effort, this can be scaled to a chain of languages.