Super Hyperpolyglot
 Share
The version of the browser you are using is no longer supported. Please upgrade to a supported browser.Dismiss

 
£
%
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
|
 
Still loading...
ABCDEFGHIJKLMNOPQRST
1
JavaScriptPythonJavaC++
2
absolute pathnamenew File("foo").getAbsolutePath()
new File("/foo").getAbsolutePath()
new File("../foo").getCanonicalPath()
new File(".").getCanonicalPath()
import java.io.File;

File f = new File("foo");
String abspath = f.getAbsolutePath();

// getCanonicalPath() expands .. and .:
File f2 = new File("../foo");
String abspath2 = f2.getCanonicalPath();
File f3 = new File("./foo");
String abspath3 = f3.getCanonicalPath();
#include
#include

char buf[PATH_MAX];
if (realpath("..", buf) == NULL) {
throw exception();
}
else {
string path(buf);
}
3
absolute valueMath.abs(-3)abs(x)Math.abs(-7)
Math.abs(-7.77)
#include // fabs()
#include // abs()

int n = -7;
int absn = abs(n);

double x = -7.77;
double absx = fabs(x);
4
access control*access keywords required for methods and members:*
public class Foo {
private int privateInt;
protected int protectedInt;
public int publicInt;
}
*access keywords define regions:*
class Foo {
int privateInt1;
int privateInt2;
public:
int publicInt1;
int publicInt2;
protected:
int protectedInt1;
int protectedInt2;
private:
int privateInt3;
int privateInt4;
};
5
add time duration
6
address copy, shallow copy, deep copy
7
allocate array on heap
8
allocate array on stack
9
allocate primitive type on heap
10
allocate stringString s = "hello";
String t = new String(s);
string* s = new string("hello");
11
anonymous class(new Object() { public void hello() { System.out.println("hello!"); }
}).hello();
*possible but not useful*
12
anonymous functionauto add = [](int n, int m) {
return n + m;
};
13
are expressions statements*yes*
14
arithmetic and logic
15
arithmetic expression1 + 3
16
arithmetic functions
17
arithmetic operators+ - * / %+ - * / %
18
arithmetic truncation
19
array access
20
array iteration
21
array literal
22
array out-of-bounds result
23
arrays
24
arrays as function arguments
25
assignmentx = 1*assignments can be chained but otherwise don't return values:*
v = 1
int n;
n = 3;
int n;
n = 3;
26
backreference in match and substitution*none*

rx = re.compile('(\w+) (\w+)')
rx.sub(r'\2 \1', 'do re')
27
backticks
28
base conversion
29
binary, octal, and hex literals0b101010
052
0x2a
*none in Java 1.6*
052
0x2a
0b0101010
052
0x2a
30
bit operators<< >> & | ^ ~<< >> & | ^ ~

>> *is arithmetic right shift, >>> is logical right shift*
<< >> & | ^ ~
bitand bitor compl

>> *is arithmetic right shift on signed integers and logical right shift on
unsigned integers*
31
block delimiters{}: *and offside rule*{ }{ }
32
boolean types
33
break and continuebreak continue
34
break, continue, redo
35
build date/time from parts
36
build pathnameimport java.io.File;

File root = File.listRoots()[0];
File etc = new File(root, "etc");
File hosts = newFile(etc, "hosts");
String path = hosts.getPath();
37
c-style for
38
case and underscores in names
39
case insensitive match test"Lorem" =~ /(?i)lorem/re.search('lorem', 'Lorem', re.I)#include

regex rx("lorem", icase);
bool match = regex_match("Lorem", rx);
40
case manipulation"lorem".toUpperCase()
"LOREM".toLowerCase()
41
catch exception
42
catch exception by type
43
character class abbreviations and anchors*char class abbrevs:*
. \d \D \s \S \w \W

*anchors:* ^ $ \b
44
character escapes
45
character translation
46
chomp
47
chr and ord(Character)65
(Integer)'A'
chr(65)
ord('A')

# Python 3:
chr(0x3bb)
ord('\u03bb')
48
class definition location*top level, class block, or function block for anonymous classes**top level, class block, or function block*
49
class nameString name = c.getName();typeid(Foo).name()
50
clone object
51
close file// traditional file handle:
f2.close()
52
closure# Python 3:
def make_counter():
i = 0
def counter():
nonlocal i
i += 1
return i
return counter

