How to resolve the algorithm Quine step by step in the Mathematica/Wolfram Language programming language
How to resolve the algorithm Quine step by step in the Mathematica/Wolfram Language programming language
Table of Contents
Problem Statement
A quine is a self-referential program that can, without any external access, output its own source.
A quine (named after Willard Van Orman Quine) is also known as:
It is named after the philosopher and logician
who studied self-reference and quoting in natural language,
as for example in the paradox "'Yields falsehood when preceded by its quotation' yields falsehood when preceded by its quotation."
"Source" has one of two meanings. It can refer to the text-based program source.
For languages in which program source is represented as a data structure, "source" may refer to the data structure: quines in these languages fall into two categories: programs which print a textual representation of themselves, or expressions which evaluate to a data structure which is equivalent to that expression.
The usual way to code a quine works similarly to this paradox: The program consists of two identical parts, once as plain code and once quoted in some way (for example, as a character string, or a literal data structure). The plain code then accesses the quoted code and prints it out twice, once unquoted and once with the proper quotation marks added. Often, the plain code and the quoted code have to be nested.
Write a program that outputs its own source code in this way. If the language allows it, you may add a variant that accesses the code directly. You are not allowed to read any external files with the source code. The program should also contain some sort of self-reference, so constant expressions which return their own value which some top-level interpreter will print out. Empty programs producing no output are not allowed. There are several difficulties that one runs into when writing a quine, mostly dealing with quoting:
Next to the Quines presented here, many other versions can be found on the Quine page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Quine step by step in the Mathematica/Wolfram Language programming language
1. First Line:
a="Print[\"a=\",InputForm[a],\";\",a]";Print["a=",InputForm[a],";",a]
- This line assigns the string
"Print[\"a=\",InputForm[a],\";\",a]"
to the variablea
. - It then uses
Print
to output the value ofa
, which is the string itself.
2. Second Line:
a := Print[InputForm[Definition[a]], ";a"];a
- This line defines a function named
a
using theSetDelayed
assignment operator (:=). - The function takes no arguments and prints the input form of the definition of
a
, followed by a semicolon and the value ofa
.
3. Third Line:
(#1[#0[#1]] &)[Defer]
- This line creates a higher-order function that takes one argument,
#1
, and applies it to the result of applying itself (#0
) to#1
. - It then applies this higher-order function to the
Defer
function, which delays the evaluation of an expression.
4. Fourth Line:
ToString[#0][] & []
- This line creates a function that takes one argument,
#0
, and converts it to a string using theToString
function. - It then applies this function to an empty list, which results in an empty string.
5. Fifth Line:
Unevaluated[1989 - 1989]
- This line creates an unevaluated expression that subtracts 1989 from itself.
- The result is an unevaluated expression, meaning it will not be evaluated until it is explicitly requested.
6. Sixth Line:
x
- This line simply defines a variable
x
without assigning any value to it.
Source code in the wolfram programming language
a="Print[\"a=\",InputForm[a],\";\",a]";Print["a=",InputForm[a],";",a]
a := Print[InputForm[Definition[a]], ";a"];a
(#1[#0[#1]] &)[Defer]
ToString[#0][] & []
Unevaluated[1989 - 1989]
x
You may also check:How to resolve the algorithm XML/Output step by step in the Phix programming language
You may also check:How to resolve the algorithm Pascal's triangle step by step in the Ring programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Clojure programming language
You may also check:How to resolve the algorithm Vampire number step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Solve the no connection puzzle step by step in the Kotlin programming language