What's my name? Produce the name of the language indirectly

40

5

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.

Ty Auvil

Posted 2011-02-20T23:44:14.867

Reputation: 473

Question was closed 2016-04-28T05:49:21.563

1so using Java reflection API is not OK? – Ming-Tang – 2011-02-21T01:15:10.837

I didn't think of that, but that's okay too. – Ty Auvil – 2011-02-21T12:20:44.517

@George: Huh? Is that now a code-golf? Why? It wasn't before ... – Joey – 2011-02-21T19:03:23.253

@Joey: No it wasn't before, but it seemed like a code golf question, so I edited it and someone approved the edit. – Nathan Osman – 2011-02-21T19:35:24.020

@Joey: Code Golf is the tie breaker. I didn't put that TAG on originally, but George suggested it and I agreed. – Ty Auvil – 2011-02-21T23:11:34.623

As of now, Anon. has 6 votes, but Eelvex, the one you picked, has 5. – Mateen Ulhaq – 2011-03-10T04:44:39.870

@George Edison: Sorry, I took out the [code-golf] tag you added, as it's not a code golf question. (See the edit comment for rationale.) – Chris Jester-Young – 2011-03-11T08:59:34.110

print(reverse("emaNegaugnaL")) C, J, and other one'rs excluded :( – Thomas Eding – 2011-07-19T00:31:19.270

There's still no solution in Haskell... – Joey Adams – 2011-07-19T00:56:58.347

@Joey: Remedied. – Thomas Eding – 2011-07-22T20:30:58.100

should'nt this be community wiki? – kinokijuf – 2011-12-25T11:28:28.433

Answers

18

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.

Eelvex

Posted 2011-02-20T23:44:14.867

Reputation: 5 204

echo ${SHELL:5} – Fish Monitor – 2012-05-18T09:27:18.530

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 – 2011-02-22T20:02:28.393

@JB: thanks for pointing that out. I was using "s where I should have 's – Eelvex – 2011-02-22T20:10:25.357

Looks like this is the winner. :) – Ty Auvil – 2011-02-28T23:59:19.990

31

Whitespace

|  	 	 			
	
    		 	   
	
    		 	  	
	
    			 	  
	
    		  	 	
	
    			  		
	
    			    
	
    		    	
	
    		   		
	
    		  	 	
	


|

Anthony

Posted 2011-02-20T23:44:14.867

Reputation: 199

1If 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. – r.e.s. – 2012-03-29T00:56:45.183

I'm basing the preceding comment on the Whitespace tutorial, and I'm using this WS interpreter in Ruby. Following is the 153-char revised version of Anthony's program (using the same previous S-T-L notation), which outputs the string "Whitespace" when executed with that interpreter: SSSTSTSTTTLTLSSSSSTTSTSSSLTLSSSSSTTSTSSTLTLSSSSSTTTSTSSLTLSSSSSTTSSTSTLTLSSSSSTTTSSTTLTLSSSSSTTTSSSSLTLSSSSSTTSSSSTLTLSSSSSTTSSSTTLTLSSSSSTTSSTSTLTLSSLLL

– r.e.s. – 2012-03-29T01:14:28.657

Not a real language, whitespace. – Alexandru – 2011-07-02T00:11:05.150

22

@Alexandru: http://compsoc.dur.ac.uk/whitespace/

– dmckee --- ex-moderator kitten – 2011-07-02T00:57:53.280

Argh. Sorry Anthony, SE doesn't let me upvote you now. – Alexandru – 2011-07-02T14:10:28.630

That's all right. I myself have recently learned about this language. – Anthony – 2011-07-02T19:49:00.307

That has to be the most esoteric language of them all. – Kazark – 2012-01-01T04:17:54.563

26

C

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

Anon.

Posted 2011-02-20T23:44:14.867

Reputation: 1 799

23putchar("putchar"[3]); I must have been an idiot an year ago. – Mateen Ulhaq – 2012-04-01T01:50:07.973

putchar((int)(putchar)+3); – Mateen Ulhaq – 2011-03-12T23:04:21.993

Use the main parameter. main(a){putchar(a+66);} – None – 2019-11-16T12:54:44.463