nays = make_counter()
53
coalesceString s1 = s2 == null ? "was null" : s2;string s1 = s2 || "was null";
54
command line args
55
command line args, script name
56
command line script
57
comment out multiple lines
58
comparison
59
comparison operators
60
complex numbers
61
compound assignment operators: arithmetic, string, logical, bit
62
concatenates = "Hello, " + "World!"s = 'Hello, '
s2 = s + 'World!'

# juxtaposition can be used to
# concatenate literals:
s2 = 'Hello, ' "World!"
#include

vector a1({1, 2, 3});
vector a2({4, 5, 6});

a1.insert(a1.cend(),
a2.cbegin(),
a2.cend());
63
concatenation
64
conditional expressionx > 0 ? x : -xx if x > 0 else -x
65
constant declaration
66
constructortuple tup("foo", 1, 3.7);

// invokes default constructors for elements:
tuple tup2;

// element types are inferred:
auto tup3 = make_tuple("foo", 1, 3.7);
67
control structure keywords
68
convert from string
69
convert from string, to string
70
convert to string
71
copy file, remove file, rename file*??*
new File("/tmp/foo").delete()
new File("/tmp/bar").renameTo("/tmp/foo")
import java.io.File;

*??*

File f2 = new File("/tmp/foo");
f2.delete();

File f3 = new File("/tmp/bar");
f3.renameTo(new File("/tmp/bar"));
72
create blank object
73
create objecto = new Int(3)Rational r = new Rational(7,3);Rational r1(7, 3);
Rational* r2 = new Rational(8, 5);
74
current date/timet = new Date()
75
current unix epochimport datetime

t = datetime.datetime.now()
epoch = int(t.strftime("%s"))
76
custom delimiters
77
date/time type
78
dates and time
79
declare and access global variable
80
declare local variable
81
declare namespacepackage foo.bar;
public class Baz {
public static final int ANSWER = 42;
}
namespace foo {
namespace bar {
class Baz {
static const int ANSWER = 42;
};
}
}
82
declare primitive type on stack
83
decoratordef logcall(f):
def wrapper(*a, **opts):
print('calling ' + f.__name__)
f(*a, **opts)
print('called ' + f.__name__)
return wrapper

@logcall
def square(x):
return x * x
84
dedupea = [1, 2, 2, 3]

// modifies array in place:
a.unique()
#include
#include

vector a({1, 1, 2, 2, 3});
set tmp(a.cbegin(), a.cend());
// often unnecessary since sets provide
// many of the same methods as vectors:
vector a2(tmp.cbegin(), tmp.cend());
85
default argument value
86
default format example
87
default scope
88
default value
89
default value, computed valuefrom collections import defaultdict

counts = defaultdict(lambda: 0)
counts['foo'] += 1

class Factorial(dict):
def __missing__(self, k):
if k > 1:
return k * self[k-1]
else:
return 1

factorial = Factorial()
90
define classclass Int {
public int value
Int (int n) {
value = n
}
}
public class Rational {
public int num;
public int denom;
public Rational add(Rational o) throws Exception {
return new Rational(this.num*o.denom +
o.num*this.denom,this.denom*o.denom);
}
public static Rational max(Rational a, Rational b) {
return (a.num*b.denom > a.num*b.denom) ? a : b;
}
}
*Rational.hpp:*
class Rational {
public:
int num, denom;
Rational(int num, int denom);
virtual ~Rational();
Rational operator+(Rational& addend);
static Rational max(Rational& a, Rational& b);
};
91
define class method*declare static in class definition**declare static in class definition*
92
define exceptionclass Bam(Exception):
def __init__(self):
super(Bam, self).__init__('bam!')
#include

class Bam : public runtime_error {
public:
Bam() : runtime_error("bam!") {}
};

throw Bam();
93
define generic typepublic class Foo {
public A a;
public Foo(A a) {
this.a = a;
}
}
template
class Foo {
public:
A a;
Foo(A a);
};

template
Foo::Foo(A a) : a(a) {
}
94
define methodpublic int height() {
return (Math.abs(this.num) > this.denom) ? Math.abs(this.num) :
this.denom;
}
int Rational::height() {
return (abs(num) > abs(denom)) ? abs(num) : abs(denom);
}
95
deleted = {1: True, 0: False}
del d[1]
m.remove("hello");m.erase(m.find("hello"));
96
delete entry
97
destroy object*none*delete r2;
98
destructorprotected void finalize() throws Throwable {
super.finalize();
}
Rational::~Rational() {};
99
dictionaries
100
directories
Loading...
 
 
 
JavaScript Python Java CPP
Scripting
CPP
Embeddable
Sheet13