{"id":401,"date":"2007-04-27T19:40:47","date_gmt":"2007-04-27T19:40:47","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2007\/04\/27\/true-pathology-a-multilingual-quine\/"},"modified":"2007-04-27T19:40:47","modified_gmt":"2007-04-27T19:40:47","slug":"true-pathology-a-multilingual-quine","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2007\/04\/27\/true-pathology-a-multilingual-quine\/","title":{"rendered":"True Pathology: A Multilingual Quine"},"content":{"rendered":"<p> While browser over at programming.reddit.com, I came across something simultaneously hideous and amazing.<\/p>\n<p>  I&#8217;ve showed quines before as part of the pathological programming posts: a quine is a program which, when run, generates <em>itself<\/em> as an output. I&#8217;ve even written about <a href=\"http:\/\/scientopia.org\/blogs\/goodmath\/2006\/11\/friday-pathological-programming-quine-madness-with-muriel\">a programming language where the only way to create a loop is through quining the program.<\/a> <\/p>\n<p> But I&#8217;ve never seen anything like this before. It&#8217;s a <em>multilingual<\/em> quine: the program below is not just a quine, but it&#8217;s simultaneously a quite in <em>three different languages<\/em>: OCaml, Haskell, and Scheme. I have <em>no idea<\/em> how the author managed to figure out how to do this; and I probably don&#8217;t <em>want<\/em> to. \ud83d\ude42<\/p>\n<p><!--more--><\/p>\n<pre>\n;; (*.) = {- *) let (@@) x y = x::y let e = [] let a = (*\n(letrec ((a '(\n; -} -- *)\n\"                                                                \" @@\n\"                      A polyglot quine in                       \" @@\n\"                   Haskell &amp; O'Caml &amp; Scheme                    \" @@\n\"                        Author: Unknown                         \" @@\n\"                                                                \" @@\n\"  Usage:  runhugs thisfile              # www.haskell.org\/hugs  \" @@\n\"          ocamlc -o x thisfile.ml ;.\/x  # www.ocaml.org         \" @@\n\"          scsh -s thisfile              # www.scsh.net          \" @@\n\"                                                                \" @@\n\"\" @@\n\";; (*.) = {- *) let (@@) x y = x::y let e = [] let a = (*\" @@\n\"(letrec ((a '(\" @@\n\"; -} -- *)\" @@\n\"\" @@\n\" e\" @@\n\";; (*:) = [\" \" ++ show x ++ \" @@\" | x (*\" @@\n\"; *) [],[] | x::y -&gt; if x = \"\" then [],y else let a,b = s y (*\" @@\n\"; *) in x::a,b let b,d = s (snd (s a)) let f = String.escaped (*\" @@\n\"; *) let c = List.map (fun x -&gt; \" \\\"\" ^ f x ^ \"\\\" @@\") a\" @@\n\";; List.iter (fun x -&gt; print_endline x) (b @ c @ d) (*\" @@\n\")) (f (lambda (x) (if (null? x) x (if (string? (car x)) (cons (\" @@\n\"car x) (f (cdr x))) (f (cdr x)))))) (g (lambda (x) (if (string=?\" @@\n\"\"\" (car x)) (cons '() (cdr x)) (let ((y (g (cdr x)))) (cons (\" @@\n\"cons (car x) (car y)) (cdr y)))))) (h (lambda (x) (if (null? x)\" @@\n\"#f (begin (display (car x)) (newline) (h (cdr x)))))) (i (lambda\" @@\n\"(x) (if (null? x) #f (begin (display \" \") (write (car x)) (\" @@\n\"display \" @@\") (newline) (i (cdr x))))))) (let ((b (g (cdr (g\" @@\n\"(f a)))))) (h (car b)) (i (f a)) (h (cdr b))))\" @@\n\"; -} -- *)\" @@\ne\n;; (*:) = [\" \" ++ show x ++ \" @@\" | x (*\n; *) [],[] | x::y -&gt; if x = \"\" then [],y else let a,b = s y (*\n; *) in x::a,b let b,d = s (snd (s a)) let f = String.escaped (*\n; *) let c = List.map (fun x -&gt; \" \"\" ^ f x ^ \"\" @@\") a\n;; List.iter (fun x -&gt; print_endline x) (b @ c @ d) (*\n)) (f (lambda (x) (if (null? x) x (if (string? (car x)) (cons (\ncar x) (f (cdr x))) (f (cdr x)))))) (g (lambda (x) (if (string=?\n\"\" (car x)) (cons '() (cdr x)) (let ((y (g (cdr x)))) (cons (\ncons (car x) (car y)) (cdr y)))))) (h (lambda (x) (if (null? x)\n#f (begin (display (car x)) (newline) (h (cdr x)))))) (i (lambda\n(x) (if (null? x) #f (begin (display \" \") (write (car x)) (\ndisplay \" @@\") (newline) (i (cdr x))))))) (let ((b (g (cdr (g\n(f a)))))) (h (car b)) (i (f a)) (h (cdr b))))\n; -} -- *)\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>While browser over at programming.reddit.com, I came across something simultaneously hideous and amazing. I&#8217;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&#8217;ve even written about a programming language where the only way to create a loop is through quining [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[92],"tags":[],"class_list":["post-401","post","type-post","status-publish","format-standard","hentry","category-pathological-programming"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-6t","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/comments?post=401"}],"version-history":[{"count":0,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/401\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=401"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}