Here are some examples to give you a brief overview and a feel for the Axiom language.

Hello World

print 'hello world!'

Functions

:hello(name) print 'hello',name+'!' hello('aaron') #output: hello aaron!

Classes

@cat num = 0 #no need to declare "self" everywhere (like in Python) :new() this.id = num++ :meow() print 'Cat #'+this.id,'says meow!' #no need to declare "static" explicitly (like in C++/Python) #static methods are just methods that never reference "this" :print_total() print 'There are',num,'cats total.' c = cat() d = cat() d.meow() #output: Cat #1 says meow! cat.print_total() #output: There are 2 cats total.

Static Variables

#class syntax also doubles as a way to declare static variables within functions #static declarations are initialized on first call (like C++, and unlike the hacks you have to use in Python/Javascript # where you have to keep track of first call and initialize/declare static variables in multiple places) :count() @static x = 0 return static.x++ print count() print count() ## output: 0 1 ##

Imports

#load and execute file, similar to #include in C++, or adding a script tag in Javascript #(does not wrap the code in a module/namespace, unlike Python) import('stuff.axm')

Remote Imports

#load and execute code from anywhere on the Internet. no need for a package manager! #code gets cached in a subdirectory named .axiom #similar to Deno import('https://aaronliu.cc/axiom/example.axm')

Strings

#strings are mutable! this is something that Python/Java/Javascript can't do s = 'hello' s[1] = 'a' print s #output: hallo #multiline strings :poem() #leading indentation is removed, unlike in Python/Javascript return ` mary had a little lamb its fleece was white as snow ` print poem() ## output: mary had a little lamb its fleece was white as snow ##

Miscellaneous

#object literals can take identifiers as keys (like Javascript) #(no need to put quotes everywhere like in Python) o = { a: 1, b: 2 } #get type (can be 'array', 'object', 'string', 'number', 'boolean', or 'null') print o.type() #output: object #for loops always iterate over the integer range [0,max) #object keys are ordered and can be retrieved using .key() #(no need for in/of like in Javascript or .iteritems()/range() like in Python) for n,o.len() print o.key(n),o[n] ## output: a 1 b 2 ## #methods are distinct from members #(this avoids the .hasOwnProperty()/Object.keys(o)/prototype hacks in Javascript) o.len = 44 #assign new key (does not overwrite .len method) print o.len() #now 3 because keys are: a,b,len print o['len'] #still 44 (can use [] to retrieve key masked by method)

Time/Date

#get current timestamp t = time() #get timestamp for a specific date t = time(2000,1,2,3,45,56) #format timestamp as date string print t.date() #output: 2000/01/02 03:45:56 Sun

File I/O

#load entire file into memory data = io.load('smallfile.txt') #process file line-by-line f = io.file('bigfile.txt') while (line = f.read_line())!=null #side note: no need for a separate walrus operator like in Python print 'LINE:',line

Native Threads

#native threads are still something that Python/Javascript can't do #(for a while Java was in that boat as well, but they fixed it) :hello(name) print 'hello',name+'!' t = os.thread(hello,null,['from another thread']) t.start() t.wait() #output: hello from another thread!

Native Function Calls

#much less syntax compared to ctypes in Python #supports more parameters (up to 9) compared to MJS #missing from NodeJS (one of the creator's biggest regrets, according to a talk he gave) some_library = ni.import('some_library.so') narf = some_library.declare('int narf(int,char,char*)') print narf(3,'c','axiom is great!') ## C source of native code ## ## int narf(int i, char c, const char* s){ printf("i = %d, c = %c, s = %s\n",i,c,s); return 99; } ## ## output: i = 3, c = c, s = axiom is great! 99 ##

Web Client

#way simpler than the default libraries in both Python (urllib2) and Javascript (XMLHttpRequest) print web.req('http://example.com')

Web Server

:on_request() web.server.write_200('text/html','<html>Hello world!</html>') web.server.use(on_request) web.server.run({port:9000}) #see other options in docs

Reference

See the complete language manual and library reference here.