Haskell - WITHOUT loading source - 478 644 characters
This assumes getContents ALWAYS ends with a newline and so drops the final character without checking because I don't feel like escaping it
A
main=interact$($'1').replicate.(1-).fromEnum.(/=map r(d++shows d[toEnum 10]))where r n|n=='-'='*'|n=='*'='-'|True=n;d="main=interact$($'1').replicate.(1-).fromEnum.(/=map r(d++shows d[toEnum 10]))where r n|n=='-'='*'|n=='*'='-'|True=n;d="
B
main=interact$($'1').replicate.(1*).fromEnum.(/=map r(d++shows d[toEnum 10]))where r n|n=='*'='-'|n=='-'='*'|True=n;d="main=interact$($'1').replicate.(1*).fromEnum.(/=map r(d++shows d[toEnum 10]))where r n|n=='*'='-'|n=='-'='*'|True=n;d="
It works like a standard quine, but swapping - for * to get the other program (avoiding those characters elsewhere).
The following test prints as expected (replacing main=interact$ with a= and b=)
main=do
putStrLn "START"
putStrLn$a "FOO"
putStrLn$a "main=interact$($'1').replicate.(1*).fromEnum.(/=map r(d++shows d[toEnum 10]))where r n|n=='*'='-'|n=='-'='*'|True=n;d=\"main=interact$($'1').replicate.(1*).fromEnum.(/=map r(d++shows d[toEnum 10]))where r n|n=='*'='-'|n=='-'='*'|True=n;d=\"\n"
putStrLn$b "FOO"
putStrLn$b "main=interact$($'1').replicate.(1-).fromEnum.(/=map r(d++shows d[toEnum 10]))where r n|n=='-'='*'|n=='*'='-'|True=n;d=\"main=interact$($'1').replicate.(1-).fromEnum.(/=map r(d++shows d[toEnum 10]))where r n|n=='-'='*'|n=='*'='-'|True=n;d=\"\n"
putStrLn "END"
-
START
1
1
END
3Is this quine-ish enough to tag it as [tag:quine]? It certainly seems so to me. – Justin – 2014-01-09T20:26:40.903
As the first two answers posted indicate, "being" another program is not terribly well defined in this descriptions. And, I'm with @Quincunx that this has something very much like the quine-nature. – dmckee --- ex-moderator kitten – 2014-01-09T22:25:52.940
@Quincunx I've added the quine tag. – Timtech – 2014-01-09T23:45:04.763
when you say it takes a program as input, do you mean it takes that program's source code as input or that program's output? – markasoftware – 2014-01-10T00:20:14.643
@Markasoftware The source code as input. – ike – 2014-01-10T00:29:17.503
@Quincunx A quine is a computer program which takes no input and produces a copy of its own source code as its only output. Neither program A nor B do that. – Brian Rogers – 2014-01-10T02:52:50.710
@BrianRogers However, to solve this problem, you have to use the same concept behind a quine. – Justin – 2014-01-10T03:21:01.467
1@Quincunx true, but nobody is doing that so far, unless you also call a quine any program that reads its source code from disk and prints it out :p – aditsu quit because SE is EVIL – 2014-01-10T04:59:04.293
2@aditsu I much dislike those answers. I think I'll post a very suboptimal answer that does not do that. I personally feel that reading source code through files is cheating; programs should work anywhere! – Justin – 2014-01-10T05:11:08.173
Ugh, my suboptimal answer is very difficult to debug. My head hurts like crazy – Justin – 2014-01-10T06:05:44.307
@Quincunx, I hear what you're saying about programs here that read their peers' code from disk. It's a shortcut, for sure. But consider a very real advantage: with such an approach, when you change code in A, you do not need to change B. The "purist" approach I think you're describing leaves both programs co-dependent on each other, doesn't it? i.e. if you make any to change A then you must also change B. Referencing is not as clever, but it is robust. :) – Darren Stone – 2014-01-10T09:40:35.990