Quines — exercise idea

I just learnt about quines — self-replicating programs.

Write a program that outputs its own source code.
You are not allowed to read any external files with the source code.
Empty programs producing no output or constant expressions are not allowed.

These seem a playful way to get to grips with:

  • quoting constructs
  • string escaping
  • source code representations / self-referencing

I imagine the tests would have to get creative, since we’d not have the usual input-output checks but rather just checking if the (non-empty, non-constant) input matches the output exactly.

Has this idea been floated before ? Does it sound like a fun addition ? :playground_slide:

1 Like

This could be fun … but I’m not sure how you’d fit it into the existing problem spec model and TDD approach.

I don’t think a quine makes sense for Exercism, as they explore edge case behaviour and not fluency in a language.

To test a quine, you need to compare the source file with the output of the thing it contains. A quine shall reproduce it’s own source code, not some source you hand it. That would be a quine generator - much much harder.