40
\$\begingroup\$

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.

\$\endgroup\$
11
  • 1
    \$\begingroup\$ so using Java reflection API is not OK? \$\endgroup\$
    – Ming-Tang
    Feb 21, 2011 at 1:15
  • \$\begingroup\$ I didn't think of that, but that's okay too. \$\endgroup\$
    – Ty Auvil
    Feb 21, 2011 at 12:20
  • \$\begingroup\$ @George: Huh? Is that now a code-golf? Why? It wasn't before ... \$\endgroup\$
    – Joey
    Feb 21, 2011 at 19:03
  • \$\begingroup\$ @Joey: No it wasn't before, but it seemed like a code golf question, so I edited it and someone approved the edit. \$\endgroup\$ Feb 21, 2011 at 19:35
  • \$\begingroup\$ @Joey: Code Golf is the tie breaker. I didn't put that TAG on originally, but George suggested it and I agreed. \$\endgroup\$
    – Ty Auvil
    Feb 21, 2011 at 23:11

86 Answers 86

31
\$\begingroup\$

Whitespace

|  	 	 			
	
    		 	   
	
    		 	  	
	
    			 	  
	
    		  	 	
	
    			  		
	
    			    
	
    		    	
	
    		   		
	
    		  	 	
	


|
\$\endgroup\$
7
  • \$\begingroup\$ Not a real language, whitespace. \$\endgroup\$
    – Alexandru
    Jul 2, 2011 at 0:11
  • 23
    \$\begingroup\$ @Alexandru: compsoc.dur.ac.uk/whitespace \$\endgroup\$ Jul 2, 2011 at 0:57
  • \$\begingroup\$ Argh. Sorry Anthony, SE doesn't let me upvote you now. \$\endgroup\$
    – Alexandru
    Jul 2, 2011 at 14:10
  • \$\begingroup\$ That's all right. I myself have recently learned about this language. \$\endgroup\$
    – Anthony
    Jul 2, 2011 at 19:49
  • 1
    \$\begingroup\$ If I'm not mistaken, your program has two fatal errors: (1) Letting S,T,L denote Space,Tab,Linefeed repsectively, the first instruction is at present SSTSTSTTTL, but should be SSSTSTSTTTL (3 S's on the left) -- the 3rd S is needed to indicate the positive sign of the binary number following it (i.e. the ascii code for 'W' = 85 = 1010111 in binary, coded as the L-terminated string TSTSTTTL), and so on for the other ascii codes. (2) The prog's final TLLL should be TLSSLLL, where the TLSS is needed to output the final character from the stack, and LLL marks the end-of-program. \$\endgroup\$
    – r.e.s.
    Mar 29, 2012 at 0:56
26
\$\begingroup\$

C

#define d(x) x(#x[3])
void main(){d(putchar);}
\$\endgroup\$
3
  • \$\begingroup\$ putchar((int)(putchar)+3); \$\endgroup\$ Mar 12, 2011 at 23:04
  • 24
    \$\begingroup\$ putchar("putchar"[3]); I must have been an idiot an year ago. \$\endgroup\$ Apr 1, 2012 at 1:50
  • \$\begingroup\$ Use the main parameter. main(a){putchar(a+66);} \$\endgroup\$
    – user85052
    Nov 16, 2019 at 12:54
23
\$\begingroup\$

Python - 23 22

