-
Notifications
You must be signed in to change notification settings - Fork 3
Home
Welcome to the aya-lang wiki!
Check the sidebar for the pages in the wiki.
Aya is a stack based programming language originally intended for code golf and programming puzzles. Unlike other stack-based programming languages, it supports user-defined types, macro-like function definitions, key-value pair dictionaries, and natural variable scoping rules allowing for more complex programs and data structures.
Aya comes with a rapidly-growing standard library written entirely in Aya code. The standard library features types such as matrices, stacks, dates and more. It also features hundreds of functions for working working on numerical computations, strings, plotting and file I/O. It even features a basic turtle library for creating drawings in the plot window.
Aya also features a minimal GUI that interfaces with Aya's stdin and stdout. The GUI features, plotting, tab-completion for special characters, and an interactive way to search QuickSearch help data.
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
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.
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
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_춦¥
A few more examples
aya> [ a b c d k l p w z ì í]
[ 2 3 10 1000 [ ] 3.14159265 -1 0 {+} {-} ]