-
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 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> 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_춦¥
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 {+} {-} ]
The date script provides a basic interface for the date parsing operators Mh
and MH
. It also provides basic date unit addition and subtraction.
aya> date.now
May 01, 2017 12:53:25 PM
aya> date.now.year
2017
aya> date.now 2 dates.month +
Jul 01, 2017 8:53:42 AM
aya> date.now 2 dates.month + .mmddyy
"07/01/17"
The set
script defines a set
type and many operator overloads. It defines s
as a prefix operator for the set constructor allowing the syntax s[ ... ]
to create sets.
aya> import ::set
aya> s[1 2 3 2 2 1] .# == ([1 2 3 2 2 1] set!)
s[ 1 2 3 ]
aya> s[1 2 3] s[2 3 4] |
s[ 1 2 3 4 ]
aya> s[1 2 3] s[2 3 4] &
s[ 2 3 ]
aya> s[1 2 3] s[2 5] /
s[ 1 3 ]