23

J,4

u:74

Having a short language name does kind of help.

J B

Posted 2011-02-20T23:44:14.867

Reputation: 9 638

Can be even shorter : u:74 – jpjacobs – 2014-02-24T12:13:47.643

23

Python - 23 22

print`credits`[97:103]

Kirill

Posted 2011-02-20T23:44:14.867

Reputation: 661

2@0xKir So? Use them in code golf 'till they're gone. – Riking – 2013-05-24T14:34:52.667

2you should leave out the space after print – gnibbler – 2011-07-05T06:25:46.447

What does the ` do? I've never seen that. – Kazark – 2012-01-01T04:13:43.837

4Backticks are a deprecated alias for repr(). Backticks are gone in Python 3.x. – Kirill – 2012-01-04T09:49:19.210

19

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

zhazam

Posted 2011-02-20T23:44:14.867

Reputation: 191

How did you find that? It also works for me in Python 2.6.6 on linux. – Mechanical snail – 2011-08-05T02:42:21.027

5Good 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 – 2011-08-15T13:24:54.370

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 :)

– zhazam – 2011-08-15T13:30:41.927

And it works on my Python 3.1.2 (adding parentheses after print, of course). – Mechanical snail – 2011-08-16T20:18:50.797

1Almost there: generateSentence(50613, 73)[66:] gives 'PYTHOCN'. – Mechanical snail – 2011-08-16T20:45:38.417

17

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

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

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


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

 - 
---
 - 

JiminP

Posted 2011-02-20T23:44:14.867

Reputation: 3 264

13

Piet, 47x2 pixels

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

boothby

Posted 2011-02-20T23:44:14.867

Reputation: 9 038

12

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

gnibbler

Posted 2011-02-20T23:44:14.867

Reputation: 14 170

1Here is what i get from these: Active and 25\Lib\site-packages\pythonwin\Pythonwin.exe, so... no good – Nas Banov – 2011-03-07T08:12:41.517

import sys;print sys.subversion[0][1:] works though – Nas Banov – 2011-03-07T08:19:24.520

6that's cheating... But I can cheat better: eval.__doc__[144:150] – JBernardo – 2011-07-05T05:53:52.527

11

brainfuck 101

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

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

Matt

Posted 2011-02-20T23:44:14.867

Reputation: 129

11

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

Etienne PIERRE

Posted 2011-02-20T23:44:14.867

Reputation: 171

5Much shorter, 25 chars, single line, main(){puts(__FILE__+2);}, assuming filename is a single letter, eg. a.c – Hasturkun – 2011-02-24T15:09:56.537

7

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

Joey

Posted 2011-02-20T23:44:14.867

Reputation: 12 260

anon: Just submit another answer. This isn't a golf, so no need to keep it short. – Joey – 2011-07-01T07:44:48.660

6

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

Skizz

Posted 2011-02-20T23:44:14.867

Reputation: 2 225

first one will produce warning about main not being of type int using gcc. – oenone – 2011-08-16T07:28:01.183

1You are not allowed to use the letter 'c'. – kinokijuf – 2011-12-25T11:29:33.580

6

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]

Donnie H

Posted 2011-02-20T23:44:14.867

Reputation: 131

Even shorter ```ruby -v`[0,4]`` – Hauleth – 2012-03-27T21:30:02.533

>

  • RUBY_COPYRIGHT is shorter than RUBY_DESCRIPTION. 2. [0,4] is shorter than [0..3].
  • < – Chris Jester-Young – 2011-03-11T08:56:51.567

    5

    cat 3

    Create a file with the following content (source code)

    cat
    

    And run it like (execute the file):

    $ cat filename
    

    Alexandru

    Posted 2011-02-20T23:44:14.867

    Reputation: 5 485

    3

    @kinokijuf There are plenty of useful languages which are not Turing-complete. See http://stackoverflow.com/q/8412741/20713 for a partial list.

    – ephemient – 2012-03-27T06:43:25.300

    5@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 – 2012-03-27T10:55:38.980

    6@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 – 2012-03-28T04:08:17.833

    Well, cat of course has a syntax. It accepts any input. (It is a regular grammar btw) – FUZxxl – 2012-07-26T11:44:33.403

    7Neither indirect nor a language? – eternalmatt – 2011-07-22T22:35:24.450

    Everything that takes a string input and produces a string output can be considered a programming language. – bitmask – 2011-08-03T00:01:57.463

    4Cat isn't a real language, because it isn't Turing-complete. – kinokijuf – 2011-12-25T11:36:01.540

    5

    Clojure - 16 chars

    (subs(str =)0 7)
    

    mikera

    Posted 2011-02-20T23:44:14.867

    Reputation: 1 233

    5

    Bash/Brainfuck/C

    //bin/bash -c 'echo ${0##*/}'
    #define p putchar
    #define exit main(){p(p+67);p(10);}
    exit
    //++++++++[->++++++++++++>+>>++>+++<<<<<]>[->+>+>+>+<<<<]
    //>+>++.>++.<-.<.>>----.<<---.>>>---.<<++.>---.
    

    Dennis

    Posted 2011-02-20T23:44:14.867

    Reputation: 196 637

    Wow! A polyglot! Next step: add Whitespace. – tbodt – 2014-02-24T22:39:34.217

    5

    Haskell, 47

    data H=Haskell deriving Show
    main=print Haskell
    

    Thomas Eding

    Posted 2011-02-20T23:44:14.867

    Reputation: 796

    5

    Ruby

    Not short, but very indirectly.

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

    Jon

    Posted 2011-02-20T23:44:14.867

    Reputation: 131

    5

    Ruby (17)

    p 1299022.to_s 36

    Outputs "ruby"

    defhlt

    Posted 2011-02-20T23:44:14.867

    Reputation: 1 717

    4

    Brainfuck

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

    Joey

    Posted 2011-02-20T23:44:14.867

    Reputation: 12 260

    Br**n ! (five more to go ...) – Dr. belisarius – 2011-02-21T18:38:12.860

    @belisarius: Hm? – Joey – 2011-02-21T19:02:27.810

    even smaller ++++++++++++++[>+++++++>++++++++<<-]>.>++.<-.>---------.+++++.<+++++.>+++++++.<---.>----------. – mniip – 2013-05-17T15:57:45.847

    Br**n you. – Mateen Ulhaq – 2011-03-10T04:46:29.667

    1you can make smaller with [...]: ++++++++++[>++++++>++++++++++>+++++++++++>++++<<<<-]>++++++.>>++++.<---.++++++++.+++++.--------.>>++.*<<---.++++++++. – JBernardo – 2011-07-07T00:27:51.813

    12

    This looks like typical Git output.

    – Joey Adams – 2011-07-07T03:34:15.990

    JBernado: Suggest an edit, then. – Joey – 2011-07-07T09:41:49.587

    do you really need the first >? – oenone – 2011-08-16T07:29:07.907

    Maybe that was just to cater for my buggy interpreter. This solution is obsolete, anyway :) – Joey – 2011-08-16T11:08:57.297

    4

    Perl

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

    ninjalj

    Posted 2011-02-20T23:44:14.867

    Reputation: 3 018

    fixed: $^X=~/([^\/]+)$/;print$1, run with -l command line switch – ardnew – 2012-04-30T21:34:07.347

    I get only per as output (missing the final l). – BioGeek – 2011-07-02T22:49:49.050

    1@BioGeek: Is your Perl binary called per? – ninjalj – 2011-07-03T06:42:05.870

    2I also get per. (My $^X says /usr/bin/perl. The [^\/]+ swallows the l.) – Ilmari Karonen – 2011-12-12T22:35:17.997

    4

    Scala — 42

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

    Update — 39 chars

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

    Stanislav Yaglo

    Posted 2011-02-20T23:44:14.867

    Reputation: 141

    Or 13: ""+Map take 5 – Régis Jean-Gilles – 2013-01-26T01:14:19.587

    Nice! A variant, same size: print((""+'a.getClass).split("\b")(3)) – PhiLho – 2011-07-27T16:00:35.763

    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)) – PhiLho – 2011-07-28T08:23:14.977

    Same trick in 23 chars: (""+Map).patch(5,"",99) – deadsven – 2011-10-25T11:51:50.463

    And 16: (""+Map).take(5) – deadsven – 2011-10-25T12:04:20.700

    I've hardly ever used symbols in Scala. – bb94 – 2014-11-30T21:40:20.260

    4

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

    qartis

    Posted 2011-02-20T23:44:14.867

    Reputation: 41

    2Gah, but now I can't name my files "»\0<3ASCII.c" – walpen – 2012-06-13T00:50:54.927

    4

    ><> (Fish) (11)

    Even better:

    '>'::o2-oo;
    

    jpjacobs

    Posted 2011-02-20T23:44:14.867

    Reputation: 3 440

    3

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

    PleaseStand

    Posted 2011-02-20T23:44:14.867

    Reputation: 5 369

    You're a bad man. – Riking – 2013-05-24T14:39:59.960

    The VBScript one produces "Bscript." on my computer. – kinokijuf – 2011-12-25T11:32:05.993

    3

    QBasic (37)

    I am using version 1.1 of the QBasic interpreter.

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

    PleaseStand

    Posted 2011-02-20T23:44:14.867

    Reputation: 5 369

    3

    Mathematica 39

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

    StringTake[ToString[FullForm[\[MathematicaIcon]]],{3,13}]
    

    DavidC

    Posted 2011-02-20T23:44:14.867

    Reputation: 24 524

    What's that weird character? If we don't know, we can't run that. – tbodt – 2014-02-20T01:24:37.503

    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. – DavidC – 2014-02-20T01:51:27.407

    3

    Lua 25 Chars

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

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

    print"\76\117\97"
    

    jpjacobs

    Posted 2011-02-20T23:44:14.867

    Reputation: 3 440

    1_VERSION:sub(1,3) – mniip – 2013-05-17T15:59:43.060

    3

    GolfScript (13)

    "#{$0[0..9]}"
    

    marinus

    Posted 2011-02-20T23:44:14.867

    Reputation: 30 224

    +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. – Ilmari Karonen – 2012-03-30T11:13:58.677

    Ps. "#{$0}"10< is three chars shorter. :) – Ilmari Karonen – 2012-03-30T11:20:12.133

    3

    Racket (45)

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

    Francisco

    Posted 2011-02-20T23:44:14.867

    Reputation: 121

    3

    D(52)

    using the extension of the source file

    import std.stdio;void main(){write(__FILE__[$-1]);}
    

    ratchet freak

    Posted 2011-02-20T23:44:14.867

    Reputation: 1 334

    2

    Windows PowerShell

    $ShellId -replace '.*\.'
    

    Joey

    Posted 2011-02-20T23:44:14.867

    Reputation: 12 260

    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 [tag:code-challenge] and not [tag:code-golf]. – Iszi – 2013-11-17T07:00:24.447

    2

    PHP

    php -v|php -r'echo fread(STDIN,3);'
    

    Arnaud Le Blanc

    Posted 2011-02-20T23:44:14.867

    Reputation: 2 286

    2

    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
    

    Skizz

    Posted 2011-02-20T23:44:14.867

    Reputation: 2 225

    Yes there is... ? – Timtech – 2013-12-31T21:40:44.257

    5There is no such thing as a »Windows .COM« :-) – Joey – 2011-05-05T07:14:55.333

    2

    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.

    Joe K

    Posted 2011-02-20T23:44:14.867

    Reputation: 1 065

    How did you come up with exactly what seed to use? – tbodt – 2014-02-22T23:11:15.643

    @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. – Vereos – 2014-02-24T10:44:26.587

    2

    Groovy - 34

    print "${''.metaClass.name}"[0..5]
    

    TheBigS

    Posted 2011-02-20T23:44:14.867

    Reputation: 151

    2

    shell (Linux)

    basename `readlink /proc/$$/exe`
    

    ephemient

    Posted 2011-02-20T23:44:14.867

    Reputation: 1 601

    1

    Ruby (36)

    # ruby -v|ruby -e"puts gets.split[0]"
    

    Hoa Long Tam

    Posted 2011-02-20T23:44:14.867

    Reputation: 1 902

    1

    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
    

    Aman ZeeK Verma

    Posted 2011-02-20T23:44:14.867

    Reputation: 609

    1

    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++)
    

    PleaseStand

    Posted 2011-02-20T23:44:14.867

    Reputation: 5 369

    1

    VBScript

    set fso = CreateObject("Scripting.FileSystemObject")
    msgbox split(fso.GetFile(Wscript.ScriptFullName).Type," ")(0)
    

    st0le

    Posted 2011-02-20T23:44:14.867

    Reputation: 2 002

    1

    Smalltalk Squeak/Pharo flavour 16 chars

    self environment
    

    In Smalltalk, the name of global name space is Smalltalk

    aka.nice

    Posted 2011-02-20T23:44:14.867

    Reputation: 411

    1

    C, 25

    The following should be in a file named c.c

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

    alternate version, 27 chars:

    main(){putchar(*__FILE__);}
    

    Hasturkun

    Posted 2011-02-20T23:44:14.867

    Reputation: 1 206

    Not sure this counts... the resulting C code contains the character 'c'. – Thomas Eding – 2011-07-19T00:28:52.140

    Put in a file named 'C' if your compiler will accept files with no extensions. – Thomas Eding – 2011-07-22T20:33:22.000

    1

    dc

    Noticed this was missing so here's

    Od*dP1-P
    

    Geoff Reedy

    Posted 2011-02-20T23:44:14.867

    Reputation: 2 828

    It needs one more 'd', like so: Od*dP1-P – daniero – 2013-07-10T10:40:23.617

    1

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

    zzzzBov

    Posted 2011-02-20T23:44:14.867

    Reputation: 2 915

    1

    Python (27)

    print str(copyright)[24:30]
    

    Jagu

    Posted 2011-02-20T23:44:14.867

    Reputation: 139

    1

    php

    Very late but php have more way to show itself.

    ob_start();
    phpcredits();
    $c=ob_get_clean();
    echo substr($c,0,3);
    

    kuldeep.kamboj

    Posted 2011-02-20T23:44:14.867

    Reputation: 625

    1

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

    Clyde Lobo

    Posted 2011-02-20T23:44:14.867

    Reputation: 1 395

    1

    Node.js: 29 characters

    console.log(process.argv[0])
    

    palanik

    Posted 2011-02-20T23:44:14.867

    Reputation: 111

    1

    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. :)

    md_rasler

    Posted 2011-02-20T23:44:14.867

    Reputation: 201

    Don't forget to explain how your answer works (in your answer). – Justin – 2014-02-25T06:05:17.387

    @Quincunx Thanks for the recommendation, added explaination. – md_rasler – 2014-02-25T15:19:17.770

    1

    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'
    

    nyuszika7h

    Posted 2011-02-20T23:44:14.867

    Reputation: 1 624

    1

    Groovy ( JVM language )

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

    Which prints groovy as output :D

    Ant's

    Posted 2011-02-20T23:44:14.867

    Reputation: 281

    How about println Closure.class.name.tokenize('.')[0] – Armand – 2012-03-31T09:11:44.007

    1

    R, 11 chars

    LETTERS[18]
    

    Alternatively 54 characters, using a non custom environment variable:

    strsplit(packageDescription("base")$Author,"")[[1]][1]
    

    Paolo

    Posted 2011-02-20T23:44:14.867

    Reputation: 696

    18 isn't a system variable or something, is it? – user unknown – 2012-03-27T13:15:09.927

    No, it is the eighteenth letter of the ISO basic Latin alphabet! ;-) – Paolo – 2012-03-27T13:28:18.330

    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. – user unknown – 2012-03-27T13:49:34.813

    1

    C, 25

    main(){printf("%X",12);}
    

    l0n3sh4rk

    Posted 2011-02-20T23:44:14.867

    Reputation: 1 387

    0

    C#

            Console.WriteLine(typeof(CSharpCodeProvider).Name.Substring(0,6));
    

    BFree

    Posted 2011-02-20T23:44:14.867

    Reputation: 109

    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. – Joey – 2011-02-21T19:55:46.317

    6Hey! I see a "CSharp" in your source code! – J B – 2011-02-22T21:44:45.240

    0

    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]
    

    Seburdis

    Posted 2011-02-20T23:44:14.867

    Reputation: 109

    You don't need the (' ') – steenslag – 2011-03-14T08:40:53.187

    0

    Common Lisp, 36 characters

    (subseq(package-name *package*)0 11)
    => "COMMON-LISP"
    

    Erik Haliewicz

    Posted 2011-02-20T23:44:14.867

    Reputation: 401

    0

    Perl

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

    afbach

    Posted 2011-02-20T23:44:14.867

    Reputation: 1

    0

    Rebol

    copy/part at system/license 16 5
    

    For Rebol 2 use:

    copy/part at system/license 1 5
    

    draegtun

    Posted 2011-02-20T23:44:14.867

    Reputation: 1 592

    0

    Perl, 28

    print @a=(a..z)[15,4,17,11];
    

    I left StackExchange

    Posted 2011-02-20T23:44:14.867

    Reputation: 159

    0

    PHP (24-25)

    25 with Bash:

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

    24 if we can omit <?php:

    echo substr(__FILE__,-3)
    

    seriousdev

    Posted 2011-02-20T23:44:14.867

    Reputation: 569

    Contain php literally - doesn't it? – user unknown – 2012-03-27T13:22:55.817

    Is first example a real solution? – Alexandru – 2011-07-02T00:12:03.027

    @Alexandru Yup. – seriousdev – 2011-07-02T08:29:42.153

    0

    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.

    Thomas Eding

    Posted 2011-02-20T23:44:14.867

    Reputation: 796

    0

    Java

    public class Me {
        public static void main(String[] args) {
                System.out.println(System.class.toString().substring(6, 7).toUpperCase() + System.class.toString().substring(7, 10));
        }
    }
    

    ChrisX

    Posted 2011-02-20T23:44:14.867

    Reputation: 1

    It's not a code golf, so we like to see the whole File, please. Does it, by any chance, contain the word Java? – user unknown – 2012-03-27T13:19:29.423

    Looks absolutely fine – Armand – 2012-03-31T09:07:44.213

    A working solution. It prints 'Java', extracted from the System class' package declaration, but there's definitely room for improvement regarding code length. – codeporn – 2012-11-20T09:29:53.643

    0

    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.

    Scott Logan

    Posted 2011-02-20T23:44:14.867

    Reputation: 332

    0

    Objective-C - 151 Chars

    Little bit of trickery by taking the class name of NSObject, and chopping off the 'NS'

    id s=[NSMutableString stringWithFormat:@"%@",[NSObject class]];
    [s deleteCharactersInRange:NSMakeRange(0,2)];NSLog(@"%@%c%c%c%c%c",s,105,118,101,45,67);
    

    Alex Coplan

    Posted 2011-02-20T23:44:14.867

    Reputation: 209

    105,118,101,45,67 aren't system variables - are they? – user unknown – 2012-03-27T13:16:30.987

    @userunknown they are the ascii codes of "ive-c". disqualify or not? – tbodt – 2014-02-22T23:13:17.280

    0

    Element, 30 characters

    2'116 110[2:1-+'101"]7'69[,#`]
    

    Element is a language of my own design. For some limited documentation, you can look here. For the source to an Element interpreter written in Perl, you can look here.

    Here is a walkthrough of how it works:

    2` stores a 2 onto the control stack for later use
    116 110 push those values (t and n) onto the stack
    [ start a for loop that is repeated twice
       2: duplicate the 110
       1-+ adds a negative one to the top copy of 110
       ' move the top copy to the control stack as temporary storage
       101 add the code for an e onto the stack
       " move the copy from the control stack back on top of the 101 
    ] end the for loop, this loops takes advantage of the fact that n m l are in consecutive order and both have an e in between 
    7' push a 7 onto the control stack
    69 push the code for an E onto the stack
    [ start a for loop that executes 7 times
       , perform ->char / ->num conversion
       # throws away the top item on the stack since this is the item->num conversion
       ` pop and output the top item on the stack, since this is the needed item->char conversion
    ] end the for loop, which prints out the numbers in character form in reverse order, to spell "Element".
    

    PhiNotPi

    Posted 2011-02-20T23:44:14.867

    Reputation: 26 739

    0

    Q (6 chars)

    10h$81
    

    skeevey

    Posted 2011-02-20T23:44:14.867

    Reputation: 4 139

    0

    bc

    ipv4=$(ipmaddr show lo ipv4 | tail -n1 | awk '{print $2}') && echo "ibase=10;obase=16;"$(echo "ibase=6;$((2**${#ipv4}))" | bc) | bc 
    

    Let's deconstruct it:

    ipmaddr show lo ipv4
    1:  lo
        inet  224.0.0.1
    

    result is unexpected, I expected 127.0.0.1, but 224.0.0.1 is sufficient.

    • tail -n1 takes the last line.
    • awk '{print $2}' only the ip, so ipv4=224.0.0.1 now.
    • ${#ipv4} is the length of this String which is 9 (our magic number :) )
    • $((2**${#ipv4})) 2^9 is 512 as we all know.
    • echo "ibase=6;$((2**${#ipv4})) | bc interprets 512 as a number to the base 6, which is 188 in decimal
    • echo "ibase=10;obase=16;"188 | bc converts it to hexadecimal, which is - surprise:

    bc

    Note: A shorter solution should be

     echo "ibase=6;obase=16;512" | bc
    

    for the right part of the &&, but somehow it doesn't work as expected.

    user unknown

    Posted 2011-02-20T23:44:14.867

    Reputation: 4 210

    0

    C, 39 chars

    main(){putchar(2[(char*)strerror(0)]);}
    

    ugoren

    Posted 2011-02-20T23:44:14.867

    Reputation: 16 527

    0

    F♯ - 187 Char

    I had some fun with this - even if it's not really golfed. I should come up with a cleverer way to obscure the 72 and 2 though

    let a="It's like OCaml... But .net!"|>Seq.sumBy(fun a->System.Convert.ToInt32(a))
    System.Console.Write(System.Convert.ToChar(a%72*2))
    System.Console.Write(System.Convert.ToChar(a%72))
    

    lochok

    Posted 2011-02-20T23:44:14.867

    Reputation: 3 139

    0

    C, obvious golfed solution

    main(){putchar(67);}
    

    Of course, it's not quite as short as the J version.

    Ilmari Karonen

    Posted 2011-02-20T23:44:14.867

    Reputation: 19 513

    0

    SQL 33 32

    print substring(@@version,11, 3)
    

    (tested with SQL Server 2008 R2 SP1)

    Cristian Lupascu

    Posted 2011-02-20T23:44:14.867

    Reputation: 8 369

    0

    Perl - 19

    Less perlish than the other perl answer, but shorter.

    print substr $^X,-4
    

    simbabque

    Posted 2011-02-20T23:44:14.867

    Reputation: 487

    0

    Haskell 137

    This uses a fairly interesting method of encoding strings. Thought I'd share it.

    import Data.Char
    main=
      (print. map chr . reverse . map last . takeWhile (not . null) . iterate (\x->zipWith subtract x$tail x))[50,-14,-31,-20,-7,0,108]
    

    Bonus points to anyone who can explain why this works.

    walpen

    Posted 2011-02-20T23:44:14.867

    Reputation: 3 237

    For those seeking enlightenment. I explain the formula here: http://www.walpenprod.com/obfuscating-strings/

    – walpen – 2012-06-13T00:48:26.897

    0

    PHP

    <?php 
    //first option use something that probably isn't available in windows installs
    print substr($_SERVER['_'],-3) . "\n";
    
    // this should work everywhere
    print strtolower(substr(array_pop(array_filter(array_keys($_SERVER),'filterSELF')),0,3)) . "\n";
    // uses the following function to filter out only 'PHP_SELF'
    function filterSELF($toCheck){
        return (strlen($toCheck) == 8 && substr($toCheck,-5) == '_SELF');
    }
    

    both return php

    Harald Brinkhof

    Posted 2011-02-20T23:44:14.867

    Reputation: 101

    0

    Nemerle, 57

    Nemerle.IO.print(typeof(Option).FullName.Substring(0,7));
    

    fre0n

    Posted 2011-02-20T23:44:14.867

    Reputation: 101

    0

    Molecule, 2 bytes

    ;M
    

    Pre-defined variables are awesome.

    user47018

    Posted 2011-02-20T23:44:14.867

    Reputation:

    This ain't no codegolf, son. – cat – 2016-04-23T17:56:00.073

    @cat I know. I'm still adding the byte count just because. – None – 2016-04-23T20:16:18.780

    0

    Factor

    Works always:

    version-info " " split first print
    

    The hacky way:

    (command-line) first "." split >title print
    

    All Factor source files end in .factor, so this just gets that and titlecases it. Won't work for compiled executables, probably.

    cat

    Posted 2011-02-20T23:44:14.867

    Reputation: 4 989

    0

    Python

    import sys
    try: from StringIO import StringIO
    except: from io import StringIO # py3
    stdout = sys.stdout
    sys.stdout = s = StringIO()
    import this # yeah
    sys.stdout = stdout
    print(s.getvalue()[11:17])
    

    mykhal

    Posted 2011-02-20T23:44:14.867

    Reputation: 641

    -1

    C#, lots of characters

    class g
    {
        static void Main()
        {
            var r = new System.Diagnostics.StackTrace(new System.Diagnostics.StackFrame(true)).GetFrame(0).GetFileName();
            System.Console.WriteLine(Microsoft.CSharp.CSharpCodeProvider.GetLanguageFromExtension(r.Substring(r.Length - 2, 2)).ToUpper());
        }
    }
    

    That's probably closer to the spirit of the problem, but this will also work, hard coding the file extension, and is probably still effectively following the guidelines:

    class g
    {
        static void Main()
        {
            System.Console.WriteLine(Microsoft.CSharp.CSharpCodeProvider.GetLanguageFromExtension(".cs").ToUpper());
        }
    }
    

    Steve

    Posted 2011-02-20T23:44:14.867

    Reputation: 671

    I read CSharp.CSharp – user unknown – 2012-03-27T13:21:36.050

    -1

    iX2Web

    **iX2001C3 934238Mwlp WDJXZWJ8Xz AJMA0K=*
    

    Timtech

    Posted 2011-02-20T23:44:14.867

    Reputation: 12 038

    -1

    Go

    This generates an indirect language name, i.e. Issue 9 (hey, it's not directly said - you need to know what this refers to). I think it's a valid name for Go, considering it has redirect on Wikipedia. For more information why Issue 9 is a valid name, please see https://code.google.com/p/go/issues/detail?id=9.

    package main
    
    import "fmt"
    
    func main() {
        fmt.Println("Issue 9")
    }
    

    Konrad Borowski

    Posted 2011-02-20T23:44:14.867

    Reputation: 11 185

    This is entertaining. It is a popcon, after all. – cat – 2016-04-23T17:55:28.507

    -2

    Java

    System.out.println("".getClass().getName().substring(0, 4));
    

    :D

    Eko Kurniawan Khannedy

    Posted 2011-02-20T23:44:14.867

    Reputation: 99

    Already given months ago (in a more verbose style). Beside, your code won't compile as is... – PhiLho – 2011-07-27T15:36:21.360

    -3

    PHP - 22/14

    (assumes a file named 'php')

    <?php echo __FILE__;?>
    

    Down to 14 with short tags

    <?=__FILE__;?>
    

    And then

    php ./php
    

    phatskat

    Posted 2011-02-20T23:44:14.867

    Reputation: 101

    file name is cheating, surely? – Armand – 2012-03-31T09:11:01.387

    Looking at the rules I believe I am well within the guidelines. – phatskat – 2012-03-31T14:38:23.247

    -4

    Javascript : 48

    alert((function Javascript(){}+"").substr(9,10))
    

    Thomas Eding

    Posted 2011-02-20T23:44:14.867

    Reputation: 796

    2That contains the test "Javascript." – tbodt – 2014-02-22T23:12:09.760