awkium: an awk interpreter


Japanese - Top - How to Use - awkium language - libraries - awkium File System - awkium shell - awkium sed - download


String functions

s.asc(string)
convert a first character of string to character code number of Unicode.

s.at(string, i)
return ith character of string. The number of the first character is 1.

s.casecmp(string1, string2)
compare the given characters ignoring cases. return a positive number if string1 is more than string2, return a negative number if string1 is less than string2, otherwise return 0.

s.caseequals(string1, string2)
returns true if the given values are equivalent. This function compares with ignoring case.

s.checksum(string, bits)
return the checksum of string.

s.chomp(string1[, string2])
truncate string2 from string1 if string1 ends with string2. If string2 is \n and string1 ends with newline, This truncates trailing \n, \r or \r\n of string1. If string2 is not specified, the value of variable RS is used instead of string2.

s.chop(string)
truncate the last character of string. If the last two characters is \r\n, this truncates the characters.

s.chr(number)
return the character corresponding to number of Unicode.

s.cmp(string1, string2)
compare the given characters. return a positive number if string1 is more than string2, return a negative number if string1 is less than string2, otherwise return 0.

s.contains(string[, string2 [, ...])
return true if string2 is substring of string1, and so on.

s.dump(string)
escape all control characters of string.
Example: "\034abc\r\n" -> "\\034abc\\r\\n"

s.ends(string1, string2)
return true if string1 ends with string2.

s.insert(string1, i, string2)
insert string2 in the ith index of string1.

s.join(array[, string])
join array to a string. The delimiter of the string is string, or the variable OFS if string is not specified.

s.ltrim(string)
trims left spaces of string.

s.parseint(string, radix)
convert string to integer. The radix of the integer is specified by radix. radix must be an integer from 2 to 36.

s.reverse(string)
reverse string.

s.rindex(string1, string2)
scan string2 from right to left and return the index in which string2 is appeared first. The number of the first character is 1. This returns 0 if string2 is not appeared in string1.

s.rtrim(string)
trims right spaces of string.

s.starts(string1, string2)
return true if string1 starts with string2.

s.tolower(string)
convert string to lower case.

s.tostring(integer, radix)
convert integer to the string. The radix of the integer is specified by radix. radix must be an integer from 2 to 36.

s.toupper(string)
convert string to upper case.

s.tr(character set1, character set2, dest)
This functions works like UNIX tr(1) command.
Example: s.tr("abc", "ABC", "abcde") -> "ABCde"
Example: s.tr("a-zA-Z", "A-Za-z", "abcdeABCDE") -> "ABCDEabcde"
Example: s.tr("a-x", "a-z", "abyz") -> "abyz"
Example: s.tr("a-z", "a-x", "abyz") -> "abyy"

s.trim(string)
trim spaces of string


Array functions

a.addall(array1[, ...])
compute union of the given arrays.
array1 will be overwritten.
Example: When arrays
a[1] = 1, a[2] = 1, a[3] = 1
b[1] = 2, b[3] = 2, b[4] = 2 are given
a.addall(a, b) -> a[1] = 1, a[2] = 1, a[3] = 1, a[4] = 2

a.any(array)
returns true if at least one true value is exist in array.

a.c(value[, ...])
create an array from the arguments.

a.clear(array)
clear array.

a.containkeys(array[, ...])
return true if keys of the left array contain keys of the right array.
Example: When
a[1] = 1, a[2] = 1, a[3] = 1
b[1] = 2, b[3] = 2,
a.containkeys(a, b) -> true

a.copy(array)
copy array

a.equalkeys(array[, ...])
return true if keys of the left array equals keys of the right array.
Example: When
a[1] = 1, a[2] = 1, a[3] = 1
b[1] = 1, b[2] = 1, b[3] = 1,
a.contain(a, b) -> true

When
a[1] = 1, a[2] = 1, a[3] = 1
b[1] = 2, b[2] = 2, b[3] = 2,
a.contain(a, b) -> true

a.equals(array[, ...])
return true if keys and values of the left array equals keys and values of the right array.
Example: When
a[1] = 1, a[2] = 1, a[3] = 1
b[1] = 1, b[2] = 1, b[3] = 1,
a.contain(a, b) -> true

When
a[1] = 1, a[2] = 1, a[3] = 1
b[1] = 2, b[2] = 2, b[3] = 2,
a.contain(a, b) -> false

a.every(array)
return true if all elements of array is true.

a.except(array1[, ...])
compute a subtraction set of the given arrays.
array1 is not overwritten.
Example: When
a[1] = 1, a[2] = 1, a[3] = 1
b[1] = 2, b[3] = 2, b[4] = 2,
a = a.except(a, b) -> a[2] = 1

a.intersect(array1[, ...])
compute intersection of the given arrays.
array1 is not overwritten.
Example: When
a[1] = 1, a[2] = 1, a[3] = 1
b[1] = 2, b[3] = 2, b[4] = 2,
a = a.intersect(a, b) -> a[1] = 1, a[3] = 1

a.iota(integer1, integer2)
create an array which starts integer1 and ends integer2.
The number of the first character is 1.

a.member(array, value)
return true if value is in array.

a.removeall(array1[, ...])
compute a subtraction set of the given arrays.
array1 will be overwritten.
Example: When
a[1] = 1, a[2] = 1, a[3] = 1
b[1] = 2, b[3] = 2, b[4] = 2,
a.except(a, b) -> a[2] = 1

a.retainall(array11[, ...])
compute intersection of the given arrays.
array1 will be overwritten.
Example: When
a[1] = 1, a[2] = 1, a[3] = 1
b[1] = 2, b[3] = 2, b[4] = 2,
a.intersect(a, b) -> a[1] = 1, a[3] = 1

a.size(array)
return the size of array.

a.union(array1[, ...])
compute union of the given arrays.
array1 is not overwritten.
Example: When
a[1] = 1, a[2] = 1, a[3] = 1
b[1] = 2, b[3] = 2, b[4] = 2,
a = a.addall(a, b) -> a[1] = 1, a[2] = 1, a[3] = 1, a[4] = 2


Date functions

Dates of awkium represent milliseconds from the UNIX epoch.
t.day(number)
return the day of the month of number.

d.dayofyear(number)
return the day of the year of number.

d.era(number)
return "BC" or "AD".

d.format(format, number)
format number by format.
The format of format is java.text.SimpleDateFormat.

d.hour(number)
return the hour (0-23).

d.millisec(number)
return the millisecond.

d.min(number)
return the minute.

d.month(number)
return the month.

d.parse(format, string)
convert string to date number by format.
The format of format is java.text.SimpleDateFormat.

d.sec(number)
return the second.

d.time([year, [month, [day, [hour, [minute, [second, [millisecond, [zone]]]]]]]])
return the date number corresponds to the given argument.
if all arguments are not specified, this returns the current time.
Otherwise, default values of the arguments shown as follows.
month1
day1
hour0
minute0
second0
millisecond0
zonelocal time zone

d.toarray(number)
return an array which inculding the values shown as follows.
keyvalue
era"BC" or "AD"
yearyear
monthmonth
dayday
weekweekday(Sunday=1, ..., Saturday=7)
dayofyearthe day of the year
hourhour
minuteminute
secondsecond
millisecondmillisecond
zonetime offset

d.week(number)
return the weekday (Sunday=1, ..., Saturday=7).

d.year(number)
return the year.

d.zone(number)
return the time offset.


Binary functions

Binary sequences of awkium represents a string of ISO-8859-1.
If you use only ASCII codes, the binary sequence is identical with the string.
b.at(binary, index)
return the signed byte of binary at index.

b.uat(binary, index)
return the unsigned byte of binary at index.

b.shortat(binary, index [, endianness])
return the signed short value of binary at index.
endianness specifies "big" or "little". Native endianness will be used if endianness is not specified.

b.shortatb(binary, index)
return the signed short value of binary at index by big endian.

b.shortatl(binary, index)
return the signed short value of binary at index by little endian.

b.ushortat(binary, index [, endianness])
return the unsigned short value of binary at index.
endianness specifies "big" or "little". Native endianness will be used if endianness is not specified.

b.ushortatb(binary, index)
return the unsigned short value of binary at index by big endian.

b.ushortatl(binary, index)
return the unsigned short value of binary at index by little endian.

b.intat(binary, index [, endianness])
return the signed int value of binary at index.
endianness specifies "big" or "little". Native endianness will be used if endianness is not specified.

b.intatb(binary, index)
return the signed int value of binary at index by big endian.

b.intatl(binary, index)
return the signed int value of binary at index by little endian.

b.uintat(binary, index [, endianness])
return the unsigned int value of binary at index.
endianness specifies "big" or "little". Native endianness will be used if endianness is not specified.

b.uintatb(binary, index)
return the unsigned int value of binary at index by big endian.

b.uintatl(binary, index)
return the unsigned int value of binary at index by little endian.

b.longat(binary, index [, endianness])
return the signed long value of binary at index.
endianness specifies "big" or "little". Native endianness will be used if endianness is not specified.

b.longatb(binary, index)
return the signed long value of binary at index by big endian.

b.longatl(binary, index)
return the signed long value of binary at index by little endian.

b.tostring(binary [, begin[, end [, character-set]]])
convert binary to a string. The default values of the arguments are shown as follows.

b.c(byte[, ...])
create a binary sequence from the given byte values.

b.write(filename, binary)
write binary to filename.

b.writebyte(filename[, byte])
write the byte value to filename.

b.writeshort(filename[, endianness [, value]])
write the short value to filename. endianness specifies "big" or "little". Native endianness will be used if endianness is not specified.

b.writeshortb(filename [, value])
write the short value to filename by big endian.

b.writeshortl(filename [, value])
write the short value to filename by little endian.

b.writeint(filename[, endianness [, value]])
write the int value to filename. endianness specifies "big" or "little". Native endianness will be used if endianness is not specified.

b.writeintb(filename [, value])
write the int value to filename by big endian.

b.writeintl(filename [, value])
write the int value to filename by little endian.

b.writelong(filename[, endianness [, value]])
write the long value to filename. endianness specifies "big" or "little". Native endianness will be used if endianness is not specified.

b.writelongb(filename [, value])
write the long value to filename by big endian.

b.writelongl(filename [, value])
write the long value to filename by little endian.


Utility functions

util.eval(string)
evaluate string and return the result.


Statistical functions

stat.mean(array)
compute (arithmetic) mean of array.

stat.geometric(array)
compute geometric mean of array.

stat.harmonic(array)
compute harmonic mean of array.

stat.median(array)
compute median of array.

stat.mode(array)
compute mode of array.

stat.percentile(array, percent)
compute percentile of array.

stat.count(array)
count the elements of array and returns the array.

stat.histogram(array, min, max, step)
convert array to a histogram.

stat.variance(array)
compute variance of array.

stat.varianceunbiased(array)
compute unbiased variance of array.

stat.skewness(array)
compute skewness of array.

stat.kurtosis(array)
compute kurtosis of array.

stat.covariance(arrayx, arrayy)
compute covariance of arrayx and arrayy.
Keys of the given array must be integers and begin with 0.

stat.correlation(arrayx, arrayy)
compute correlation coefficient of arrayx and arrayy.
Keys of the given array must be integers and begin with 0.

stat.regression(arrayx, arrayy)
compute regression of arrayx and arrayy.
Keys of the given array must be integers and begin with 0.
The result is an array with two elements which represents y=r[1]x+r[0].

stat.normal(x, mean, variance)
compute density of the normal distribution.

stat.gamma(x, k, theta)
compute density of the gamma distribution.

stat.chisquared(x, nu)
compute density of the chi squared distribution.

stat.exponential(x, lambda)
compute density of the exponential distribution.

stat.t(x, nu)
compute density of the Student's t distribution.

stat.continuousuniform(x, a, b)
compute density of the continuous uniform distribution.

stat.cuniform(x, a, b)
compute density of the continuous uniform distribution.

stat.binomial(x, n, p)
compute probability of the binomial distribution.

stat.poisson(x, lambda)
compute probability of the Poisson distribution.

stat.discreteuniform(x, a, b)
compute probability of the discrete uniform distribution.

stat.duniform(x, a, b)
compute probability of the discrete uniform distribution.

stat.beta(x, alpha, beta)
compute density of the beta distribution.

stat.f(x, d1, d2)
compute density of the F distribution.

stat.cdfnormal(x, mean, variance)
compute cumulative density of the normal distribution.

stat.cdfgamma(x, k, theta)
compute cumulative density of the gamma distribution.

stat.cdfchisquared(x, nu)
compute cumulative density of the chi squared distribution.

stat.cdfexponential(x, lambda)
compute cumulative density of the exponential distribution.

stat.cdft(x, nu)
compute cumulative density of the Student's t distribution.

stat.cdfcontinuousuniform(x, a, b)
compute cumulative density of the continuous uniform distribution.

stat.cdfcuniform(x, a, b)
compute cumulative density of the continuous uniform distribution.

stat.cdfbinomial(x, n, p)
compute cumulative probability of the binomial distribution.

stat.cdfpoisson(x, lambda)
compute cumulative probability of the Poisson distribution.

stat.cdfbeta(x, alpha, beta)
compute cumulative density of the binomial distribution.

stat.cdff(x, d1, d2)
compute cumulative density of the F distribution.

stat.cdfdiscreteuniform(x, a, b)
compute cumulative probability of the discrete uniform distribution.

stat.cdfduniform(x, a, b)
compute cumulative probability of the discrete uniform distribution.

stat.qnormal(x, mean, variance)
compute quantile of the normal distribution.

stat.qgamma(x, k, theta)
compute quantile of the gamma distribution.

stat.qchisquared(x, nu)
compute quantile of the chi squared distribution.

stat.qexponential(x, lambda)
compute quantile of the exponential distribution.

stat.qt(x, nu)
compute quantile of the Student's t distribution.

stat.qcontinuousuniform(x, a, b)
compute quantile of the continuous uniform distribution.

stat.qcuniform(x, a, b)
compute quantile of the continuous uniform distribution.

stat.qbinomial(x, n, p)
compute quantile of the binomial distribution.

stat.qpoisson(x, lambda)
compute quantile of the Poisson distribution.

stat.qdiscreteuniform(x, a, b)
compute quantile of the discrete uniform distribution.

stat.qduniform(x, a, b)
compute quantile of the discrete uniform distribution.

stat.qbeta(x, alpha, beta)
compute quantile of the beta distribution.

stat.qf(x, d1, d2)
compute quantile of the F distribution.

stat.rnormal(mean, variance[, n])
generate n random numbers under the normal distribution.
If n is not specified, one number will be generated.

stat.rgamma(k, theta[, n])
generate n random numbers under the gamma distribution.
If n is not specified, one number will be generated.

stat.rchisquared(ν[, n])
generate n random numbers under the chi squared distribution.
If n is not specified, one number will be generated.

stat.rexponential(λ[, n])
generate n random numbers under the exponential distribution.
If n is not specified, one number will be generated.

stat.rt(ν[, n])
generate n random numbers under the Student's t distribution.
If n is not specified, one number will be generated.

stat.rcontinuousuniform(a, b [, n])
generate n random numbers under the continuous uniform distribution.
If n is not specified, one number will be generated.

stat.rcuniform(a, b [, n])
generate n random numbers under the continuous uniform distribution.
If n is not specified, one number will be generated.

stat.rbinomial(n, p[, n])
generate n random numbers under the binomial distribution.
If n is not specified, one number will be generated.

stat.rpoisson(λ[, n])
generate n random numbers under the Poisson distribution.
If n is not specified, one number will be generated.

stat.rdiscreteuniform(a, b [, n])
generate n random numbers under the discrete uniform distribution.
If n is not specified, one number will be generated.

stat.rduniform(a, b[, n])
generate n random numbers under the discrete uniform distribution.
If n is not specified, one number will be generated.

stat.rbeta(α, β[, n])
generate n random numbers under the beta distribution.
If n is not specified, one number will be generated.

stat.rf(d1, d2[, n])
generate n random numbers under the F distribution.
If n is not specified, one number will be generated.

stat.chisquaredtest(measured, expected, significance)
return 0 if the null hypothesis is false.

stat.t1test(measured, expected-mean, significance)
return 0 if the null hypothesis is false.

stat.t2test(measured1, measured12, significance)
return 0 if the null hypothesis is false.


Relational algebra functions

Relational table of awkium represents as follows.

array[column_number] = record name TBLSEP value SUBSEP ...

column_number is a sequential number from 1, SUBSEP is a built-in variable, TBLSEP is also a variable. TBLSEP is "\x1e" by default.

For example, table "idols"
name age height weight
Amami Haruka 17 158 46
Takatsuki Yayoi 14 145 37
Kikuchi Makoto 17 159 44
Ganaha Hibiki 16 152 41
is represented as follows. (Here, SUBSEP="," and TBLSEP=":")
idols[1] = name:Amami Haruka,age:17,height:158,weight:46
idols[2] = name:Takatsuki Yayoi,age:14,height:145,weight:37
idols[3] = name:Kikuchi Makoto,age:17,height:159,weight:44
idols[4] = name:Ganaha Hibiki,age:16,height:152,weight:41
rel.select(table, expression)
select records from table using expression. Example: select records whose age is less than 16 from table "idols".
rel.select(idols, "age <= 16")
name age height weight
Takatsuki Yayoi 14 145 37
Ganaha Hibiki 16 152 41

rel.project(table, record, ...)
project the given record from table.
Example: project name and age from table "idols".
rel.project(idols, "name", "age")
name age
Amami Haruka 17
Takatsuki Yayoi 14
Kikuchi Makoto 17
Ganaha Hibiki 16

rel.restrict(table1, table2)
rescrict table1 to table2.
Example: rescrict table "idols" to table "res" (shown as follows).
age height
17 158
rel.project(idols, res)
name age height weight
Amami Haruka 17 158 46

rel.naturaljoin(table1, table2)
join table1 and table2 naturally.
Example: join table "idols" and table "three" (shown as follows)
name b w h
Amami Haruka 83 56 82
Takatsuki Yayoi 74 54 78
Hoshii Miki 86 55 83
rel.naturaljoin(idols, three)
name age height weight b w h
Amami Haruka 17 158 46 83 56 82
Takatsuki Yayoi 14 145 37 74 54 78

rel.union(table1, table2)
compute union of table1 and table2

rel.intersect(table1, table2)
compute intersection of table1 and table2

rel.except(table1, table2)
compute subtraction of table1 and table2

rel.crossjoin(table1, table2)
compute cross join of table1 and table2

rel.divide(table1, table2)
divide table1 by table2.
Example: the result dividing table "a" (shown as follows)
name hobby
Amami Haruka cooking
Amami Haruka Karaoke
Mimura Kanako cooking
Ohtsuki Yui Karaoke
by table "b" (shown as follows)
hobby
cooking
Karaoke
is as follows.
rel.divide(a, b)
name
Amami Haruka


Linear algegra functions

Matrices of awkium are represented as arrays with two keys.
Example: a matrix
    + 1 2 3 +
a = | 4 5 6 |
    + 7 8 9 +
represents as follows.
a[1,1] = 1, a[1,2] = 2, a[1,3] = 3
a[2,1] = 4, a[2,2] = 5, a[2,3] = 6
a[3,1] = 7, a[3,2] = 8, a[3,3] = 9

To compute summation, Subtraction and muliplication by scalar you can use array operation.

mat.det(matrix)
compute determinant of matrix.

mat.invert(matrix)
compute invesion of matrix.

mat.multiply(matrix1, matrix2)
muliplicate the given matrices.

mat.solve(matrix A, array b)
solve the equation Ax = b.