From sunybcs!lammens Mon Apr 2 17:26:22 EDT 1990 Article 24 of sunyab.cs.676: Path: sunybcs!lammens >From: lammens@acsu.Buffalo.EDU (Joe Lammens) Newsgroups: sunyab.cs.676 Subject: Universal program Date: 2 Apr 90 18:13:17 GMT Sender: nobody@acsu.Buffalo.EDU Distribution: local Lines: 511 Last Thursday (03/29) we briefly discussed universal programs, and what they do to descriptions of other programs (you can substitute Turing Machine" for "program" if you like). If you're interested in the subject, and are somewhat familiar with theory of computation, you might find the lisp program below interesting to experiment with. It's a lisp implementation of a universal program that takes numbers as input and interprets them as programs, and some related functions. The code has all the documentation you need. Cut between the ----CUT HERE---- lines (there's one at the end too!), save to a file and load the file into any Common Lisp interpreter. The code has some on-line examples. Enjoy. ----CUT HERE---- ;;;--------------------------------------------------------------------------- ;;; ;;; universal.lisp ;;; ;;; Joe Lammens 10/26/89 ;;; SUNY/Buffalo dept. of Computer Science, Buffalo NY 14260 ;;; e-mail lammens@cs.buffalo.edu ;;; ;;; Feel free to distribute. ;;; ;;; Revised 03/31/90 to use inc, dec, bnz in stead of increment, ;;; decrement, branch-on-not-zero as mnemonic instruction names. ;;; ;;; This file contains some functions for coding, decoding and executing ;;; programs (or their corresponding numbers) of the language L as ;;; defined in Martin D. Davis & Elaine J. Weyuker, "Computability, ;;; Complexity and Languages", Academic Press, New York etc. 1983, ;;; chapters 2-4. The syntax is Common Lisp, as defined in Guy L. Steele ;;; jr., "Common Lisp", Digital Press, Bedford MA 1984. Since this stuff ;;; is meant for educational use or just for fun, it is not optimized ;;; for efficiency. Efficiency is not a consideration with a language ;;; like L anyway. But I suspect functions like next-bigger-prime could ;;; be optimized quite a bit. Load the complete file into a Common Lisp ;;; system and enjoy. A couple of example calls are included near the ;;; end of the file. ;;; ;;;--------------------------------------------------------------------------- ;;; ;;; All functions work with integer numbers or L-programs in list format, ;;; which is a list of instructions. Common Lisp in principle allows integers ;;; of any magnitude, although (de)coding big L-programs might take a while or ;;; might cause the interpreter to run out of memory. Each instruction is a ;;; list of four symbols (