Giter Club home page Giter Club logo

self-replicating-programs's Introduction

self-replicating-programs

A number of self replicating programs (quines)

  • PHP, probably v5.x on into v8.0.2
  • self_replicating.py - Python 2.x
  • self_rep_alternating.py - Python 2.x, alternates generations
  • replicate.html - JavaScript and HTML, replicates in a browser. Try it!
  • triplet - Perl, Bash, Python 2.x and PHP quine relay/ouroboros program. Execute run_replication to try it out.
  • Shell script, Bash, probably ksh. Changes just a little with each reproduction.
  • Python 3.x "f" strings
  • GNU m4 macro
  • awk
  • GPP

The Python3, m4, awk and PHP versions are conceptually similar to my Go self-replicating program in that they all use a formatting string as an argument to formatting. The specifics of this are peculiar to each language, but are reminiscent of Combinatory Logic's M M term.

You have to run the self-replicating awk program like this:

$ awk -f r.awk

The m4 macro processor self-replicator is of interest. First, m4 input doesn't have a way to escape characters in its input. Second, m4 quoted strings use matched pairs of "grave accents" (`) (ASCII 0x27) and single quotes (') (ASCII 0x2c), allowing embedding quoted strings in quoted strings. Between allowing quoted strings in quoted strings, and the defn built-in, it's not too hard to write a self-replicating m4 input. Avoiding a trivial self replicator is the hard part. Any input that does not define and use a macro will cause m4 to produce output identical to its input. Using the defn builtin, which doesn't technically violate the rules of writing quines, seems roughly equivalent to those programs that open the file of their own source and write it out.

m4 macro language notes

I found writing a quine in GPP (and here), the Generic Preprocessor, terrifically difficult.

Default user macros make it impossible to interpolate strings in macro bodies and in outputs without also having whitespace. Bash can interpolate variables like this: some${variable}text, using curly braces to lexically mark the variable. Default GPP doesn't have that.

Default string format, and macro expansion inside strings make it easy to write infinitely-expanding macros In contrast, Python has ', " and """ delimiters for strings, Bash, PHP and Perl have " and ', Go has " and `. In all of these languages, one mode of delimiting strings allows variable interpolation, and one mode does not allow it.

I used GPP's "meta macros" to change macro definition and macro expansion rules part way through the quine to overcome these difficulties. I'd be interested in seeing a GPP quine that does not use meta macros to change default string interpolation and macro substitution behavior.

self-replicating-programs's People

Contributors

bediger4000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.