Quine: Difference between revisions

Jump to navigation Jump to search
1,173 bytes added ,  09:55, 30 June 2022
Line 18: Line 18:


== Further Entries ==
== Further Entries ==
 
=== Replicate ===
In 2022, [[APL Farm]] user OsKaR31415 shared the following:<ref>[https://discord.com/channels/821509511977762827/821511138184396840/976205210580037662 Transcript for 2022-05-17] [[APL Farm]]</ref>
In May 2022, [[APL Farm]] user OsKaR31415 shared the following:<ref>[https://discord.com/channels/821509511977762827/821511138184396840/976205210580037662 Transcript]. [[APL Farm]]. 2022-05-17.</ref>
<source lang=apl>
<source lang=apl>
       '{∊⍵⍺⍵⍺,4/⍵}'{∊⍵⍺⍵⍺,4/⍵}''''
       '{∊⍵⍺⍵⍺,4/⍵}'{∊⍵⍺⍵⍺,4/⍵}''''
</source>
</source>
Explanation:
==== Explanation ====


In this code, the main function is <source lang=apl inline>{∊⍵⍺⍵⍺,4/⍵}</source> with the right argument <source lang=apl inline>⍵</source> being single quote literal (spelled with four quotes, <source lang=apl inline>''''</source>, because single quotes delimit APL character literals, and quotes inside such must be doubled), and the left argument <source lang=apl inline>⍺</source> being the character vector representation of the function (<source lang=apl inline>'{∊⍵⍺⍵⍺,4/⍵}'</source>).
In this code, the main function is <source lang=apl inline>{∊⍵⍺⍵⍺,4/⍵}</source> with the right argument <source lang=apl inline>⍵</source> being single quote literal (spelled with four quotes, <source lang=apl inline>''''</source>, because single quotes delimit APL character literals, and quotes inside such must be doubled), and the left argument <source lang=apl inline>⍺</source> being the character vector 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: [quote] [function] [quote] [function] [quote] [quote] [quote] [quote]. This is precisely what the function does. Given the representation of a function <source lang=apl inline>⍺</source> (itself in this case), and character <source lang=apl inline>⍵</source> (here, the quote), it produces the structure <source lang=apl inline>⍵ ⍺ ⍵ ⍺ ⍵ ⍵ ⍵ ⍵</source>. A more explicit version would be <source lang=apl inline>'{⍵,⍺,⍵,⍺,⍵,⍵,⍵,⍵}'{⍵,⍺,⍵,⍺,⍵,⍵,⍵,⍵}''''</source> which simply concatenates together the required parts. The original quine is very similar, only using the shorter <source lang=apl inline>4/⍵</source> to produce the 4 occurrences of <source lang=apl inline>⍵</source>, and [[code golf|golfs]] away the spaces, instead opting for [[Enlist]] (<source lang=apl inline>∊</source>) to flatten the intermediary [[nested array]].
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]. This is precisely what the function does. Given the representation of a function <source lang=apl inline>⍺</source> (itself in this case), and character <source lang=apl inline>⍵</source> (here, the quote), it produces the structure <source lang=apl inline>⍵ ⍺ ⍵ ⍺ ⍵ ⍵ ⍵ ⍵</source>. A more explicit version would be <source lang=apl inline>'{⍵,⍺,⍵,⍺,⍵,⍵,⍵,⍵}'{⍵,⍺,⍵,⍺,⍵,⍵,⍵,⍵}''''</source> which simply concatenates together the required parts. The original quine is very similar, only using the shorter <source lang=apl inline>4/⍵</source> to produce the 4 occurrences of <source lang=apl inline>⍵</source>, and [[code golf|golfs]] away the spaces, instead opting for [[Enlist]] (<source lang=apl inline>∊</source>) to flatten the intermediary [[nested array]].
=== <source lang=apl inline>⎕UCS</source> ===
In Jun 2022, [[Jay Foad]] shared the following:<ref>Message {{M|61482904}}. [[APL Orchard]]. 2022-06-30.</ref>
<source lang=apl>
      {,⍨⍵,⎕UCS 39}'{,⍨⍵,⎕UCS 39}'
</source>
==== Explanation ====
In this code, the main function is <source lang=apl inline>{,⍨⍵,⎕UCS 39}</source> with the argument <source lang=apl inline>⍵</source> being the function itself which avoids duplication of quotes by generating the quote from its [[Universal Character Set]] code point (<source lang=apl inline>⎕UCS</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: [function] [quote] [function] [quote]. This is precisely what the function does. Given the representation of a function <source lang=apl inline>⍵</source> (itself in this case), it generates a quote and concatenates it on the right of the function definition, giving [function] [quote]. It then uses [[commute|self]]-[[catenate|concatenation]] (<source lang=apl inline>,⍨</source>) to repeat the two parts into the required four.


== External links ==
== External links ==

Navigation menu