# What's my name? Produce the name of the language indirectly [closed]

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.

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

## Whitespace

|

|
• Not a real language, whitespace. Jul 2, 2011 at 0:11
• @Alexandru: compsoc.dur.ac.uk/whitespace Jul 2, 2011 at 0:57
• Argh. Sorry Anthony, SE doesn't let me upvote you now. Jul 2, 2011 at 14:10
• That's all right. I myself have recently learned about this language. Jul 2, 2011 at 19:49
• 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. Mar 29, 2012 at 0:56

## C

#define d(x) x(#x[3])
void main(){d(putchar);}

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

# Python - 23 22

printcredits[97:103]

• you should leave out the space after print Jul 5, 2011 at 6:25
• What does the  do? I've never seen that. Jan 1, 2012 at 4:13
• Backticks are a deprecated alias for repr(). Backticks are gone in Python 3.x. Jan 4, 2012 at 9:49
• @0xKir So? Use them in code golf 'till they're gone. May 24, 2013 at 14:34

## J,4

u:74


Having a short language name does kind of help.

• Can be even shorter : u:74 Feb 24, 2014 at 12:13

# 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)])

• How did you find that? It also works for me in Python 2.6.6 on linux. Aug 5, 2011 at 2:42
• 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" :) Aug 15, 2011 at 13:24
• 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 :) Aug 15, 2011 at 13:30
• And it works on my Python 3.1.2 (adding parentheses after print, of course). Aug 16, 2011 at 20:18
• Almost there: generateSentence(50613, 73)[66:] gives 'PYTHOCN'. Aug 16, 2011 at 20:45

## 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. • 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. – J B Feb 22, 2011 at 20:02 • @JB: thanks for pointing that out. I was using "s where I should have 's Feb 22, 2011 at 20:10 • Looks like this is the winner. :) Feb 28, 2011 at 23:59 • echo${SHELL:5} May 18, 2012 at 9:27

## 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...

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

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

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

-
---
-


Piet, 47x2 pixels

Using 5x5 codels:

## 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:]

• Here is what i get from these: Active and 25\Lib\site-packages\pythonwin\Pythonwin.exe, so... no good Mar 7, 2011 at 8:12
• import sys;print sys.subversion[0][1:] works though Mar 7, 2011 at 8:19
• that's cheating... But I can cheat better: eval.__doc__[144:150] Jul 5, 2011 at 5:53

## brainfuck 101

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


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

## 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);}

• Much shorter, 25 chars, single line, main(){puts(__FILE__+2);}, assuming filename is a single letter, eg. a.c Feb 24, 2011 at 15:09

## 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);
}
}

• anon: Just submit another answer. This isn't a golf, so no need to keep it short.
– Joey
Jul 1, 2011 at 7:44

## 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));

• first one will produce warning about main not being of type int using gcc. Aug 16, 2011 at 7:28
• You are not allowed to use the letter 'c'. Dec 25, 2011 at 11:29

## 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

pruby -v[0,4]

• 1. RUBY_COPYRIGHT is shorter than RUBY_DESCRIPTION. 2. [0,4] is shorter than [0..3]. Mar 11, 2011 at 8:56
• Even shorter ruby -v[0,4] Mar 27, 2012 at 21:30

## cat 3

Create a file with the following content (source code)

cat


And run it like (execute the file):

$cat filename  • Neither indirect nor a language? Jul 22, 2011 at 22:35 • Cat isn't a real language, because it isn't Turing-complete. Dec 25, 2011 at 11:36 • @kinokijuf There are plenty of useful languages which are not Turing-complete. See stackoverflow.com/q/8412741/20713 for a partial list. Mar 27, 2012 at 6:43 • @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. Mar 27, 2012 at 10:55 • @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. Mar 28, 2012 at 4:08 # Clojure - 16 chars (subs(str =)0 7)  ## Haskell, 47 data H=Haskell deriving Show main=print Haskell  # Ruby Not short, but very indirectly. 4.times{|x|print((82+11.24*x+8.231*Math.tan(111.2*x)).floor.chr)}  ### Ruby (17) p 1299022.to_s 36 Outputs "ruby" # Bash/Brainfuck/C //bin/bash -c 'echo${0##*/}'
#define p putchar
#define exit main(){p(p+67);p(10);}
exit
//++++++++[->++++++++++++>+>>++>+++<<<<<]>[->+>+>+>+<<<<]
//>+>++.>++.<-.<.>>----.<<---.>>>---.<<++.>---.

• Wow! A polyglot! Next step: add Whitespace. Feb 24, 2014 at 22:39

## Brainfuck

>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
++++++++++++++++++++++++++++++++++++++++++++++++.
-----------------.
++++++++.
+++++.
--------.
+++++++++++++++.
------------------.
++++++++.

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

## Perl

$^X=~/([a-z]+)[^\/]+$/;print$1,$/

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

## Scala — 42

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


Update — 39 chars

print(('a.getClass+"").substring(6,11))

• Nice! A variant, same size: print((""+'a.getClass).split("\\b")(3)) Jul 27, 2011 at 16:00
• 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)) Jul 28, 2011 at 8:23
• Same trick in 23 chars: (""+Map).patch(5,"",99) Oct 25, 2011 at 11:51
• And 16: (""+Map).take(5) Oct 25, 2011 at 12:04
• Or 13: ""+Map take 5 Jan 26, 2013 at 1:14

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);}

• Gah, but now I can't name my files "&raquo;\0<3ASCII.c" Jun 13, 2012 at 0:50

## ><> (Fish) (11)

Even better:

'>'::o2-oo;


## 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"))

• The VBScript one produces "Bscript." on my computer. Dec 25, 2011 at 11:32
• You're a bad man. May 24, 2013 at 14:39

## QBasic (37)

I am using version 1.1 of the QBasic interpreter.

FOR x=0TO 5:?CHR$(PEEK(2588+x));:NEXT  Lua 25 Chars print(arg[-1]:match"%w+")  Or, analogue to the J B's J solution 17 chars: print"\76\117\97"  • _VERSION:sub(1,3) May 17, 2013 at 15:59 ## GolfScript (13) "#{$0[0..9]}"

• +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. Mar 30, 2012 at 11:13
• Ps. "#{\$0}"10< is three chars shorter. :) Mar 30, 2012 at 11:20

## Racket (45)

racket -e "(display(substring(banner)10 17))"
`