Skip to content
Nicholas Paul edited this page May 1, 2017 · 14 revisions

Welcome to the aya-lang wiki!

Check the sidebar for the pages in the wiki.

A Tour of Aya

Basic language features

Aya is a stack based language. The code

1 1 +

will return "2".

All lowercase letters are used for variables. The colon (:) operator is used for assignment.

.# This is a line comment
"Hello" :first
"World!" :snd

Almost everything else is an operator. The :P operator will print the item on the top of the stack to stdout.

first " " + snd + :P

Blocks are used to define functions.

{2*}:double
4 double .# will return 8

Blocks may have arguments and local variables. In the example below, a, b, and c are arguments and x, y, and z are local variables.

{a b c : x y z, 
  [a b c] .# a list with a, b and c inside
}:myfun;

The following will call myfun and assign 1 to a, 2 to b, and 3 to c within the scope of the function. It will return the list [1 2 3].

1 2 3 myfun .# => [1 2 3]

Block headers may include type assertions and local variable initializers.

{a::num b::str, x(10) y z("hello"),
  [a b x y z]
}:myfun

1 "cats" myfun .# => [1 "cats" 10 0 "hello"

Aya also supports dictionaries. {,} creates an empty dictionary. . is used for dictionary access and .: is used for assignment.

{,} :dict
3 dict.:x
dict.x .# returns 3

Variables may also be assigned within the dictionary literal

{, "hi":a  4:b }:dict
dict.a .# returns "hi"
dict.b .# returns 4

Standard library

The Aya standard library consists of type definitions, mathematical functions, string and list operations, plotting tools and even a small turtle graphics library. It also defines functions and objects for working with colors, dates, files, GUI elements, and basic data structures such as queues, stacks, and sets. The standard library also contains a file which defines extended ASCII operators for use when code golfing.

matrix

The matrix type provides a basic interface and operator overloads for working with matrices.

aya> import ::matrix

aya> 3 3 10 matrix.randint :mat
|  7  8  2 |
|  8  7  3 |
|  8  4  4 |

aya> mat [[0 1] 0] I
|  7 |
|  8 |
 
aya> mat [[0 1] 0] I .t
|  7  8 |

aya> mat 2 ^ 100 -
|   29   20  -54 |
|   36   25  -51 |
|   20    8  -56 |

golf

golf defines many short variables that are useful when golfing. It also uses the Mk operator to add additional single character operators. In the following code, all variables 춦¥ and r are defined in the golf script.

aya> .# Generate and print an addition table
aya> 6r_춦¥
   0   1   2   3   4   5
   1   2   3   4   5   6
   2   3   4   5   6   7
   3   4   5   6   7   8
   4   5   6   7   8   9
   5   6   7   8   9  10

A few more examples

aya> [ a b c d k l p w z ì í]
[ 2 3 10 1000 [ ] 3.14159265 -1 0 {+} {-} ]
Clone this wiki locally