Hacker News new | past | comments | ask | show | jobs | submit login
Quine (rosettacode.org)
35 points by lelf on Jan 17, 2020 | hide | past | favorite | 19 comments



On of my favorites in this kind of contests (what they funnily enough have an entry for) is HQ9+.

Since it doesn't seem to have a regular English wiki article: It is an esotieric language that is not turing complete but can do pretty much anything that people usually do with esoteric languages. It has 4 opcodes:

H prints "Hello World!".

Q prints the source text of the input program (quine).

9 prints 99 bottles of beer.

+ increments the accumulator.


Since a few people have posted links to language wikis, I clarify: when I said "wiki article" I meant on Wikipedia.

There are articles on Wikipedia in a hand full of languages about HQ9+, but no regular English one (there is one in simplified English tough). I'm surprised there even is a German one, usually people on the German Wikipedia are quite trigger happy with deletion requests and speedy deletions.




You can write a minikanren program that will generate quines.

> We will teach attendees how to use the relational (logic) language miniKanren to write several relational interpreters and reducers capable of automatically synthesizing recursive, symbolic programs, including quines (programs that evaluate to themselves) and fixpoint combinators (such as the famous Y-combinator). https://www.thestrangeloop.com/2014/program-synthesis-using-...

- miniKanren, live and untagged: quine generation via relational interpreters (programming pearl) (http://webyrd.net/quines/quines.pdf) by William E. Byrd, Eric Holk, and Daniel P. Friedman


A very useful application of quines: https://tiddlywiki.com/

Learned about it first from Joe Armstrong: https://joearms.github.io/#


My homepage is a Quine: https://tritarget.org/

It is created using TiddlyWiki


The Racket one is my favorite so far:

((λ (x) `(,x ',x)) '(λ (x) `(,x ',x)))


Wow. I've only really looked at this in C and OO languages. That Racket example distills the quine to its essence in a way I've never seen before. I have to agree with you.


It's arguably the most famous Quine of all, so famous that it has a pompous name! It's called the Omega combinator in lambda calculus, and is a stepping stone to the more famous Y combinator. If you think it's cool, the Y combinator will blow your mind :)


Already explored that one :D


Quines are fun! My favorite generalization is the quine relay: "This is a Ruby program that generates Rust program that generates Scala program that generates ...(through 128 languages in total)... REXX program that generates the original Ruby code again." https://github.com/mame/quine-relay

The same author also has a radiation-hardened quine, which still emits the original quine even if you delete any(!) one character before running it: https://github.com/mame/radiation-hardened-quine

But coming back to traditional quines; the most common solution is of the form:

> The following string followed by itself in quotes: "The following string followed by itself in quotes: "

This is by no means the only possible solution: If you view the compiler/interpreter as a function then a quine is the fixpoint of that function.

So, if your "compiler" is `cat`, the shell identity function, then any string is a quine! A fork bomb is also a kind of quine. The quine there is not the code itself, but a process running the code. That process is "interpreted" by the kernel, which dutifully creates an exact copy of the fork-bomb process.

I've never sat down and tried it, but one day I want to write a quine of the form: "Initialize a PRNG with this seed and print the first n bytes". Probably there's a language which lets you get the required code small enough that you could brute-force the correct seed.


One of my favorite (pseudo?-) quines is the shell script

  #!/usr/bin/cat


That's a cat-script, not a shell-script.


...fair enough. What's the general term for a shebang-ified text executable?


  10 LIST


They had a Quine programme featured in one of the Advent of Code problems (that ran on the VM you built over the course of a few), I really enjoy the links and extra stuff they include in AoC!


TiddlyWiki is still one of the best useful Quines out there!!! https://tiddlywiki.com/#Quine


quine "quine"




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: