Tell me more ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Produce only the name of a programming language using only the facilities of the language itself. The name of the language can only be invoked indirectly, i.e., from non custom environment variables, built-in functions or methods or the interpreter/compiler of the language. Output should be the name of the language only.

One example would be:

$ awk --v | awk 'NR<2 { print $2}'  # GNU Awk 3.1.8
Awk

The answer I select will be the one with the most up votes. In case of a tie, the shortest golfed version (separate or the only given answer), will be the tie breaker.

share|improve this question
show 11 more comments

72 Answers

1 2 3
up vote 15 down vote accepted

BASH, 17 7

bash -c 'echo $0'

or even

echo ${0#-}

if you already run bash :D

update: "echo $0" gets $0 expanded first so 'echo $0' is the correct answer.

share|improve this answer
show 4 more comments

C

#define d(x) x(#x[3])
void main(){d(putchar);}
share|improve this answer
4  
putchar("putchar"[3]); I must have been an idiot an year ago. – muntoo Apr 1 '12 at 1:50
show 1 more comment

Whitespace

|  	 	 			
	
    		 	   
	
    		 	  	
	
    			 	  
	
    		  	 	
	
    			  		
	
    			    
	
    		    	
	
    		   		
	
    		  	 	
	


|
share|improve this answer
9  
@Alexandru: compsoc.dur.ac.uk/whitespace – dmckee Jul 2 '11 at 0:57
show 6 more comments

J,5

74{a.

Having a short language name does kind of help.

share|improve this answer

Python - 23 22

print`credits`[97:103]
share|improve this answer
2  
you should leave out the space after print – gnibbler Jul 5 '11 at 6:25
3  
Backticks are a deprecated alias for repr(). Backticks are gone in Python 3.x. – 0xKirill Jan 4 '12 at 9:49
show 2 more comments

Python

import sys;print sys.copyright[24:30]

This also works for me (sys.executable is '/usr/bin/python')

import sys;print sys.executable[9:]
share|improve this answer
1  
Here is what i get from these: Active and 25\Lib\site-packages\pythonwin\Pythonwin.exe, so... no good – Nas Banov Mar 7 '11 at 8:12
4  
that's cheating... But I can cheat better: eval.__doc__[144:150] – JBernardo Jul 5 '11 at 5:53
show 1 more comment

brainfuck 101

++++++++[->++++++++++++>+>>++>+++<<<<<]>[->+>+>+>+<<<<]>+>++.>++.<-.<.>>----.<<---.>>>---.<<++.>---.

could probably be golfed slightly further, but it's 6am and I should get some sleep...

share|improve this answer

C

In the spirit of Anon's answer in C (considering a C file always has the extension .c). I'd suggest :

#include <stdio.h>
void main(){puts(__FILE__+sizeof(__FILE__)-2);}
share|improve this answer
5  
Much shorter, 25 chars, single line, main(){puts(__FILE__+2);}, assuming filename is a single letter, eg. a.c – Hasturkun Feb 24 '11 at 15:09

Python (win32) - abuse of the random module

I'm not sure whether this actually works. Depends on the implementation.

print ''.join([(random.seed(835)==None)and'']+[chr(random.randint(64,90)) for x in range(3)]+[(random.seed(53281)==None)and'']+[chr(random.randint(64,90)) for x in range(3)])
share|improve this answer
2  
Good to hear! I wrote a small bruteforcing tool to determine how you need to seed the random module to get a certain sequence. With a three-character sequence, this doesn't take too long - this script joins together two three-letter sequences to get "PYTHON" :) – zhazam Aug 15 '11 at 13:24
show 4 more comments

C

Built using DevStudio 2005

#include <stdio.h>
void main ()
{
  int i,j,i2;
  for (i=j=0,i2=200;i2<=200;i2-=19,j==putchar(32|(i2<'Q'&&i2>'+'&&(j<20||i<12||i>28))*3)+8?j=0,i2+=i,i+=putchar('\n')-8:(i2+=j,j+=2));
}

Slightly shorter version (with compiler warnings)

int i,j,k;
for (i=j=k=0;k<=0;k-=19,j==putchar(32|(k<-119&&k>-157&&j<20|i<12|i>28)*3)+8?j=0,k+=i,i+=putchar('\n')-8:(k+=j,j+=2));
share|improve this answer
show 3 more comments

cat 3

Create a file with the following content (source code)

cat

And run it like (execute the file):

$ cat filename
share|improve this answer
3  
Neither indirect nor a language? – eternalmatt Jul 22 '11 at 22:35
4  
Cat isn't a real language, because it isn't Turing-complete. – kinokijuf Dec 25 '11 at 11:36
1  
@kinokijuf There are plenty of useful languages which are not Turing-complete. See stackoverflow.com/q/8412741/20713 for a partial list. – ephemient Mar 27 '12 at 6:43
2  
@ephemient: Cat is not only not turing complete, it isn't a language at all. It has no syntax, no grammer, no keywords. I don't know where bitmask got his definition - I don't follow it. – user unknown Mar 27 '12 at 10:55
1  
@userunknown It's hard to imagine cat being a language, and besides this violates the spirit of the question (uses the language name directly). My comment was to refute the idea that "Cat isn't a real language, because it isn't Turing-complete". It isn't a language for other reasons, but Turing-completeness isn't a good deciding factor. – ephemient Mar 28 '12 at 4:08
show 2 more comments

Piet, 47x2 pixels

Using 5x5 codels: Piet program to print "Piet"

share|improve this answer

Java

public class Name {
    public static void main(String[] args) {
        String s = "";
        s = s.getClass().getName();
        s = s.substring(0, 1).toUpperCase() + s.substring(1, 4);
        System.out.println(s);
    }
}
share|improve this answer
show 1 more comment

Clojure - 16 chars

(subs(str =)0 7)
share|improve this answer

Brainfuck

>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
++++++++++++++++++++++++++++++++++++++++++++++++.
-----------------.
++++++++.
+++++.
--------.
+++++++++++++++.
------------------.
++++++++.
share|improve this answer
1  
you can make smaller with [...]: ++++++++++[>++++++>++++++++++>+++++++++++>++++<<<<-]>++++++.>>++++.<---.++++++++‌​.+++++.--------.>>++.*<<---.++++++++. – JBernardo Jul 7 '11 at 0:27
6  
This looks like typical Git output. – Joey Adams Jul 7 '11 at 3:34
show 7 more comments

Scala — 42

print(((1,1).getClass+"").substring(6,11))

Update — 39 chars

print(('a.getClass+"").substring(6,11))
share|improve this answer
show 5 more comments

C - 34

I don't have enough reputation to add this as a comment to the previous C entry. Same idea as above, but the filename can be anything.c

main(){puts(index(__FILE__,0)-1);}
share|improve this answer
1  
Gah, but now I can't name my files "&raquo;\0<3ASCII.c" – walpen Jun 13 '12 at 0:50

Ruby - 27

puts RUBY_DESCRIPTION[0..3]

Update from Chris Jester-Young's comment:

Ruby - 24

puts RUBY_COPYRIGHT[0,4]

Updated from Hauleth:

Ruby - 15

p`ruby -v`[0,4]
share|improve this answer
show 2 more comments

Visual Basic (version 6.0)

MsgBox Right(Error(458), 12)

VBScript

On Error Resume Next
Err.Raise 458
MsgBox Right(Err.Description, 8)

Both VB6 and VBScript

On Error Resume Next
Err.Raise 458
D = Err.Description
MsgBox Mid(D, InStr(2, D, "V"))
share|improve this answer
show 1 more comment

QBasic (37)

I am using version 1.1 of the QBasic interpreter.

FOR x=0TO 5:?CHR$(PEEK(2588+x));:NEXT
share|improve this answer

Perl

$^X=~/([a-z]+)[^\/]+$/;print$1,$/
share|improve this answer
1  
@BioGeek: Is your Perl binary called per? – ninjalj Jul 3 '11 at 6:42
1  
I also get per. (My $^X says /usr/bin/perl. The [^\/]+ swallows the l.) – Ilmari Karonen Dec 12 '11 at 22:35
show 2 more comments

Lua 25 Chars

print(arg[-1]:match"%w+")

Or, analogue to the J B's J solution 17 chars:

print"\76\117\97"
share|improve this answer
show 1 more comment

GolfScript (13)

"#{$0[0..9]}"
share|improve this answer
show 2 more comments

D(52)

using the extension of the source file

import std.stdio;void main(){write(__FILE__[$-1]);}
share|improve this answer

><> (Fish) (11)

Even better:

'>'::o2-oo;
share|improve this answer

Haskell, 47

data H=Haskell deriving Show
main=print Haskell
share|improve this answer

Ruby

Not short, but very indirectly.

4.times{|x|print((82+11.24*x+8.231*Math.tan(111.2*x)).floor.chr)}
share|improve this answer

PHP

php -v|php -r'echo fread(STDIN,3);'
share|improve this answer

Assembler

Assembled using A86, generates a Windows .COM (tested on XP)

inc cx
push bx
push bx
inc bp
dec bp
inc dx
dec sp
inc bp
push dx
and al,72
mov ah,9
mov dx,si
inc sp
pop si
pop cx
int 21h
ret
share|improve this answer
5  
There is no such thing as a »Windows .COM« :-) – Joey May 5 '11 at 7:14

Racket (45)

racket -e "(display(substring(banner)10 17))"
share|improve this answer
1 2 3

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.