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\$
  • 1
    \$\begingroup\$ so using Java reflection API is not OK? \$\endgroup\$ – Ming-Tang Feb 21 '11 at 1:15
  • \$\begingroup\$ I didn't think of that, but that's okay too. \$\endgroup\$ – Ty Auvil Feb 21 '11 at 12:20
  • \$\begingroup\$ @George: Huh? Is that now a code-golf? Why? It wasn't before ... \$\endgroup\$ – Joey Feb 21 '11 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\$ – Nathan Osman Feb 21 '11 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 '11 at 23:11

86 Answers 86

3
\$\begingroup\$

D(52)

using the extension of the source file

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

Mathematica 39

This makes use of the FullForm name of the Mathematica icon.

StringTake[ToString[FullForm[\[MathematicaIcon]]],{3,13}]
\$\endgroup\$
  • \$\begingroup\$ What's that weird character? If we don't know, we can't run that. \$\endgroup\$ – tbodt Feb 20 '14 at 1:24
  • \$\begingroup\$ That character is #63319. In Mathematica it has goes by the name of \[MathematicaIcon]. StringTake returns the string, "Mathematica" taken from the name of the character. \$\endgroup\$ – DavidC Feb 20 '14 at 1:51
2
\$\begingroup\$

Windows PowerShell

$ShellId -replace '.*\.'
\$\endgroup\$
  • \$\begingroup\$ Well, I was going to beat your length by 1 with $ShellId[10..19]-join'', but then I realized you could just make it up by losing whitespace. And then I also realized this is a code-challenge and not code-golf. \$\endgroup\$ – Iszi Nov 17 '13 at 7:00
2
\$\begingroup\$

PHP

php -v|php -r'echo fread(STDIN,3);'
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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
| improve this answer | |
\$\endgroup\$
  • 5
    \$\begingroup\$ There is no such thing as a »Windows .COM« :-) \$\endgroup\$ – Joey May 5 '11 at 7:14
  • \$\begingroup\$ Yes there is... ? \$\endgroup\$ – Timtech Dec 31 '13 at 21:40
2
\$\begingroup\$

Groovy - 34

print "${''.metaClass.name}"[0..5]
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

shell (Linux)

basename `readlink /proc/$$/exe`
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Java

import java.util.Random;
public class J {
    public static void main(String[] args) {
        Random r = new Random(-2134197984);
        String s = "";
        while (true) {
            int k = r.nextInt(27);
            if (k == 26) break;
            s += (char)('a' + k);
        }
        System.out.println(s);
    }
}

Inspired by this stackoverflow question.

\$\endgroup\$
  • \$\begingroup\$ How did you come up with exactly what seed to use? \$\endgroup\$ – tbodt Feb 22 '14 at 23:11
  • \$\begingroup\$ @tbodt It's quite easy to build a generator that eventually will find if such a seed exists. In the same SO question, there's an answer about this, actually. \$\endgroup\$ – Vereos Feb 24 '14 at 10:44
1
\$\begingroup\$

Ruby (36)

# ruby -v|ruby -e"puts gets.split[0]"
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

BASH (39)

bash --version | head -1 | cut -d, -f1
GNU bash

if bash is required output then its 55 chars

bash --version | head -1 | cut -d, -f1 | cut -d" " -f2
bash
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

JavaScript

Both of these include the "Script" part of JavaScript as a string literal. Could someone suggest a way to derive that part from the DOM when no script elements exist in the document?

JavaScript was named after Java (77)

for(i in navigator)i[4]=='E'&&alert(i[0].toUpperCase()+i.slice(1,4)+'Script')

Script elements have a "language" attribute (218, works in Chrome/Safari only)

u=123;for(w=l=97;w<u;++w)for(x=l;x<u;++x)for(y=l;y<u;++y)for(z=l;z<u;document.write('<script language="'+n+'script">this._?alert(n[_=0].toUpperCase()+n.slice(1)+"Script"):_=1</script>'))n=String.fromCharCode(w,x,y,z++)
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

VBScript

set fso = CreateObject("Scripting.FileSystemObject")
msgbox split(fso.GetFile(Wscript.ScriptFullName).Type," ")(0)
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

C, 25

The following should be in a file named c.c

main(){puts(__FILE__+2);}

alternate version, 27 chars:

main(){putchar(*__FILE__);}
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Not sure this counts... the resulting C code contains the character 'c'. \$\endgroup\$ – Thomas Eding Jul 19 '11 at 0:28
  • \$\begingroup\$ Put in a file named 'C' if your compiler will accept files with no extensions. \$\endgroup\$ – Thomas Eding Jul 22 '11 at 20:33
1
\$\begingroup\$

JavaScript/ECMAScript – 31, 35, 57

for(i in{ECMAScript:0})alert(i)

located in JavaScript.html, or ECMAScript.html:

alert(location.href.substr(-15,10))

document.write(window.location.pathname.substr(-15, 10));

