Interpret your lang, but not yourself?

Perl, 89 chars, no cheating

$_=q($_=q(Q);s/Q/$_/;($q=join"",<>)eq$_?die:eval$q);s/Q/$_/;($q=join"",<>)eq$_?die:eval$q

Note that this code is extremely picky about what counts as "itself". In particular, it will not recognize itself if there are any trailing newlines or other extra whitespace in the input. To test it, save it into a file named (for example) unquine.pl and do this:

$ perl unquine.pl unquine.pl
Died at unquine.pl line 1, <> line 1.

Remember, the unquine.pl file should be exactly 89 bytes long, no more, no less. Running it with some other Perl script as input just executes the other script, as it should:

$ perl unquine.pl hello.pl
Hello, world!

As the name might suggest, the implementation is based on a quine — specifically, this one:

$_=q($_=q(Q);s/Q/$_/);s/Q/$_/

This code sets $_ equal to itself; the rest of the program (which, of course, must be duplicated inside $_) just compares $_ to the input, dies if they match and evaluates the input otherwise.


Ruby, 63

b=$<.read
t="b=$<.read\nt=%p\nb!=t%%t&&eval(b)"
b!=t%t&&eval(b)

Python, 167 130 118 bytes

This is my first attempt at golfing, so here goes! It interprets any program except itself

Improved version:

i=open(raw_input()).read();q='i=open(raw_input()).read();q=%s;i==q%%repr(q)and a;exec(i)\n';i==q%repr(q)and a;exec(i)

If it gets itself then it barfs with:

Traceback (most recent call last):
  File "pygolf.py", line 1, in <module>
    i=open(raw_input()).read();q='i=open(raw_input()).read();q=%s;i==q%%repr(q)and a;exec(i)\n';i==q%repr(q)and a;exec(i)
NameError: name 'a' is not defined

I think this solution works pretty much the same way as Ilmari Karonen's, the basic idea is something like:

input = read_some_file()
if input == some_quine()
    barf()
interpret(input)

The quine I used was based on this one:

(lambda x: x + repr((x,)))('(lambda x: x + repr((x,)))',)

But I since realized a much shorter quine is:

q='q=%s;q%%repr(q)';q%repr(q)

And that can be even shorter if you allow the interactive python shell, in which case you can do:

'%s;_%%repr(_)';_%repr(_)

Since python doesn't have a short way to get command line args, I went with raw_input() (which is still pretty long, but not as long as

import sys;sys.argv[1]

Usage is:

echo "foobar.py" | python quinterpretter.py

or

python quinterpretter.py
<type filename and hit enter>

I found a shorter quine to use, but here is my old version (for posterity):

i=open(raw_input()).read();a if i==(lambda x,y:x+repr((x,y))+y)('i=open(raw_input()).read();a if i==(lambda x,y:x+repr((x,y))+y)', ' else 1;exec(i)\n') else 1;exec(i)