Quine: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 24: Line 24:
</source>
</source>
Explanation :
Explanation :
    In this code, the main function is <source lang=apl inline>{∊⍵⍺⍵⍺,4/⍵}</source>. In this function, the right argument <source lang=apl inline>⍵</source> is the literal <source lang=apl inline>'</source>, and the left argument <source lang=apl inline>⍺</source> is the string containing the representation of the function : <source lang=apl inline>'{∊⍵⍺⍵⍺,4/⍵}'</source>.
In this code, the main function is <source lang=apl inline>{∊⍵⍺⍵⍺,4/⍵}</source>. In this function, the right argument <source lang=apl inline>⍵</source> is the literal <source lang=apl inline>'</source>, and the left argument <source lang=apl inline>⍺</source> is the string containing the representation of the function : <source lang=apl inline>'{∊⍵⍺⍵⍺,4/⍵}'</source>.
The idea behind this quine is that the only thing you need to have a string containing the original code is to reproduce this structure : <source lang=text inline>[quote] [function] [quote] [function] [quote] [quote] [quote] [quote]</source>. So this is precisely what the function does : given the representation of a function <source lang=apl inline>⍵</source> (itself in this case), and a string <source lang=apl inline>⍺</source>(the quote here), it reproduce the structure `⍵ ⍺ ⍵ ⍺ ⍵ ⍵ ⍵ ⍵`. Another quine is <source lang=apl inline>'{∊⍵ ⍺ ⍵ ⍺ ⍵ ⍵ ⍵ ⍵}'{∊⍵ ⍺ ⍵ ⍺ ⍵ ⍵ ⍵ ⍵}''''</source>, and the only thing to notice on this one is the use of <source lang=apl inline>∊</source> so the result is not a nested array of strings, but a flat string.
The idea behind this quine is that the only thing you need to have a string containing the original code is to reproduce this structure : <source lang=text inline>[quote] [function] [quote] [function] [quote] [quote] [quote] [quote]</source>. So this is precisely what the function does : given the representation of a function <source lang=apl inline>⍵</source> (itself in this case), and a string <source lang=apl inline>⍺</source>(the quote here), it reproduce the structure `⍵ ⍺ ⍵ ⍺ ⍵ ⍵ ⍵ ⍵`. Another quine is <source lang=apl inline>'{∊⍵ ⍺ ⍵ ⍺ ⍵ ⍵ ⍵ ⍵}'{∊⍵ ⍺ ⍵ ⍺ ⍵ ⍵ ⍵ ⍵}''''</source>, and the only thing to notice on this one is the use of <source lang=apl inline>∊</source> so the result is not a nested array of strings, but a flat string.
The quite proposed here is very similar, it only replaces the 4 occurences of <source lang=apl inline>⍵</source> by <source lang=apl inline>4/⍵</source> and deletes the useless spaces for the purpose of golfing.
The quite proposed here is very similar, it only replaces the 4 occurences of <source lang=apl inline>⍵</source> by <source lang=apl inline>4/⍵</source> and deletes the useless spaces for the purpose of golfing.

Revision as of 00:02, 18 May 2022

A quine is a program which takes no input and produces a copy of its own source code as its only output.

In APL, a quine is listed in the FinnAPL idiom library as "an expression giving itself":

      1⌽22⍴11⍴'''1⌽22⍴11⍴'''

In 2019, Nick Nikolov proposed to shorten it using the commute operator:[1]

      1⌽,⍨9⍴'''1⌽,⍨9⍴'''

Explanation:[2]

  • '''1⌽,⍨9⍴''' the characters '1⌽,⍨9⍴'
  • 9⍴ reshape to shape 9, resulting in '1⌽,⍨9⍴''
  • ,⍨ concatenate with itself, resulting in '1⌽,⍨9⍴'''1⌽,⍨9⍴''
  • 1⌽ rotate one character to the left, getting the characters: 1⌽,⍨9⍴'''1⌽,⍨9⍴'''

Further Entries

In 2022, APL Farm user OsKaR31415 shared the following:

      '{∊⍵⍺⍵⍺,4/⍵}'{∊⍵⍺⍵⍺,4/⍵}''''

Explanation : In this code, the main function is {∊⍵⍺⍵⍺,4/⍵}. In this function, the right argument is the literal ', and the left argument is the string containing the representation of the function : '{∊⍵⍺⍵⍺,4/⍵}'. The idea behind this quine is that the only thing you need to have a string containing the original code is to reproduce this structure : [quote] [function] [quote] [function] [quote] [quote] [quote] [quote]. So this is precisely what the function does : given the representation of a function (itself in this case), and a string (the quote here), it reproduce the structure `⍵ ⍺ ⍵ ⍺ ⍵ ⍵ ⍵ ⍵`. Another quine is '{∊⍵ ⍺ ⍵ ⍺ ⍵ ⍵ ⍵ ⍵}'{∊⍵ ⍺ ⍵ ⍺ ⍵ ⍵ ⍵ ⍵}'''', and the only thing to notice on this one is the use of so the result is not a nested array of strings, but a flat string. The quite proposed here is very similar, it only replaces the 4 occurences of by 4/⍵ and deletes the useless spaces for the purpose of golfing.

External links