\$\endgroup\$
1
\$\begingroup\$

Python (27)

print str(copyright)[24:30]
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Python (win32)

68 characters

>>> import sys;print str.upper(sys.executable[12])+sys.executable[13:18]
'Python'

41 characters

>>> print __import__('sys').executable[12:18]
'python'
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Groovy ( JVM language )

def a =  Closure.class.name​​​​​​​​​
6.times { print a[it] }

Which prints groovy as output :D

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ How about println Closure.class.name.tokenize('.')[0] \$\endgroup\$ – Armand Mar 31 '12 at 9:11
1
\$\begingroup\$

R, 11 chars

LETTERS[18]

Alternatively 54 characters, using a non custom environment variable:

strsplit(packageDescription("base")$Author,"")[[1]][1]
\$\endgroup\$
  • \$\begingroup\$ 18 isn't a system variable or something, is it? \$\endgroup\$ – user unknown Mar 27 '12 at 13:15
  • \$\begingroup\$ No, it is the eighteenth letter of the ISO basic Latin alphabet! ;-) \$\endgroup\$ – Paolo Mar 27 '12 at 13:28
  • \$\begingroup\$ 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. \$\endgroup\$ – user unknown Mar 27 '12 at 13:49
1
\$\begingroup\$

C, 25

main(){printf("%X",12);}
\$\endgroup\$
1
\$\begingroup\$

Smalltalk Squeak/Pharo flavour 16 chars

self environment

In Smalltalk, the name of global name space is Smalltalk

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

dc

Noticed this was missing so here's

Od*dP1-P
\$\endgroup\$
  • \$\begingroup\$ It needs one more 'd', like so: Od*dP1-P \$\endgroup\$ – daniero Jul 10 '13 at 10:40
1
\$\begingroup\$

php

Very late but php have more way to show itself.

ob_start();
phpcredits();
$c=ob_get_clean();
echo substr($c,0,3);
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Javascript

Fiddle : http://jsfiddle.net/RU2kA/1/

Code should be run from a html page enclosed within the script tag that has a type attribute

var x = document.querySelector("script");alert(x.type.split("/")[1]); 
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Node.js: 29 characters

console.log(process.argv[0])
\$\endgroup\$
1
\$\begingroup\$

Java

class j {
    public static void main(String a[]){
        System.out.print(Character.UnicodeBlock.of(43392).toString().substring(0,4));
    }
}

The Character constant referenced is the Unicode block of Javanese, which contains the aksara Jawa characters traditionally used for writing the Javanese language. :)

\$\endgroup\$
  • \$\begingroup\$ Don't forget to explain how your answer works (in your answer). \$\endgroup\$ – Justin Feb 25 '14 at 6:05
  • \$\begingroup\$ @Quincunx Thanks for the recommendation, added explaination. \$\endgroup\$ – md_rasler Feb 25 '14 at 15:19
0
\$\begingroup\$

C#

        Console.WriteLine(typeof(CSharpCodeProvider).Name.Substring(0,6));
\$\endgroup\$
  • \$\begingroup\$ That would print CSharp, though, which is only an approximation of the name used in contexts that won't allow #, such as identifiers or Wikipedia. \$\endgroup\$ – Joey Feb 21 '11 at 19:55
  • 6
    \$\begingroup\$ Hey! I see a "CSharp" in your source code! \$\endgroup\$ – J B Feb 22 '11 at 21:44
0
\$\begingroup\$

Ruby(35)

Using the RUBY_DESCRIPTION variable may be cheating a little, but I'm not using the string "ruby" at least.

puts RUBY_DESCRIPTION.split(' ')[0]
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ You don't need the (' ') \$\endgroup\$ – steenslag Mar 14 '11 at 8:40
0
\$\begingroup\$

PHP (24-25)

25 with Bash:

a=`php -v`&&echo ${a:0:3}

24 if we can omit <?php:

echo substr(__FILE__,-3)
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Is first example a real solution? \$\endgroup\$ – Alexandru Jul 2 '11 at 0:12
  • \$\begingroup\$ @Alexandru Yup. \$\endgroup\$ – seriousdev Jul 2 '11 at 8:29
  • \$\begingroup\$ Contain php literally - doesn't it? \$\endgroup\$ – user unknown Mar 27 '12 at 13:22
0
\$\begingroup\$

Haskell, 52

main=putStr$map(enumFrom 'G'!!)[1,26,44,36,30,37,37]

Could be shorter if the answer can be case insensitive. I chose to start at 'G' because Haskell has no G's in its name, and 'G' comes before 'H' using enumFrom. This solution does not define anything other than main.

\$\endgroup\$
0
\$\begingroup\$

Erlang, 21 chars

[H|_]=pre_loaded(),H.

Run in the interactive shell. This works in R14B02 but I don't know if the Erlang module will always be first in the list.

| improve this answer | |
\$\endgroup\$

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