While browser over at programming.reddit.com, I came across something simultaneously hideous and amazing.

I’ve showed quines before as part of the pathological programming posts: a quine is a program which, when run, generates *itself* as an output. I’ve even written about a programming language where the only way to create a loop is through quining the program.

But I’ve never seen anything like this before. It’s a *multilingual* quine: the program below is not just a quine, but it’s simultaneously a quite in *three different languages*: OCaml, Haskell, and Scheme. I have *no idea* how the author managed to figure out how to do this; and I probably don’t *want* to.

;; (*.) = {- *) let (@@) x y = x::y let e = [] let a = (* (letrec ((a '( ; -} -- *) " " @@ " A polyglot quine in " @@ " Haskell & O'Caml & Scheme " @@ " Author: Unknown " @@ " " @@ " Usage: runhugs thisfile # www.haskell.org/hugs " @@ " ocamlc -o x thisfile.ml ;./x # www.ocaml.org " @@ " scsh -s thisfile # www.scsh.net " @@ " " @@ "" @@ ";; (*.) = {- *) let (@@) x y = x::y let e = [] let a = (*" @@ "(letrec ((a '(" @@ "; -} -- *)" @@ "" @@ " e" @@ ";; (*:) = [\" \" ++ show x ++ \" @@\" | x<-( *.)]; main = {-" @@ "; -} sequence_ (map putStrLn (x ++ ( *:) ++ y)); (x, _:y) = {-" @@ "; -} span p (tail (dropWhile p ( *.))); p = (/= \"\"); infixr {-" @@ "; -} @@; (@@) = (:); e = [] {- *) let rec s = function [] -> (*" @@ "; *) [],[] | x::y -> if x = \"\" then [],y else let a,b = s y (*" @@ "; *) in x::a,b let b,d = s (snd (s a)) let f = String.escaped (*" @@ "; *) let c = List.map (fun x -> \" \\\"\" ^ f x ^ \"\\\" @@\") a" @@ ";; List.iter (fun x -> print_endline x) (b @ c @ d) (*" @@ ")) (f (lambda (x) (if (null? x) x (if (string? (car x)) (cons (" @@ "car x) (f (cdr x))) (f (cdr x)))))) (g (lambda (x) (if (string=?" @@ "\"\" (car x)) (cons '() (cdr x)) (let ((y (g (cdr x)))) (cons (" @@ "cons (car x) (car y)) (cdr y)))))) (h (lambda (x) (if (null? x)" @@ "#f (begin (display (car x)) (newline) (h (cdr x)))))) (i (lambda" @@ "(x) (if (null? x) #f (begin (display \" \") (write (car x)) (" @@ "display \" @@\") (newline) (i (cdr x))))))) (let ((b (g (cdr (g" @@ "(f a)))))) (h (car b)) (i (f a)) (h (cdr b))))" @@ "; -} -- *)" @@ e ;; (*:) = [" " ++ show x ++ " @@" | x<-( *.)]; main = {- ; -} sequence_ (map putStrLn (x ++ ( *:) ++ y)); (x, _:y) = {- ; -} span p (tail (dropWhile p ( *.))); p = (/= ""); infixr {- ; -} @@; (@@) = (:); e = [] {- *) let rec s = function [] -> (* ; *) [],[] | x::y -> if x = "" then [],y else let a,b = s y (* ; *) in x::a,b let b,d = s (snd (s a)) let f = String.escaped (* ; *) let c = List.map (fun x -> " \"" ^ f x ^ "\" @@") a ;; List.iter (fun x -> print_endline x) (b @ c @ d) (* )) (f (lambda (x) (if (null? x) x (if (string? (car x)) (cons ( car x) (f (cdr x))) (f (cdr x)))))) (g (lambda (x) (if (string=? "" (car x)) (cons '() (cdr x)) (let ((y (g (cdr x)))) (cons ( cons (car x) (car y)) (cdr y)))))) (h (lambda (x) (if (null? x) #f (begin (display (car x)) (newline) (h (cdr x)))))) (i (lambda (x) (if (null? x) #f (begin (display " ") (write (car x)) ( display " @@") (newline) (i (cdr x))))))) (let ((b (g (cdr (g (f a)))))) (h (car b)) (i (f a)) (h (cdr b)))) ; -} -- *)