[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Self replicating code



Here is a brute-force expression which prints itself.  This was in LISP370,
circa 1978.

 (PRINT
   ( (LAMBDA (X Y)
       (SEQ
         (RPLACA (CDAR (CDDADR X)) (COPY Y))
         (RPLACA (CDADR (CADADR X)) (COPY Y))
         (EXIT X) ) )
     (COPY
       "(PRINT
         ( (LAMBDA (X Y)
             (SEQ
               (RPLACA (CDAR (CDDADR X)) (COPY Y))
               (RPLACA (CDADR (CADADR X)) (COPY Y))
               (EXIT X) ) ) (COPY "NIL) "NIL ) ) )
     "(PRINT
       ( (LAMBDA (X Y)
           (SEQ
             (RPLACA (CDAR (CDDADR X)) (COPY Y))
             (RPLACA (CDADR (CADADR X)) (COPY Y))
             (EXIT X) ) ) (COPY "NIL) "NIL ) ) ) )


The uses of copy were to keep it from modifying itself.
Obviously, shared sub-structure could be used to shorten the
representation.

Cyril N. Alberga