print`credits`[97:103]
\$\endgroup\$
4
  • 2
    \$\begingroup\$ you should leave out the space after print \$\endgroup\$
    – gnibbler
    Jul 5, 2011 at 6:25
  • \$\begingroup\$ What does the ` do? I've never seen that. \$\endgroup\$
    – Kazark
    Jan 1, 2012 at 4:13
  • 5
    \$\begingroup\$ Backticks are a deprecated alias for repr(). Backticks are gone in Python 3.x. \$\endgroup\$
    – Kirill
    Jan 4, 2012 at 9:49
  • 2
    \$\begingroup\$ @0xKir So? Use them in code golf 'till they're gone. \$\endgroup\$
    – Riking
    May 24, 2013 at 14:34
23
\$\begingroup\$

J,4

u:74

Having a short language name does kind of help.

\$\endgroup\$
1
  • \$\begingroup\$ Can be even shorter : u:74 \$\endgroup\$
    – jpjacobs
    Feb 24, 2014 at 12:13
19
\$\begingroup\$

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)])
\$\endgroup\$
5
  • \$\begingroup\$ How did you find that? It also works for me in Python 2.6.6 on linux. \$\endgroup\$ Aug 5, 2011 at 2:42
  • 5
    \$\begingroup\$ 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" :) \$\endgroup\$
    – zhazam
    Aug 15, 2011 at 13:24
  • \$\begingroup\$ The rest is using list comprehensions and other dirty tricks to get it to fit it in one line. You can find the bruteforcing tool here :) \$\endgroup\$
    – zhazam
    Aug 15, 2011 at 13:30
  • \$\begingroup\$ And it works on my Python 3.1.2 (adding parentheses after print, of course). \$\endgroup\$ Aug 16, 2011 at 20:18
  • 1
    \$\begingroup\$ Almost there: generateSentence(50613, 73)[66:] gives 'PYTHOCN'. \$\endgroup\$ Aug 16, 2011 at 20:45
18
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ It's only dash-prefixed if it's a login shell and it's not a login shell if it's the one that runs your program. \$\endgroup\$
    – J B
    Feb 22, 2011 at 20:02
  • \$\begingroup\$ @JB: thanks for pointing that out. I was using "s where I should have 's \$\endgroup\$
    – Eelvex
    Feb 22, 2011 at 20:10
  • \$\begingroup\$ Looks like this is the winner. :) \$\endgroup\$
    – Ty Auvil
    Feb 28, 2011 at 23:59
  • \$\begingroup\$ echo ${SHELL:5} \$\endgroup\$ May 18, 2012 at 9:27
17
\$\begingroup\$

BrainFuck

Just for fun (I know this isn't related to the purpose of the task.), I wrote this code...

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

And when I replaced <,>,[,],. with space...

+++++   -+-+-     ++    +++++  +     +
+    +  +    +   -  +     +    ++    -   
+    +  +    -  +    +    +    - -   - 
+++++   +++++   ------    +    -  +  - 
+    +  +    +  +    -    -    -   + -  
+    +  +    -  -    -    -    -    -+ 
++---   +    +  +    -  +++++  +     - 

+++  + +  +++  + + 
-    + +  +    ++ 
+++  + +  +    + 
+    + -  +    ++
+    ++-  -+-  + +


---  
---
---
---

 - 
---
 - 
\$\endgroup\$
13
\$\begingroup\$

Piet, 47x2 pixels

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

\$\endgroup\$
12
\$\begingroup\$

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:]
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Here is what i get from these: Active and 25\Lib\site-packages\pythonwin\Pythonwin.exe, so... no good \$\endgroup\$
    – Nas Banov
    Mar 7, 2011 at 8:12
  • \$\begingroup\$ import sys;print sys.subversion[0][1:] works though \$\endgroup\$
    – Nas Banov
    Mar 7, 2011 at 8:19
  • 6
    \$\begingroup\$ that's cheating... But I can cheat better: eval.__doc__[144:150] \$\endgroup\$
    – JBernardo
    Jul 5, 2011 at 5:53
11
\$\begingroup\$

brainfuck 101

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

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

\$\endgroup\$
11
\$\begingroup\$

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);}
\$\endgroup\$
1
  • 5
    \$\begingroup\$ Much shorter, 25 chars, single line, main(){puts(__FILE__+2);}, assuming filename is a single letter, eg. a.c \$\endgroup\$
    – Hasturkun
    Feb 24, 2011 at 15:09
7
\$\begingroup\$

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);
    }
}
\$\endgroup\$
1
  • \$\begingroup\$ anon: Just submit another answer. This isn't a golf, so no need to keep it short. \$\endgroup\$
    – Joey
    Jul 1, 2011 at 7:44
6
\$\begingroup\$

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));
\$\endgroup\$
2
  • \$\begingroup\$ first one will produce warning about main not being of type int using gcc. \$\endgroup\$
    – Rommudoh
    Aug 16, 2011 at 7:28
  • 1
    \$\begingroup\$ You are not allowed to use the letter 'c'. \$\endgroup\$
    – kinokijuf
    Dec 25, 2011 at 11:29
6
\$\begingroup\$

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]
\$\endgroup\$
2
  • \$\begingroup\$ 1. RUBY_COPYRIGHT is shorter than RUBY_DESCRIPTION. 2. [0,4] is shorter than [0..3]. \$\endgroup\$ Mar 11, 2011 at 8:56
  • \$\begingroup\$ Even shorter ```ruby -v`[0,4]`` \$\endgroup\$
    – Hauleth
    Mar 27, 2012 at 21:30
5
\$\begingroup\$

cat 3

Create a file with the following content (source code)

cat

And run it like (execute the file):

$ cat filename
\$\endgroup\$
7
  • 7
    \$\begingroup\$ Neither indirect nor a language? \$\endgroup\$ Jul 22, 2011 at 22:35
  • 4
    \$\begingroup\$ Cat isn't a real language, because it isn't Turing-complete. \$\endgroup\$
    – kinokijuf
    Dec 25, 2011 at 11:36
  • 3
    \$\begingroup\$ @kinokijuf There are plenty of useful languages which are not Turing-complete. See stackoverflow.com/q/8412741/20713 for a partial list. \$\endgroup\$
    – ephemient
    Mar 27, 2012 at 6:43
  • 5
    \$\begingroup\$ @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. \$\endgroup\$ Mar 27, 2012 at 10:55
  • 6
    \$\begingroup\$ @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. \$\endgroup\$
    – ephemient
    Mar 28, 2012 at 4:08
5
\$\begingroup\$

Clojure - 16 chars

(subs(str =)0 7)
\$\endgroup\$
5
\$\begingroup\$

Haskell, 47

data H=Haskell deriving Show
main=print Haskell
\$\endgroup\$
5
\$\begingroup\$

Ruby

Not short, but very indirectly.

4.times{|x|print((82+11.24*x+8.231*Math.tan(111.2*x)).floor.chr)}
\$\endgroup\$
5
\$\begingroup\$

Ruby (17)

p 1299022.to_s 36

Outputs "ruby"

\$\endgroup\$
5
\$\begingroup\$

Bash/Brainfuck/C

//bin/bash -c 'echo ${0##*/}'
#define p putchar
#define exit main(){p(p+67);p(10);}
exit
//++++++++[->++++++++++++>+>>++>+++<<<<<]>[->+>+>+>+<<<<]
//>+>++.>++.<-.<.>>----.<<---.>>>---.<<++.>---.
\$\endgroup\$
1
  • \$\begingroup\$ Wow! A polyglot! Next step: add Whitespace. \$\endgroup\$
    – tbodt
    Feb 24, 2014 at 22:39
4
\$\begingroup\$

Brainfuck

>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
++++++++++++++++++++++++++++++++++++++++++++++++.
-----------------.
++++++++.
+++++.
--------.
+++++++++++++++.
------------------.
++++++++.
\$\endgroup\$
9
  • \$\begingroup\$ Br**n ! (five more to go ...) \$\endgroup\$ Feb 21, 2011 at 18:38
  • \$\begingroup\$ @belisarius: Hm? \$\endgroup\$
    – Joey
    Feb 21, 2011 at 19:02
  • \$\begingroup\$ Br**n you. \$\endgroup\$ Mar 10, 2011 at 4:46
  • 1
    \$\begingroup\$ you can make smaller with [...]: ++++++++++[>++++++>++++++++++>+++++++++++>++++<<<<-]>++++++.>>++++.<---.++++++++.+++++.--------.>>++.*<<---.++++++++. \$\endgroup\$
    – JBernardo
    Jul 7, 2011 at 0:27
  • 13
    \$\begingroup\$ This looks like typical Git output. \$\endgroup\$
    – Joey Adams
    Jul 7, 2011 at 3:34
4
\$\begingroup\$

Perl

$^X=~/([a-z]+)[^\/]+$/;print$1,$/
\$\endgroup\$
4
  • \$\begingroup\$ I get only per as output (missing the final l). \$\endgroup\$
    – BioGeek
    Jul 2, 2011 at 22:49
  • 1
    \$\begingroup\$ @BioGeek: Is your Perl binary called per? \$\endgroup\$
    – ninjalj
    Jul 3, 2011 at 6:42
  • 2
    \$\begingroup\$ I also get per. (My $^X says /usr/bin/perl. The [^\/]+ swallows the l.) \$\endgroup\$ Dec 12, 2011 at 22:35
  • \$\begingroup\$ fixed: $^X=~/([^\/]+)$/;print$1, run with -l command line switch \$\endgroup\$
    – ardnew
    Apr 30, 2012 at 21:34
4
\$\begingroup\$

Scala — 42

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

Update — 39 chars

print(('a.getClass+"").substring(6,11))
\$\endgroup\$
6
  • \$\begingroup\$ Nice! A variant, same size: print((""+'a.getClass).split("\\b")(3)) \$\endgroup\$
    – PhiLho
    Jul 27, 2011 at 16:00
  • \$\begingroup\$ I prefer it capitalized, but of course, it isn't golf anymore. So, for the pleasure of making variants: print(classOf[App].toString.split("\\W").map(_.capitalize).apply(1)) \$\endgroup\$
    – PhiLho
    Jul 28, 2011 at 8:23
  • \$\begingroup\$ Same trick in 23 chars: (""+Map).patch(5,"",99) \$\endgroup\$
    – deadsven
    Oct 25, 2011 at 11:51
  • \$\begingroup\$ And 16: (""+Map).take(5) \$\endgroup\$
    – deadsven
    Oct 25, 2011 at 12:04
  • \$\begingroup\$ Or 13: ""+Map take 5 \$\endgroup\$ Jan 26, 2013 at 1:14
4
\$\begingroup\$

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);}
\$\endgroup\$
1
  • 2
    \$\begingroup\$ Gah, but now I can't name my files "&raquo;\0<3ASCII.c" \$\endgroup\$
    – walpen
    Jun 13, 2012 at 0:50
4
\$\begingroup\$

><> (Fish) (11)

Even better:

'>'::o2-oo;
\$\endgroup\$
3
\$\begingroup\$

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"))
\$\endgroup\$
2
  • \$\begingroup\$ The VBScript one produces "Bscript." on my computer. \$\endgroup\$
    – kinokijuf
    Dec 25, 2011 at 11:32
  • \$\begingroup\$ You're a bad man. \$\endgroup\$
    – Riking
    May 24, 2013 at 14:39
3
\$\begingroup\$

QBasic (37)

I am using version 1.1 of the QBasic interpreter.

FOR x=0TO 5:?CHR$(PEEK(2588+x));:NEXT
\$\endgroup\$
3
\$\begingroup\$

Lua 25 Chars

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

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

print"\76\117\97"
\$\endgroup\$
1
  • 1
    \$\begingroup\$ _VERSION:sub(1,3) \$\endgroup\$
    – mniip
    May 17, 2013 at 15:59
3
\$\begingroup\$

GolfScript (13)

"#{$0[0..9]}"
\$\endgroup\$
2
  • \$\begingroup\$ +1 Clever... very clever. Of course, this doesn't work if you've renamed the interpreter, or if you're, say, running it from a different directory. \$\endgroup\$ Mar 30, 2012 at 11:13
  • \$\begingroup\$ Ps. "#{$0}"10< is three chars shorter. :) \$\endgroup\$ Mar 30, 2012 at 11:20
3
\$\begingroup\$

Racket (45)

racket -e "(display(substring(banner)10 17))"
\$\endgroup\$

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