The meta-polyglot quine

CJam / Fission, 22 bytes

"'!+OR'")5-"{'_'~}_~";

Try it in CJam. Try it in Fission.

In CJam, this prints the standard Fission quine:

'!+OR"

Try the Fission quine.

In Fission, this prints a "-less variant of the standard CJam quine:

{'_'~}_~

Try the CJam quine.

This also works for 22 bytes (printing the same quines):

"& *NQ!":)R"{'_'~}_~";

Explanation

In CJam:

"'!+OR'"    e# Push this string.
)           e# Pull off the last character.
5-          e# Subtract 5, turning ' into ".
"{'_'~}_~"  e# Push this string.
;           e# And discard it again.

So at the end of the program, the stack contains the string "'!+OR" and the character ", both of which are implicitly printed.

In Fission, program flow starts at the R with a right-going atom. '" just changes the atoms mass, ), 5 and - are ignored for various reasons. Then the atom enters print mode at the " and prints {'_'~}_~. ; destroys the atom and terminates the program.


Clojure / Common Lisp, 274 bytes

(defmacro t []"((fn [s] (print (list s (list (quote quote) s)))) (quote (fn [s] (print (list s (list (quote quote) s))))))")(if '()(print(let[s clojure.string/replace](.toUpperCase(s(s(s(s(s(t)"fn""lambda")"[s]""(s)")"(quote ""'")"e)""e")")))))""))))"))))(eval '(princ(t))))

Some spaces added for readability

(defmacro t []"((fn [s] (print (list s (list (quote quote) s))))
     (quote (fn [s] (print (list s (list (quote quote) s))))))")
(if '()(print(let[s clojure.string/replace](.toUpperCase
    (s(s(s(s(s(t)"fn""lambda")"[s]""(s)")"(quote ""'")"e)""e")")))))""))))"))))
    (eval '(princ(t))))

Basically defines a macro which returns a quine in Clojure. Clojure requires parameters for macro definition provided as vector ([]) whereas Common Lisp (thankfully) just ignores it. After that we differ 2 languages by evaluating '() which equals to nil and thus falsey in Common Lisp and is true in Clojure. Then we do string manipulations using Clojure which Common Lisp doesn't even try to evaluate as it goes in another if branch. Clojure on the other hand tries to check if another branch is at least correct before executing so had to use eval there to both be correct in Clojure and output correct string in Common Lisp.

Note: just returning two different string might probably be shorter but then it won't be different to a polyglot challenges about outputing different strings in different languages. ¯\_(ツ)_/¯

Clojure original source run: https://ideone.com/SiQhPf

Common Lisp original source run: https://ideone.com/huLcty

Clojure output : ((LAMBDA (S) (PRINT (LIST S (LIST 'QUOTE S)))) '(LAMBDA (S) (PRINT (LIST S (LIST 'QUOTE S)))))

Common Lisp output : ((fn [s] (print (list s (list (quote quote) s)))) (quote (fn [s] (print (list s (list (quote quote) s))))))

Clojure output run in Common Lisp: https://ideone.com/T1DF7H

Vice versa: https://ideone.com/Fezayq


CJam 0.6.6 dev / GolfScript, 15 14 12 bytes

"0$p"0$~a:n;

Thanks to @jimmy23013 for golfing off 2 bytes!

Rest to be updated.

Verification

Since the submission involves significant whitespace, it's best to compare hexdumps.

$ xxd -g 1 mpquine
0000000: 22 60 30 24 7e 22 30 24 7e 4e 4d 3a 6e 3b        "`0$~"0$~NM:n;
$
$ cjam mpquine | tee quine.gs | xxd -g 1
0000000: 22 60 30 24 7e 22 60 30 24 7e 0a                 "`0$~"`0$~.
$ golfscript quine.gs | xxd -g 1
0000000: 22 60 30 24 7e 22 60 30 24 7e 0a                 "`0$~"`0$~.
$ cjam quine.gs | xxd -g 1
0000000: 22 60 30 24 7e 22 60 30 24 7e                    "`0$~"`0$~
$
$ golfscript mpquine | tee quine.cjam | xxd -g 1
0000000: 22 60 30 24 7e 22 60 30 24 7e                    "`0$~"`0$~
$ cjam quine.cjam | xxd -g 1
0000000: 22 60 30 24 7e 22 60 30 24 7e                    "`0$~"`0$~
$ golfscript quine.cjam | xxd -g 1
0000000: 22 60 30 24 7e 22 60 30 24 7e 0a                 "`0$~"`0$~.

CJam

CJam prints "`0$~"0$~ and a trailing linefeed. Try it online!

The generated program prints "`0$~"0$~ with the trailing linefeed in GolfScript (Try it online!), but without the linefeed in CJam (Try it online!).

How the metaquine works

"`0$~"         e# Push that string on the stack.
      0$~      e# Push a copy and evaluate it:
               e#   `     Inspect the string, pushing "\"`0$~\"".
               e#    0$   Push a copy.
               e#      ~  Evaluate, pushing "`0$~".
               e# Both "\"`0$~\"" and "`0$~" are now on the stack.
         NM    e# Push "\n" and "".
           :n; e# Map print over the elements of "" (none) and pop the result.
               e# "\"`0$~\"", "`0$~", and "\n" are now on the stack, and the
               e# characters they represent will be printed implicitly.

How the quine works

"`0$~"          # Push that string on the stack.
      0$~       # As in CJam.
         <LF>   # Does nothing.
                # "\"`0$~\"" and "`0$~" are now on the stack, and the characters
                # they represent will be printed implicitly, plus a linefeed.

Unlike GolfScript, CJam doesn't print a trailing linefeed by default, so this is not a quine in CJam.

GolfScript

GolfScript prints "`0$~"0$~, without trailing whitespace. Try it online!

The generated program prints "`0$~"0$~ without trailing whitespace in CJam (Try it online!), but GolfScript appends a linefeed (Try it online!).

How the metaquine works

"`0$~"0$~       # As in CJam.
         NM     # Unrecognized token. Does nothing.
           :n   # Store the top of the stack – "`0$~" – in the variable n. n holds
                # "\n" by default. When the program finishes, the interpreter
                # prints n implicitly, usually resulting in a trailing linefeed.
                # By redefining n, it will print "0$~" instead.
             ;  # Pop the string from the stack so it won't be printed twice.

How the quine works

"`0$~"0$~      e# Works as in GolfScript.

Unlike CJam, GolfScript will append a linefeed to the contents of the stack, so this is not a quine in GolfScript.