Preface
A few years ago, I thought I'd try to develop a language that was fun and easy to use. You don't have to stick to too many patterns, and you don't have to memorize too much grammar. Yes, and that's what created Aquarius.
Aquarius is inspired by some very good languages, and I try to take some of the features I think are great from them. At first glance, you might think it looks a lot like Lisp. Yes, the I used lisp-like parentheses to organize expressions; In terms of content, Aquarius references and implements Ruby modules such as String partly. Other references may be subtle rather than intuitive.
Aquarius has a very important principle of minimalism. If a feature or syntax is not necessary, AQ will never adopt it:
- There are no statements, only expressions
- Lambda is first-class
- ...
Several years ago, I had an embedded version implementation on an IBM platform. The latest Aquarius is a standalone version implemented by GO when I learned the GO language.
Conventions
Tips
This icon signifies a tip, suggestion, or general note.
This icon indicates a warning or caution.
Expression declaration
- Object with
..means expr repeats 1 times or more.
(if {expression1}: {expression2}..)
- Object with
...means expr repeats 0 times or more.
(|{parameter}...|{expression}...)
Acknowledgement
I want to thank my family so much. They gave me the time and engrgy to make this interesting tool. In particular, I want to thank my son Victor, whose innocence and loveliness have given me great strength.
In the meantime, thank you for taking the time to read this book and learn about it.
Aquarius introduction
Aquarius is a dynamic functional script language, abbreviated as AQR.
It is designed as simple as possible. For loops, we only provide a for expression syntax, unlike other languages that have similar syntaxes while{}, do{}while()... Similarly for conditional branching, there is only if expression syntax, no switch, no ?: expression...
Many concepts are different from normal languages. There's no Classes here, no Packages here, no statements here. In contrast to classes in object-oriented languages, we use Module to organize data and data-related behavior. At the same time, we provide Lambdas, similar to methods in object-oriented languages, to organize expressions.
The Tao produced One; One produced Two; Two produced Three; Three produced All things.
Expression is the atomic elment in Aquarius. It makes up the Lambda, further Module. We sketch out real business with infinite combinations of expressions.
Variable is the most simple expression, such as builtin nil, true and false. Of course the variables you defined are also expressions.
In addition to these simple expressions, there are Module and Lambda invoking expressions, conditional if expressions, loop for expressions and try catch expressions for error handling.
Reserved words
There are four types of reserved words that are used for specific semantics in Aquarius. They can not be defined or assigned.
Keywords are used to indicate specific syntactic structures and control semantics.
There are some predefined global values and lambda-related specific variables in Aquarius. You don't have to declare them yourself, and just use them.
Just like predefined variables, there are several predefined lambdas you can invoke directly.
Aquarius provides you with some useful basic modules right out of the box.
List of reserved words
| type | words |
|---|---|
| keyword | if eif else for try catch finally break continue let require as |
| variable | true false nil error self args lambda |
| lambda | puts show noop assert |
| module | Nil String True False Error RegExp Range List Dict Int Float |
Comment
The design of the comment is very simple, all the content between both # will be discarded during compilation.
# escaping is NOT SUPPORTED. You can not put # in the comment.
single line comment
# here is single line comment #
multiline comment
#
this
is
multi-line
comments
#
Require and Alias
require is used to express the dependency on other modules.
(require {module})
After require is called, the {module} can be used as a variable later.
It is not an expression, but an directive.
In addition, it provides you another, more convenient syntax to help you deal with particularly tedious module names.
(require {module} as {name})
At this point, you can use {name} as if it were {module}. {name} is an alias of {module}.
example:
(require examples/fibonacci)
(require examples/fibonacci as fib)
...
# we can use not only example/fibonacci #
(examples/fibonacci: 10)
# but also fib with the same effect. #
# they are essentially the same thing. #
(fib: 10)
Definitions
The definition starts with let keyword, and the = sign connects the defined {name} and its value evaluated from {expression}. it returns defined variable.
(let {name} = {expression})
Definitions are all lambda-level (scoped in which they are defined, and all sub context).
One point to note is that you can refer the {name} in the scope before definition, but the value at this time is nil, and only after the definition, variable can be obtained.
(puts: foo) # foo == nil #
(let foo = 1) # without this expression, there will be a runtime error #
Assignments
The assignment looks like definition. The behavior of assignment is to first look for the {name} in current context, and if it cannot find it, it will look for it in the outer context, until it is found. If not found it, a new {name} will be created in current context.
({name} = {value})
You should define the {name} firstly, then can refer it. The below example will raise error.
(puts: foo) # runtime error: 'foo' is not found #
(foo = 1)
Modules and lambdas
Module and Lambda are both used to organize expressions to express business logic. Athough they can both organize expressions, they are very different.
Lambda is usually used to describe an algorithn or business logic. By invoking lambda's : with some input parameters, then a calculation is output.
Module is a bit different in that it not only has sereral Lambdas, but also data. And often, these lambdas work around that data.
Lambda
(|{parameter}...|{expression}...)
Here {para} and {expression} can both be optinal.
(||) # an empty lambda #
(|| 1 2) # foo lambda just return `2` #
(|i j| 1 2) # foo lambda with 2 parameters valued `nil` #
(|(i = 2) j| 1 2) # foo lambda's parameter i has default value `2` #
By default, the default value of each parameter is nil, you can also define the default value yourself. When the parameter does not specify a value at the time of the call, the default value will take effect.
Predefined variables
| variables | |
|---|---|
self | The lambda generated closure (context). |
args | A list of copy of arguments in lambda context. |
lambda | The lambda that generated current context. |
Invoking
Lambda has the invoking method :. You just execute it like this
(puts: "here" "are" "parameters")
Module
Modules are those *.aqr files (or compiled *.aqrc) loaded from the file system.
(String: 1 2 3)
Predefined variables
| variables | |
|---|---|
self | The module generated closure (context). |
args | A list of copy of arguments in module context. |
Export
In a module, you can use an capital variable refered to a lambda, which will be exproted to outside world. Any non-lambda variables won't be detected outside module.
Condition
Aquarius provides only one expression for branching process control, if expression.
If expression
if is one of control flow expressions.
(if {expression1}: {expression2}...)
As show above, expression2 will be calling if expression1 evaluates to true, or do nothing.
(if {expression1}:
{expression2}..
else
{expression3}..
)
There also has an optional default else branch. expression3 will be calling while expression1 is evaluates to false.
(if {expression1}:
{expression2}..
eif {expression3}:
{expression4}..
else
{expression5}..
)
if expression supports multi comparing branches, like expression1 and expression3 shown above. They compares in order from top to bottom.
Recursion
Aquarius has only one loop control expression, for expression.
for expression
expression2 will be calling when expression1 evaluates to true, or it will jump to next stage of codes.
(for {expression1}:
{expression2}..
)
Optinally, for expression contains an else sub expression which will be calling while expression1 evalutes to false.
(for {expression1}:
{expression2}..
else
{expression3}..
)
In scope of the for expression, we can use two specific directives continue and break to do special stop. Their behavior are similar to that in other languages.
- break - exit from current loop immediately.
- continue - move from current cycle into next one.
(let i = 1)
(for (i < 10):
(if (i even?): break)
(i = (i + 1))
else
(puts: i) #i == 2#
)
Try catch and finally
Aquarius has an error mechanism: Error. When you create an Error, it will bubble from current scope to the outmost scope.
try expression
If there is an error created in try block, it will jump to catch block, and you can refer error to fetch error details.
if you catch the error, it will stop bubbling outwoards.
(try
{expression}..
catch
{expression}..
)
In addition, you can add a finally block in try.
(try
{expression}..
catch
{expression}..
finally
{expression}..
)
It ensures that its expressions are always executed.
example
(try
(puts:1)
(puts:2)
(Error:"222")
catch
(puts:3)
(Error:"333")
finally
(puts:4)
)
output
1
2
3
4
Error: 333
Basic modules and lambdas
Let's take a look at basic modules and lambdas in Aquarius.
"hello"
100
3.1415926
[1 2 3]
{"name": "bob" "age": 19}
(puts: 1 2 3)
(assert: (1 == 1) "it's true")
Common methods
All modules and lambdas have common methods. In addition to modules and lambdas, other entities in Aquarius also have these methods, such as variables.
{1} and {2} are placeholders for entities such as modules, lambdas and variables.
| method | |
|---|---|
| ({1} == {2}) -> bool | Determine whether {1} is equal to {2} |
| ({1} != {2}) -> bool | Determine whether {1} is not equal to {2} |
| ({1} to_s) -> string | Converts {1} to string |
| ({1} to_b) -> bool | Converts {1} to boolean |
| ({1} type) -> string | Extracts type of {1} |
Nil
Non-value in Aquarius. We need to be aware of the difference between it and nil.
(let x = (Nil to_b))
(let y = (nil to_b))
(puts: x y)
zhoudefa@DefaBook aquarius % ./bin/aqr run ./ext/test/test.aqr
true false
Booleans
True and False are designed as boolean modules. true and false are the corresponding values. Conditions need an boolean expression as condition expression, and ==, != methods are all return boolean values.
Numerics
Int and Float are two numeric modules.
Int is the set of all signed 64-bit integers(range: -9223372036854775808 through 9223372036854775807).
Float is the set of all IEEE-754 64-bit floating-point numbers in Aquarius.
Strings
A String value holds an arbitrary sequence of bytes, typically representing characters. And the String module implements subset of Ruby 2.7.0 string methods.
There is a convention here that calls to method which name ends with ! change the value itself. The corresponding method without an ! suffix returns a new String.
(let x = "abcd")
(let y = (x reverse))
(puts: x y (x == y))
zhoudefa@DefaBook aquarius % ./bin/aqr run ./ext/test/test.aqr
abcd dcba false
Now let's look at the result for reverse!.
(let x = "abcd")
(let y = (x reverse!))
(puts: x y (x == y))
zhoudefa@DefaBook aquarius % ./bin/aqr run ./ext/test/test.aqr
dcba dcba true
Lists
List is a container module implements subset of Ruby 2.7.0 Array. Some methods have two formats, one names with suffix ! that evaluated in place and the other is not.
(let x = []) # list literal #
(let y = (List: 1 2 3))
(puts: x y)
zhoudefa@DefaBook aquarius % ./bin/aqr run ./ext/test/test.aqr
[] [1 2 3]
Dicts
Like List, Dict is a container module that implements parts of Ruby 2.7.0 Hash.
(let x = {}) # dict literal #
(let y = (Dict:))
(puts: x y)
zhoudefa@DefaBook aquarius % ./bin/aqr run ./ext/test/test.aqr
{} {}
dict initialization does not accpet any parameters.
RegExp
A RegExp holds a regular expression, used to match a pattern against strings. There are two ways to create a RegExp value: One is the literal form of the regular expression, which wraps the expression in ``; Another way is to call : of RegExp module directly.
Regular expressions (regexps) are patterns which describe the contents of a string. They're used for testing whether a string contains a given pattern, or extracting the portions that match.
(let x = `\s`)
(let y = "w hat")
(let z = "what")
(puts: (x match? y) (x match? z))
zhoudefa@DefaBook aquarius % ./bin/aqr run ./ext/test/test.aqr
true false
Range
A Range is a contiguous interval of integers. There's a beginning and an end. The end is not included. We can create a new Range value by calling : of Range module. Alternatively, we can call the integer's .. method to create it.
(let x = (1 .. 2))
(let y = (Range: 1 2))
(puts: x y)
(puts: (x count) (x begin) (x end))
(x >> (|i|(puts: "->" i)))
(x << (|i|(puts: "->" i)))
zhoudefa@DefaBook aquarius % ./bin/aqr run ./ext/test/test.aqr
(1..2) (1..2)
1 1 2
-> 1
-> 1
Error
Errors are special in Aquraius. When you initalize an error value, the program will interrupt execution immiediately. If there is a try expression around it, the program jumps to the catch block immediately. The error will be eaten.
In the
catchblock, the predefined variableerrorwill now be the error you just caught. You can get the information from error value.
puts
puts lambda outputs the parameters as string to the stdout. show is alias of puts.
(puts: String 1 nil)
termial shows
<module String> 1 nil
assert
assert lamabda is used to perform an assertion on an expression.
(assert: (true == false) "Failed to assert boolean")
zhoudefa@DefaBook aquarius % ./bin/aqr run ./ext/test/test.aqr
AssertError: Failed to assert boolean
(assert : ...) /Users/zhoudefa/Documents/Projects/others/aquarius/ext/test/test.aqrc:25:1
(main : ...) /Users/zhoudefa/Documents/Projects/others/aquarius/ext/test/test.aqrc:25:26
zhoudefa@DefaBook aquarius %
noop
noop is an empty lambda which does nothing when it is called. It acts as a placeholder.
Nil
module methods:
:
(Nil:) -> nil
True
module methods:
value methods:
:
(True:) -> true
&
(true & any...) -> bool
|
(true | any...) -> true
^
(true ^ any...) -> bool
!
(true !) -> false
not
not is alias of !.
(true not) -> false
False
module methods:
value methods:
:
(False:) -> false
&
(false & any...) -> false
|
(false | any...) -> bool
^
(false ^ any...) -> bool
!
(false !) -> true
not
(false not) -> true
Int
module methods:
value methods:
:
Return 0.
(Int :) -> int
+
Return Int+others.
(Int + others(numeric)...) -> numeric
-
Return Int-others.
(Int - others(numeric)...) -> numeric
*
Return Int*others.
(Int * others(numeric)...) -> numeric
/
Return Int/others. It returns an error, if any.
(Int / others(numeric)...) -> numeric
%
Return Int%others. It returns an error, if any.
(Int % others(int)...) -> int
**
Return Int**y, the base-Int exponential of y.
(Int ** y(numeric)...) -> float
>
Return Int>i. i will first be converted to numeric.
(Int > i(any)) -> bool
>=
Return Int>=i. i will first be converted to numeric.
(Int >= i(any)) -> bool
<
Return Int<i. i will first be converted to numeric.
(Int < i(any)) -> bool
<=
Return Int<=i. i will first be converted to numeric.
(Int <= i(any)) -> bool
abs
Return the absolute value of Int.
(Int abs) -> int
&
Calculate the result of bitwise AND of Int and i.
(Int & i(int)) -> int
|
Calculate the result of bitwise OR of Int and i.
(Int | i(int)) -> int
^
Calculate the result of bitwise XOR of Int and i.
(Int ^ i(int)) -> int
~
Calculate the result of bitwise NOT of Int.
(Int ~) -> int
<<
Left shift operation on Int. i should be non-negative.
(Int << i(int)) -> int
>>
Right shift operation on Int. i should be non-negative.
(Int >> i(int)) -> int
negate
Return the inverse of Int.
(Int negate) -> int
even?
Test whether Int is even.
(Int even?) -> bool
odd?
Test whether Int is odd.
(Int odd?) -> bool
next
Return Int+1.
(Int next) -> int
pred
Return Int-1.
(Int pred) -> int
..
Return a new Range. Int is begin and 0 is
default end if i is not provided.
(Int .. i(int)) -> int
times
Call f (Int abs)-1 times, and cursor from 0 to
(Int abs)-1 as the parameter of f.
(Int times f(lambda)) -> self
to_f
Transfer to Float
(Int to_f) -> float
to_i
Return Int self.
(Int to_i) -> int
Float
module methods:
value methods:
:
Returns 0.0.
(Float :) -> float
+
Returns Float+others.
(Float + others(numeric)...) -> float
-
Returns Float-others.
(Float - others(numeric)...) -> float
*
Returns Float*others.
(Float * others(numeric)...) -> float
/
Returns Float/others. It Returnss an error, if any.
(Float / others(numeric)...) -> float
**
Returns Float**y, the base-Float exponential of y.
(Float ** y(numeric)...) -> float
>
Returns Float>i. i will first be converted to numeric.
(Float > i(any)) -> bool
>=
Returns Float>=i. i will first be converted to numeric.
(Float >= i(any)) -> bool
<
Returns Float<i. i will first be converted to numeric.
(Float < i(any)) -> bool
<=
Returns Float<=i. i will first be converted to numeric.
(Float <= i(any)) -> bool
abs
Returns the absolute value of Float.
(Float abs) -> float
negate
Returns the inverse of Float.
(Float negate) -> float
to_f
Returns Float self.
(Float to_f) -> float
to_i
Transfer to Int
(Float to_i) -> int
String
module methods:
value methods:
- *
- +
- <<
- >>
- capitalize
- capitalize!
- <=>
- center
- chars
- chr
- clear
- delete
- delete!
- lower
- lower!
- upper
- upper!
- each
- empty?
- end_with?
- start_with?
- include?
- index
- rindex
- insert
- size
- ljust
- rjust
- lstrip
- lstrip!
- rstrip
- rstrip!
- strip
- strip!
- partition
- rpartition
- replace
- reverse
- reverse!
- slice
- slice!
- split
:
Return a new string. if s is provided, return s to_s.
(String : [s(any)]) -> string
*
Return a new string that repeat String t times. If t < 1, returns
empty string.
(String * t(int)) -> string
+
Return a new string that concat String and s to_s.
(String + s(any)...) -> string
<<
Append s s to_s to the end of String, and return itself.
(String << s(any)...) -> string
>>
Prepend s s to_s to the head of String, and return itself.
(String >> s(any)...) -> string
capitalize
Return a new capitalized string of String.
(String capitalize) -> string
capitalize!
Capitalize String in place, and return itself.
(String capitalize!) -> string
<=>
Compare with s to_s.
return -1, if String > s;
returns 0, when String == s;
returns 1, when String < s.
(String <=> s(any)) -> int
center
Centers String in width. If width is greater than the length of String,
returns a new string of length width with String centered and padded with
pad; otherwise, returns copy of String. Default pad is \s.
(String center width(int) [pad(string)]) -> string
chars
Returns an array of characters in String.
(String chars) -> list
chr
Returns the first character in String.
(String chr) -> string
clear
Make String empty.
(String clear) -> string
delete
Return a new copied String with r deleted.
(String delete r(string)...) -> string
delete!
Remove all r in String.
(String delete! r(string)...) -> self
lower
Return a new copied String with all uppercase characters replaced
with lowercase ones.
(String lower) -> string
lower!
Replace all uppercase characters to lowercase ones, and return itself.
(String lower!) -> self
upper
Return a new copied String with all lowercase characters replaced
with uppercase ones.
(String upper) -> string
upper!
Replace all lowercase characters to uppercase ones, and return itself.
(String upper!) -> self
each
For each character, call f, and return itself.
(String each f(lambda)) -> self
empty?
Returns true if String is empty.
(String empty?) -> bool
end_with?
Returns true if String ends with s.
(String end_with? s(string)) -> bool
start_with?
Returns true if String starts with s.
(String end_with? s(string)) -> bool
include?
Returns true if String contains s.
(String include? s(string)) -> bool
index
Returns the index of the first occurrence of the given s.
Returns -1, if s is not found.
(String index s(string)) -> int
rindex
Returns the index of the last occurrence of the given s.
Returns -1, if s is not found.
(String rindex s(string)) -> int
insert
Inserts s before the character at the given index i, modifying String.
Negative indices count from the end of the String, and insert after
the given character. The intent is insert aString so that it starts at
the given index.
(String insert i(int) s(string)) -> self
size
Return length of String.
(String size) -> int
ljust
If width is greater than the length of String, returns a new string
of length width with String left justified and padded with pad;
otherwise, returns copied String.
(String ljust width(int) pad(string)) -> string
rjust
If width is greater than the length of String, returns a new string
of length width with String right justified and padded with pad;
otherwise, returns copied String.
(String rjust width(int) pad(string)) -> string
lstrip
Returns a copy of the String with leading whitespace removed.
(String lstrip) -> string
lstrip!
Removes leading whitespace from the String, and returns itself.
(String lstrip!) -> self
rstrip
Returns a copy of the String with trailing whitespace removed.
(String rstrip) -> string
rstrip!
Removes trailing whitespace from the String, and returns itself.
(String rstrip!) -> self
strip
Returns a copy of the String with heading and trailing whitespace removed.
(String strip) -> string
strip!
Removes heading and trailing whitespace from the String, and returns itself.
(String strip!) -> self
partition
Searches sep in the String and returns the part before it, the match, and
the part after it. If it is not found, returns two empty strings and String.
(String partition sep(string)) -> [string, string, string]
rpartition
Searches sep in the String from the end and returns the part before it, the match, and
the part after it. If it is not found, returns two empty strings and String.
(String rpartition! sep(string)) -> [string, string, string]
replace
Replaces the contents of String with the corresponding values in other, and
return itself.
(String replace other(string)) -> self
reverse
Returns a new string with the characters from String in reverse order.
(String reverse) -> string
reverse!
Reverses String in place, and return itself.
(String reverse!) -> self
slice
Returns a substring containing length c characters starting
at the i index. If c is provided, and
c < 0, returns nil;
c == 0, returns empty string;
c > 0, return length of substring from index i.
(String slice i(int) [c(int)]) -> string
slice!
Deletes the specified portion from String, and returns the portion deleted.
(String slice! i(int) [c(int)]) -> string
split
Divides String into substrings based on a sep, returning a list of
these substrings.
(String split sep(string)) -> list
List
List implements part of the Ruby's Array API.
module methods:
value methods:
- +
- -
- *
- |
- &
- <<
- push
- unshift
- >>
- @
- any?
- all?
- clear
- map
- map!
- compact
- compact!
- count
- cycle
- delete@
- delete
- delete_if
- drop
- drop_if
- each
- reverse_each
- empty?
- fetch
- fill
- index
- rindex
- first
- include?
- insert
- join
- keep_if
- last
- size
- pop
- shift
- reject
- reject!
- reverse
- reverse!
- sample
- select
- select!
- slice
- slice!
- sort
- sort!
- take
- take_if
- uniq
- uniq!
- values@
- zip
:
Returns a new list containing item s.
(List : s(any)) -> list
+
Returns a new List containing List and all elements in l.
(List + l(list)...) -> list
-
Returns a new List that is a copy of the original List,
removing all occurrences of any item that also appear in l.
(List - l(list)...) -> list
*
If t is String, return a new string connected by t; If
t is Int, returns a new list built by concatenating the t
copies of self.
(List * t(string|int)) -> string|list
|
Returns a new list contains elements that are union of List and l.
(List | l(list)) -> list
&
Returns a new list contains elements that are intersection of List and l.
(List & l(list)) -> list
<<
Append data in the end of list, and return itself.
(List << data(any)...) -> self
push
It is an alias of <<.
(List push data(any)...) -> self
unshift
Prepend data in the heading of list, and return itself.
(List unshift data(any)...) -> self
>>
Pop up n elements from the end of List, and return itself.
if n is not provided, it is 1 by default; n is in [1, size).
(List >> [n(int)]) -> self
@
Returns the element at index i. A negative index counts from the end of self.
Raise Error if the index is out of range.
(List @ [i(int)]) -> any
any?
Passes each item into f as first parameter to evaluate a value
which will be converted to true/false. Any of true result of f
will stop loop call and return true, otherwise return false.
(List any? f(lambda)) -> bool
all?
Passes each item into f as first parameter to evaluate a value
which will be converted to true/false. Return true if all results
are true, or false.
(List all? f(lambda)) -> bool
clear
Remove all elements from List, and return itself.
(List clear) -> self
map
Returns a new list with the results of running f once
for every item in List.
(List map f(lambda)) -> list
map!
Replace each item with the result of running f once for it,
and return itself.
(List map! f(lambda)) -> self
compact
Returns a copy of List with all nil elements removed.
(List compact) -> list
compact!
Removes nil elements from List, and return itself.
(List compact!) -> self
count
Returns the number of elements.
If i is provided, counts the number of i.
(List count [i(any)]) -> int
cycle
Calls the given f for each item n times, and return List itself.
(List cycle n(int) f(lambda)) -> self
delete@
Deletes the element at the specified index i, returning that element,
or raise Error if the index is out of range;
or nil if List is empty.
(List delete@ i(int)) -> any
delete
Deletes all elements from self that are equal to data.
Returns data, or nil if no matching item found.
(List delete data(any)) -> any
delete_if
Deletes every element of self for which f evaluates to true.
(List delete_if f(lambda)) -> self
drop
Drops first n elements from List and returns the rest of the elements
in an array. n is 1 by default.
(List drop [n(int)]) -> list
drop_if
Returns a new list contains elements which passes to f and evaluate
to false.
(List drop_if f(lambda)) -> list
each
Calls f once for each element in self, passing that element as a parameter.
Returns itself.
(List each f(lambda)) -> self
reverse_each
Same as each, but traverses self in reverse order.
(List reverse_each f(lambda)) -> self
empty?
Returns true if List contains no elements.
(List emtpy?) -> bool
fetch
Returns the element at index i, or nil if it does not exsit. If default
is provided and is a Lambda, then default is called with i as parameter
and return the result; otherwise return default.
(List fetch i(int) [default(any)]) -> any
fill
start is 0 by default;
count is size by default;
Fill the List count elements from start with data or evaluate data
with parameter of index if data is Lambda.
(List fill data(any) [start(int)] [count(int)]) -> self
index
Returns the index of the first element in List such that the element is equal
to data or data evaluates to true if data is Lambda.
If no match, returns nil.
(List index data(any)) -> int
rindex
Returns the last index of the first element in List such that the element is equal
to data or data evaluates to true if data is Lambda.
If no match, returns nil.
(List rindex data(any)) -> int
first
Returns first n elements. n is 1 by default.
If List is empty, returns nil.
(List first [n(int)]) -> list
include?
Returns true if the data is present in self, otherwise returns false.
(List include? data(any)) -> bool
insert
Inserts from i all of the data in sequence, and return itself.
If i is negative, index will calculate from the end.
(List insert i(int) data(any)...) -> self
join
Returns a string join all elements of List by sep, which is empty
string by default.
(List join [sep(string)]) -> string
keep_if
Deletes every element of self for which f evaluates to false,
and returns self.
(List keep_if f(lambda)) -> self
last
Returns last n elements. n is 1 by default.
If List is empty, returns nil.
(List last [n(int)]) -> list
size
Returns the count of elements.
(List size) -> int
pop
Removes the last n elements from List and returns it.
If size < n, returns entire List copy.
If size > n > 1, returns a list.
If n == 1, returns the last element.
If n < 1, returns [].
If List is empty, return nil.
(List pop [n(int)]) -> any
shift
Removes the first n elements from List and returns it.
If size < n, returns entire List copy.
If size > n > 1, returns a list.
If n == 1, returns the last element.
If n < 1, returns [].
If List is empty, return nil.
(List shift [n(int)]) -> any
reject
Returns a new list containing the items in self for which
the f is false.
(List reject f(lambda)) -> list
reject!
Deletes every element of self for which the block evaluates to true,
if no changes made returns nil.
(List reject! f(lambda)) -> self
reverse
Returns a new list containing self‘s elements in reverse order.
(List reverse) -> list
reverse!
Reverses self in place.
(List reverse!) -> self
sample
Choose a random element or n random elements from List.
(List sample) -> any
select
Returns a new list containing all elements of List for which
f returns true.
(List select f(lambda)) -> list
select!
Invokes f passing in successive elements from self, deleting
elements for which f returns false.
(List select! f(lambda)) -> self|nil
slice
Returns the element at index i, or returns a list starting at
the start index i and continuing for c elements.
(List slice i(int) [c(int)]) -> list|nil
slice!
Deletes the element(s) given by an index i.
Returns the deleted object (or objects), or nil
if the index is out of range,
or List is empty.
(List slice! i(int) [c(int)]) -> list|nil
sort
Returns a new list created by sorting self.
(List sort [f(lambda)]) -> list
sort!
Sorts self in place.
(List sort! [f(lambda)]) -> self
take
Returns first n elements from List.
(List take n(int)) -> list
take_if
Returns a new list contains the elements that passed to f
and evaluate to true.
(List take_if f(lambda)) -> list
uniq
Returns a new list by removing duplicate values in self.
(List uniq) -> list
uniq!
Removes duplicate elements from self.
(List uniq!) -> self
values@
Returns a list containing the elements in self corresponding
to the indices i. If index i is out of range, nil is filling.
(List values@ i(int)...) -> list
zip
Converts any arguments to list, then merges elements of self with
corresponding elements from each argument.
If the size of any argument is less than the size of the initial list,
nil values are supplied.
(List zip) -> list
Dict
Dict implements part of the Ruby's Hash API.
module methods:
value methods:
- <<
- any?
- all?
- clear
- clone
- delete
- delete_if
- each
- empty?
- fetch
- keep_if
- key
- keys
- key?
- include?
- member?
- size
- merge
- merge!
- replace
- reject
- reject!
- select
- select!
- shift
- to_l
- value?
- values
- values@
:
Create and return a new Dict value.
(Dict :) -> dict
<<
Store a new pair of key-value into dict. If value is not
provided, nil is default value.
(Dict << key(string) [value(any)]) -> string
any?
Passes each dict key-value pair into f as first and second
parameter to evaluate a value which will be converted to true/false.
Any of true result of f will stop loop call and return true,
otherwise return false.
(Dict any? [f(lambda)]) -> bool
all?
Passes each dict key-value pair into f as first and second
parameter to evaluate a value which will be converted to true/false.
Return true if all results are true, or false.
(Dict all? [f(lambda)]) -> bool
clear
Remove all key-value pairs from Dict, and return itself.
(Dict clear) -> self
clone
Return a new copy of Dict.
(Dict clone) -> dict
delete
Delete key from Dict, and return value if key is existing key or nil.
(Dict delete key(string)) -> any
delete_if
Passes every key and value pair to f to evaluate. It will delete key
from Dict if result is true.
(Dict delete_if f(lambda)) -> self
each
Passes each key and value pair to f to evaluate. returns Dict itself.
(Dict each f(lambda)) -> self
empty?
Test if the Dict has no key.
(Dict empty?) -> bool
fetch
Looks up key in Dict. If the key exists, the value is returned.
Otherwise, it returns default. There is a special case of default.
If default is a Lambda, the value will be passed to default
lambda as a parameter, and then return the final result of lambda.
(Dict fetch key(string) [default(any)]) -> any
keep_if
Passes every key and value pair to f to evaluate. It will delete key
from Dict if result is false.
(Dict keep_if f(lambda)) -> self
key
If value is stored value in Dict then return the corresponding key.
Otherwise, return nil.
(Dict key value(any)) -> string
keys
Returns List of all keys.
(Dict keys) -> list
key?
Test if key is a key in Dict.
(Dict key? key(string)) -> bool
include?
It is an alias of key?
(Dict include? key(string)) -> bool
member?
It is an alias of key?
(Dict member? key(string)) -> bool
size
Return the number of key-value pairs.
(Dict size) -> int
merge
Returns a new Dict merged from Dict and d. If
a key exists in both dict, the value in the Dict is retained.
If f is provided, then value will be passed to f as a parameter,
and then the calculation result of f will replace the value.
(Dict merge d(dict) [f(lambda)]) -> dict
merge!
Combine d into Dict. If the key does not exist in Dict. it will
be merged directly. If the key already exists and f is provided, then
the value corresponding to the key is as a parameter to calculate f,
and the result is as the value in the Dict.
(Dict merge! d(dict) [f(lambda)]) -> self
replace
Replace all key-value pairs of Dict with the pairs of d.
(Dict replace d(dict)) -> dict
reject
Create a new dict with key-value pairs copied from Dict which
passes to f as first and second parameters, and is evaluated to false.
(Dict reject f(lambda)) -> dict
reject!
Remove the key-value pairs from Dict which passes to f as first
and second parameters, and is evaluated to true.
(Dict reject! f(lambda)) -> self
select
Create a new dict with key-value pairs copied from Dict which
passes to f as first and second parameters, and is evaluated to true.
(Dict select f(lambda)) -> dict
select!
Remove the key-value pairs from Dict which passes to f as first
and second parameters, and is evaluated to false.
(Dict select! f(lambda)) -> self
shift
Pop up a key-value pair as 2-element list, where first is key and
second is value.
(Dict shift) -> [string, any]
to_l
Returns a list of 2-element list of key-value pair.
(Dict to_l) -> list
value?
Test if value is stored in Dict.
(Dict value? value(any)) -> bool
values
Returns a list of all value stored in Dict.
(Dict values) -> list
values@
Return a list containing the value corresponding to all key.
If key does not exist, value will be nil.
(Dict values@ key(string)...) -> list
RegExp
It is wrapper of Golang RegExp.
module methods:
value methods:
:
Returns a new regular expression value.
(RegExp: expr(string)) -> RegExp
match?
Reports whether source contains any match of the regular expression.
(RegExp match? source(string)) -> bool
expr
Returns source text to compile regular expression.
(RegExp expr) -> string
groups
Returns the number of parenthesized subexpressions in the regular expression.
(RegExp groups) -> int
names
Returns the names of the parenthesized subexpressions in the regular expression.
(RegExp names) -> [string...]
literal_prefix
Returns a 2-element list [literal boolean], where literal string that must begin any
match of the regular expression. It returns the boolean true if the literal string
comprises the entire regular expression.
(RegExp literal_prefix) -> [string, boolean]
longest
Makes future searches prefer the leftmost-longest match.
(RegExp longest) -> self
find
Returns a string holding the text of the leftmost match in s of the regular expression. If there is no match, the return value is an empty string, but it will also be empty if the regular expression successfully matches an empty string.
(RegExp find s(string)) -> string
find_all
Returns a list of all successive matches of the expression.
i finger out number of results you want.
(RegExp find_all s(string) [i(int)]) -> [string...]
Range
module methods:
value methods:
:
Return a new Value of Range.
begin is left bound, and optional end is right bound.
(Range: begin(int) [end(int)]) -> Range
begin
Return the first number of Range.
(Range begin) -> int
end
Return the last number of Range.
(Range end) -> int
count
Return length of Range.
(Range count) -> int
>>
Range walk through begin to end and return itself.
f is called for each step.
(Range >> f(lambda)) -> self
<<
Range walk reversely from end to begin and return itself.
f is called for each step.
(Range << f(lambda)) -> self
>>>
Range walk through begin to end and return itself.
s indicates the step width, and f is called for each step.
(Range >>> s(int) f(lambda)) -> self
<<<
Range walk reversely from end to begin and return itself.
s indicates the step width, and f is called for each step.
(Range <<< s(int) f(lambda)) -> self
sample
Return random number between the begin and end.
(Range sample) -> self
Error
module methods:
value methods:
:
(Error: msg(string)) -> error
message
Returns error description.
(Error message) -> string
puts
lambda methods:
:
puts display all parameters in sequence into stdout.
(puts: any...) -> nil
show
lambda methods:
:
show display all parameters with info in sequence into stdout.
(show: any...) -> nil
noop
lambda methods:
:
(noop:) -> nil
assert
lambda methods:
:
assert expect the any as true, or it raises an error, with
message string if provided.
(assert: [any [string]]) -> nil
Libraries
Yes, let's provide some very nice, very useful libraries. In the future, these libraries will continue to grow.
Math
module methods:
ceil
(Math ceil i(float)) -> float
floor
(Math floor i(float)) -> float
sin
(Math sin i(float)) -> float
asin
(Math asin i(float)) -> float
sinh
(Math sinh i(float)) -> float
asinh
(Math asinh i(float)) -> float
cos
(Math cos i(float)) -> float
acos
(Math acos i(float)) -> float
cosh
(Math cosh i(float)) -> float
acosh
(Math acosh i(float)) -> float
tan
(Math tan i(float)) -> float
atan
(Math atan i(float)) -> float
tanh
(Math tanh i(float)) -> float
atanh
(Math atanh i(float)) -> float
os
module methods:
- stdin
- stdout
- stderr
- platform
- arch
- exit
- get_env
- get_env_ex
- set_env
- unset_env
- clear_env
- environ
- user_home_dir
- user_config_dir
- user_cache_dir
- hostname
- uid
- gid
- euid
- egid
- groups
- start_process
- find_process
stdin
open File pointing to the standard input file descriptor.
(os stdin) -> file
stdout
open File pointing to the standard output file descriptor.
(os stdout) -> file
stderr
open File pointing to the standard error file descriptor.
(os stderr) -> file
platform
it is runtime.GOOS in Golang.
(os platform) -> string
arch
it is runtime.GOARCH in Golang.
(os arch) -> string
exit
exit causes the current program to exit with the given status code. Conventionally,
code zero indicates success, non-zero an error. The program terminates immediately,
finally sub-expression in try will not execute.
(os exit code(int)) -> nil
get_env
Return the value of the environment variable named by the key. It returns the value,
which will be empty if the variable is not present.
(os get_env key(string)) -> string
get_env_ex
Return a 2-element list value of the environment variable named by the key and bool
value which indicate whether the key exists.
(os get_env_ex key(string)) -> [string,bool]
set_env
Sets the value of the environment variable named by the key. It returns an error, if any.
(os set_env key(string) val(string)) -> nil
unset_env
Unsets a single environment variable. It returns an error, if any.
(os unset_env key(string)) -> nil
clear_env
Deletes all environment variables.
(os clear_env) -> nil
environ
Returns a dict of strings representing the environment.
(os environ) -> dict
user_home_dir
Returns the current user's home directory. It returns an error, if any.
(os user_home_dir) -> string
user_config_dir
Returns the default root directory to use for user-specific
configuration data. Users should create their own application-specific
subdirectory within this one and use that. It returns an error, if any.
(os user_config_dir) -> string
user_cache_dir
Returns the default root directory to use for user-specific cached data.
Users should create their own application-specific subdirectory within
this one and use that. It returns an error, if any.
(os user_cache_dir) -> string
hostname
Returns the host name reported by the kernel. It returns an error, if any.
(os hostname) -> string
uid
Returns the numeric user id of the caller.
(os uid) -> int
gid
Returns the numeric group id of the caller.
(os gid) -> int
euid
Returns the numeric effective user id of the caller.
(os euid) -> int
egid
Returns the numeric effective group id of the caller.
(os egid) -> int
groups
Returns a list of the numeric ids of groups that the caller belongs to.
It returns an error, if any.
(os groups) -> [int...]
start_process
Starts a new process with the program, arguments and attributes specified by name, args.
(os start_process name(string) args(any)...) -> process
find_process
Looks for a running process by its pid.
(os find_process pid(int)) -> process
os/Process
value methods:
release
Releases any resources associated with the proc.
(proc release) -> nil
kill
Kill causes the proc to exit immediately.
(proc kill) -> nil
wait
Waits for the proc to exit, and then returns a
os/ProcessState describing its status.
(proc wait) -> state
signal
Sends a signal to the Process.
| Signal | Desc |
|---|---|
| SIGABRT | 0x6 |
| SIGALRM | 0xe |
| SIGBUS | 0xa |
| SIGCHLD | 0x14 |
| SIGCONT | 0x13 |
| SIGEMT | 0x7 |
| SIGFPE | 0x8 |
| SIGHUP | 0x1 |
| SIGILL | 0x4 |
| SIGINFO | 0x1d |
| SIGINT | 0x2 |
| SIGIO | 0x17 |
| SIGIOT | 0x6 |
| SIGKILL | 0x9 |
| SIGPIPE | 0xd |
| SIGPROF | 0x1b |
| SIGQUIT | 0x3 |
| SIGSEGV | 0xb |
| SIGSTOP | 0x11 |
| SIGSYS | 0xc |
| SIGTERM | 0xf |
| SIGTRAP | 0x5 |
| SIGTSTP | 0x12 |
| SIGTTIN | 0x15 |
| SIGTTOU | 0x16 |
| SIGURG | 0x10 |
| SIGUSR1 | 0x1e |
| SIGUSR2 | 0x1f |
| SIGVTALRM | 0x1a |
| SIGWINCH | 0x1c |
| SIGXCPU | 0x18 |
| SIGXFSZ | 0x19 |
(proc signal s(string)) -> nil
os/ProcessState
value methods:
pid
Returns the process id of the exited process.
(state pid) -> pid
exited?
Reports whether the program has exited.
(state exited?) -> bool
success?
Reports whether the program exited successfully, such as with exit status 0 on Unix.
(state success?) -> bool
system_time
Returns the system CPU time time/Duration of the exited process and its children.
(state system_time) -> duration
user_time
Returns the user CPU time time/Duration of the exited process and its children.
(state user_time) -> duration
fs
module methods:
- perm
- remove
- open
- open_file
- create
- exist?
- read_all
- read_line
- chtimes
- move
- remove_all
- chdir
- walk
- chmod
- chown
FileMode type
| Mode | Desc |
|---|---|
| ModeDir | d: is a directory |
| ModeAppend | a: append-only |
| ModeExclusive | l: exclusive use |
| ModeTemporary | T: temporary file; Plan 9 only |
| ModeSymlink | L: symbolic link |
| ModeDevice | D: device file |
| ModeNamedPipe | p: named pipe (FIFO) |
| ModeSocket | S: Unix domain socket |
| ModeSetuid | u: setuid |
| ModeSetgid | g: setgid |
| ModeCharDevice | c: Unix character device |
| ModeSticky | t: sticky |
| ModeIrregular | ?: non-regular file; nothing else is known about this file |
FileMode permission
Normally, use expression such as (fs perm 777) to generate a permission
FileMode.
flag
Exactly one of O_RDONLY, O_WRONLY, or O_RDWR must be specified. The remaining values may be or'ed in to control behavior.
| Flag | Desc |
|---|---|
| O_RDONLY | open the file read-only |
| O_WRONLY | open the file write-only |
| O_RDWR | open the file read-write |
| O_CREATE | create a new file if none exists |
| O_EXCL | used with O_CREATE, file must not exist |
| O_APPEND | append data to the file when writing |
| O_TRUNC | truncate regular writable file when opened |
| O_SYNC | open for synchronous I/O |
perm
Create a permission fs/FileMode.
(fs perm p(int)) -> filemode
remove
Remove the file name. It returns an error, if any.
(fs remove name(string)) -> nil
open
Open the file name. It returns an error, if any.
(fs open name(string)) -> file
open_file
Open file for generalize purple. Users can use OS_RDONLY flag for reading, OS_WRONLY flag for writing, etc.
(fs open_file name(string) flag(int) mode(filemode)) -> file
create
Create a new file name. It returns an error, if any.
(fs create name(string)) -> file
exist?
Test whether the file name exists.
(fs exist? name(string)) -> bool
read_all
Read all content in file name. It returns an error, if any.
(fs readall name(string)) -> string
read_line
Read lines in file name by calling the callback for each line.
Every line as first parameter of callback.
It returns an error, if any.
(fs read name(string) callback(lambda)) -> nil
chtimes
Changes the access and modification times of the name file
(fs chtimes name(string) atime(time) mtime(time)) -> nil
move
Moves source to target. If target already exists and is
not a directory, move replaces it.
(fs move source(string) target(string)) -> nil
remove_all
Removes path and any children it contains.
(fs remove_all path(string)) -> nil
chdir
Changes the current working directory to path.
(fs chdir path(string)) -> nil
walk
Walks the file tree rooted at root, calling callback for each
file or directory in the tree, including root.
file path is as callback first parameter,
file info is as callback second parameter.
(fs walk root(string) callback(lambda)) -> nil
chmod
Changes the mode of the name file to mode.
(fs chmod name(string) mode(filemode)) -> nil
chown
Changes the numeric uid and gid of the name file.
On Windows, it will raise error.
(fs chown name(string) uid(int) gid(int)) -> nil
fs/File
value methods:
info
Returns the fs/FileInfo structure describing file.
(file info) -> fileinfo
chmod
Changes the mode of the file to mode.
(file chmod mode(filemode)) -> self
chown
Changes the numeric uid and gid of the named file. On Windows, it will raise error.
(file chown uid(int) gid(int)) -> self
read
For each character, calling callback. If callback
return false, loop will exit.
(file read callback(lambda)) -> nil
read_line
For each line, calling callback. If callback
return false, loop will exit.
(file read_line callback(lambda)) -> nil
write
All parameters are first converted into strings, and then written to the file.
It returns an error, if any.
(file write any...) -> nil
write_line
All parameters are first converted into strings, and then written to the file.
At last, append a new line.
It returns an error, if any.
(file write_line any...) -> nil
close
Close the file to release the resource.
It returns an error, if any.
(file close) -> nil
fs/FileMode
value methods:
dir?
Reports whether mode describes a directory.
(mode dir?) -> bool
regular?
Reports whether mode describes a regular file.
(mode regular?) -> bool
mode_type
Returns type bits.
(mode mode_type) -> mode
mode_perm
Returns the Unix permission bits.
(mode mode_perm) -> mode
|
Returns the or operation result of mode and mode1.
(mode | mode1(mode)) -> mode
fs/FileInfo
value methods:
dir?
Alias of dir? of fs/FileMode.
(info dir?) -> bool
name
File base name.
(info name) -> string
size
Returns length in bytes for regular files.
(info size) -> int
mode
Returns file mode fs/FileMode bits.
(info mode) -> mode
modified_time
Returns modification time Time.
(info modified_time) -> time
exec
module methods:
Command
Returns the Cmd struct to execute the named program with the given arguments.
(exec Command name(string) args(string)...) -> cmd
$
Alias of Command.
(exec $ name(string) args(string)...) -> cmd
Pipe
Executes cmd one by one in the pipeline, and returns
a 2-elements list, where first is stdout of last cmd, and
second is stderr of cmd. It returns an error, if any.
(exec Piple cmd(cmd)...) -> [stdout, stderr]
|
Alias of Pipe.
(exec | cmd(cmd)...) -> [stdout, stderr]
exec/Cmd
value methods:
Output
Runs the command and returns its standard output. It returns an error, if any.
(cmd Output) -> string
CombinedOutput
Runs the command and returns its combined standard output and standard error.
It returns an error, if any.
(cmd CombinedOutput) -> string
Run
Starts the specified command and waits for it to complete. It returns an error, if any.
(cmd Run) -> nil
Start
Starts the specified command but does not wait for it to complete.
It returns an error, if any.
(cmd Start) -> nil
Wait
Waits for the command to exit and waits for any copying to stdin or
copying from stdout or stderr to complete. It returns an error, if any.
(cmd Wait) -> nil
http
module methods:
get
Send a http GET request with http/Query optionally, and return a http/Response.
(http get url(string) [query(query)]) -> response
post
Send a http POST request with any data, and return a http/Response.
(http post url(string) data(any)) -> response
post_form
Send a http POST request with http/Query, and return a http/Response.
Header entity Content-Type: application/x-www-form-urlencoded is attached.
(http post_form url(string) data(query)) -> response
post_json
Send a http POST request with any data that will be encoded as json, and return a http/Response.
Header entity Content-Type: application/json is attached.
(http post_json url(string) data(query)) -> response
put_form
Send a http PUT request with http/Query, and return a http/Response.
Header entity Content-Type: application/x-www-form-urlencoded is attached.
(http put_form url(string) data(query)) -> response
put_json
Send a http PUT request with any data that will be encoded as json, and return a http/Response.
Header entity Content-Type: application/json is attached.
(http put_json url(string) data(query)) -> response
patch_form
Send a http PATCH request with http/Query, and return a http/Response.
Header entity Content-Type: application/x-www-form-urlencoded is attached.
(http path_form url(string) data(query)) -> response
patch_json
Send a http PATCH request with any data that will be encoded as json, and return a http/Response.
Header entity Content-Type: application/json is attached.
(http patch_json url(string) data(query)) -> response
delete
Send a http DELETE request, and return a http/Response.
(http delete url(string)) -> response
head
Send a http HEAD request, and return a http/Response.
(http head url(string)) -> response
options
Send a http OPTIONS request, and return a http/Response.
(http options url(string)) -> response
http/Query
module methods:
value methods:
:
Create a http/Query value.
(http/Query :) -> query
get
Gets the first value associated with the given key.
If there are no values associated with the key, returns
the empty string. To access multiple values, use gets.
(query get key(string)) -> string
gets
Gets the values associated with the given key.
If there are no values associated with the key, returns [].
To access the first value, use get.
(query get key(string)) -> string
set
Sets the key to val. It replaces any existing values.
Returns nil.
(query set key(string) val(string)) -> nil
add
Adds the val to key. It appends to any
existing values associated with key. Returns nil.
(query add key(string) val(string)) -> nil
delete
Deletes the values associated with key. Returns nil.
(query delete key(string)) -> nil
encode
Encodes the values into “URL encoded” form ("bar=baz&foo=quux") sorted by key.
(query encode) -> string
http/Request
module methods:
value methods:
OPTIONS
Create a new OPTIONS request.
(http/Request OPTIONS url(string)) -> request
GET
Create a new GET request.
(http/Request GET url(string)) -> request
POST
Create a new POST request.
(http/Request POST url(string)) -> request
PUT
Create a new PUT request.
(http/Request PUT url(string)) -> request
PATCH
Create a new PATCH request.
(http/Request PATCH url(string)) -> request
DELETE
Create a new DELETE request.
(http/Request DELETE url(string)) -> request
HEAD
Create a new HEAD request.
(http/Request HEAD url(string)) -> request
TRACE
Create a new TRACE request.
(http/Request TRACE url(string)) -> request
header@
Gets first key header entity first value.
(request header@ key(string)) -> string
headers@
Gets first key header entity values as list.
(request headers@ key(string)) -> []
header
override == true, set the key as val;
override == false, append the key value val.
default override is false.
(request header key(string) val(string) [override(bool)]) -> self
headers
Like header, but val is a list of string.
(request headers@ key(string) val(list) [override(bool)]) -> self
query_string
Sets QueryString typeof http/Query of request. returns itself.
(request query_string qs(query)) -> self
basic_auth
Sets the request's Authorization header to use HTTP Basic Authentication
with the provided username and password. return itself.
(request basic_auth username(string) password(string)) -> self
form
Sets form data of request. the request set header
Content-Type: application/x-www-form-urlencoded.
returns itself.
(request form data(query)) -> self
form
Sets json data of request. the request set header
Content-Type: application/json.
returns itself.
(request json data(any)) -> self
http/Response
value methods:
status
Returns http response status, such as 200 OK.
(response status) -> string
status_code
Returns http response status code, such as 200.
(response status_code) -> int
header
Returns header map keys to values.
(response header) -> dict
proto
Returns version HTTP/1.1.
(response proto) -> string
proto_major
Returns version major part 1.
(response proto_major) -> int
proto_minor
Returns version minor part 1.
(response proto_minor) -> int
text
Returns response body.
(response text) -> string
json
Returns response body parsed as json.
(response json) -> any
>>
Call lambda f, and response as parameter of f, return its result.
(response >> f(lambda)) -> any
http/Cookie
module methods:
value methods:
:
Create a http/Cookie value.
(http/Cookie : key(string) val(string)) -> cookie
expire
Sets the expire time of cookie.
(cookie expire time(time)) -> self
path
Sets the path time of cookie.
(cookie path data(string)) -> self
domain
Sets the domain time of cookie.
(cookie domain data(string)) -> self
http/Client
module methods:
value methods:
http
Returns a http client.
(http/Client http) -> client
https
Return a https client.
(http/Client https certfilepath(string) keyfilepath(string)) -> client
proxy
Set the proxy of request. Return itself, or an error, if any.
(client proxy url(string)) -> self
ttl
Set the TTL of request. Return itself, or an error, if any.
(client ttl dur(duration)) -> self
do
Sends http/Request and returns
http/Response, or an error, if any.
(client do request(request)) -> response
time
This module wrappers the Go package time.
module methods:
now
Returns the current local time.
(time now) -> Time
parse
Parses a formatted string and returns the time value it represents.
(time parse {layout}string {value}string) -> Time
parse_in_location
Like parse, but need one more parameter localtion.
location is formatted string like Europe/Berlin, Asia/Shanghai.
(time parse_in_location {layout}string {value}string {location}string) -> Time
unix
Returns the local Time corresponding to the given Unix time, sec seconds
and nsec nanoseconds since January 1, 1970 UTC. It is valid to pass nsec
outside the range [0, 999999999]. Not all sec values have a corresponding
Time value. One such value is 1<<63-1 (the largest Int value).
(time unix {sec}int {nsec}int) -> Time
date
Returns the Time corresponding to
yyyy-mm-dd hh:mm:ss + nsec nanoseconds
in the appropriate zone for that time in the given location.
(time date {year}int {month}int {day}int {hour}int {min}int {sec}int {nsec}int {location}string) -> Time
parse_duration
Parses a duration string. A duration string is a possibly signed sequence of decimal
numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or
"2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
(time parse_duration {duration}string) -> duration
until
Returns the duration until t.
(time until {t}time) -> duration
since
Returns the time elapsed since t.
(time since {t}time) -> duration
sleep
Pauses the current goroutine for at least the duration dur. A negative or zero
duration causes sleep to return immediately.
(time sleep {dur}duration) -> nil
timer
Creates a new time/Timer.
(time timer {dur}duration) -> timer
ticker
Returns a new time/Ticker. The period of the ticks is specified by the dur argument.
The ticker will adjust the time interval or drop ticks to make up for slow receivers.
The duration dur must be greater than zero; if not, ticker will raise an error.
(time ticker {dur}duration) -> timer
time/Time
module methods:
- ANSIC
- UnixDate
- RubyDate
- RFC822
- RFC822Z
- RFC850
- RFC1123
- RFC1123Z
- RFC3339
- RFC3339Nano
- Kitchen
- Stamp
- StampMilli
- StampMicro
- StampNano
value methods:
- format
- clock
- year
- month
- day
- hour
- minute
- second
- nanosecond
- weekday
- date
- iso_week
- zero?
- local
- location
- zone
- unix
- unix_nano
- year_day
- UTC
- add_date
- add
- sub
- round
- truncate
- in
- after?
- before?
- equal?
==
(Time == any) -> bool
formats
| key | value |
|---|---|
| ANSIC | Mon Jan _2 15:04:05 2006 |
| UnixDate | Mon Jan _2 15:04:05 MST 2006 |
| RubyDate | Mon Jan 02 15:04:05 -0700 2006 |
| RFC822 | 02 Jan 06 15:04 MST |
| RFC822Z | 02 Jan 06 15:04 -0700 |
| RFC850 | Monday, 02-Jan-06 15:04:05 MST |
| RFC1123 | Mon, 02 Jan 2006 15:04:05 MST |
| RFC1123Z | Mon, 02 Jan 2006 15:04:05 -0700 |
| RFC3339 | 2006-01-02T15:04:05Z07:00 |
| RFC3339Nano | 2006-01-02T15:04:05.999999999Z07:00 |
| Kitchen | 3:04PM |
| Stamp | Jan _2 15:04:05 |
| StampMilli | Jan _2 15:04:05.000 |
| StampMicro | Jan _2 15:04:05.000000 |
| StampNano | Jan _2 15:04:05.000000000 |
format
Returns a textual representation of the time value formatted according to layout.
(Time format layout(string)) -> string
clock
Returns the hour, minute, and second within the day specified by Time.
(Time clock) -> [hour(int),min(int),sec(int)]
year
Returns the year in which Time occurs.
(Time year) -> int
month
Returns the month of the year specified by Time.
(Time month) -> [int, string]
day
Returns the day of the month specified by Time.
(Time day) -> int
hour
Returns the hour within the day specified by Time, in the range [0, 23].
(Time hour) -> int
minute
Returns the minute offset within the hour specified by Time, in the range [0, 59].
(Time minute) -> int
second
Returns the second offset within the minute specified by Time, in the range [0, 59].
(Time second) -> int
nanosecond
Returns the nanosecond offset within the second specified by Time, in the range [0, 999999999].
(Time nanosecond) -> int
weekday
Returns the day of the week specified by Time.
(Time weekday) -> [int, string]
date
Returns the year, month, and day in which Time occurs.
(Time date) -> [int, [int, string], int]
iso_week
Returns the ISO 8601 year and week number in which Time occurs. Week ranges from 1 to 53.
Jan 01 to Jan 03 of year n might belong to week 52 or 53 of year n-1, and Dec 29 to Dec 31
might belong to week 1 of year n+1.
(Time iso_week) -> [int, int]
zero?
Reports whether Time represents the zero time instant, January 1, year 1, 00:00:00 UTC.
(Time zero?) -> bool
local
Returns Time with the location set to local time.
(Time local) -> time
location
Returns the time zone information associated with Time.
(Time location) -> time
zone
Computes the time zone in effect at time Time, returning the
abbreviated name of the zone (such as "CET") and its offset
in seconds east of UTC.
(Time zone) -> [string, int]
unix
Returns t as a Unix time, the number of seconds elapsed since January 1, 1970 UTC.
The result does not depend on the location associated with Time.
(Time unix) -> int
unix_nano
Returns Time as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC.
(Time unix_nano) -> int
year_day
Returns the day of the year specified by Time, in the range [1,365] for non-leap years,
and [1,366] in leap years.
(Time year_day) -> int
UTC
Returns Time with the location set to UTC.
(Time UTC) -> time
add_date
Returns Time with the location set to UTC.
(Time add_date year(int) month(int) day(int)) -> time
add
Returns the time Time+dur.
(Time add dur(duration)) -> time
sub
returns the duration Time-time.
(Time sub time(time)) -> duration
round
Returns the result of rounding Time to the nearest multiple of dur (since the zero time).
(Time round dur(duration)) -> time
truncate
Returns the result of rounding Time down to a multiple of dur (since the zero time).
(Time truncate dur(duration)) -> time
in
Returns a copy of t representing the same time instant, but with the copy's location information
set to loc for display purposes.
(Time in loc(string)) -> time
after?
reports whether the time instant Time is after t.
(Time after? t(time)) -> bool
before?
reports whether the time instant Time is before t.
(Time before? t(time)) -> bool
equal?
reports whether Time and t represent the same time instant.
(Time equal? t(time)) -> bool
time/Duration
module methods:
value methods:
Nanosecond
Create a time/Duration value, int is 1 as default.
(time/Duration Nanosecond [int]) -> duration
Microsecond
Create a time/Duration value, int is 1 as default.
(time/Duration Microsecond [int]) -> duration
Millisecond
Create a time/Duration value, int is 1 as default.
(time/Duration Millisecond [int]) -> duration
Second
Create a time/Duration value, int is 1 as default.
(time/Duration Second [int]) -> duration
Minute
Create a time/Duration value, int is 1 as default.
(time/Duration Minute [int]) -> duration
Hour
Create a time/Duration value, int is 1 as default.
(time/Duration Hour [int]) -> duration
nanoseconds
Returns the duration as an integer nanosecond count.
(time/Duration nanoseconds) -> int
microseconds
Returns the duration as an integer microsecond count.
(time/Duration microseconds) -> int
milliseconds
Returns the duration as an integer millisecond count.
(time/Duration milliseconds) -> int
seconds
Returns the duration as a floating point number of seconds.
(time/Duration seconds) -> float
minutes
Returns the duration as a floating point number of minutes.
(time/Duration minutes) -> float
hours
Returns the duration as a floating point number of hours.
(time/Duration hours) -> float
round
Returns the result of rounding time/Duration to the nearest multiple of
duration. The rounding behavior for halfway values is to round away from
zero. If the result exceeds the maximum (or minimum) value that can be stored
in a Duration, round returns the maximum (or minimum) duration.
If duration <= 0, round returns time/Duration unchanged.
(time/Duration round duration) -> duration
truncate
Returns the result of rounding time/Duration toward zero to a multiple of
duration. If duration <= 0, truncate returns time/Duration unchanged.
(time/Duration truncate duration) -> duration
time/Timer
value methods:
>>
lambda will be executed with Time value as the first parameter, after duration of time/Timer expired.
(time/Timer >> lambda) -> nil
time/Ticker
value methods:
>>
lambda will be executed with Time value as the first parameter,
in every Duration of time/Ticker. If you want to exit
the loop calling, let lambda return true.
(time/Ticker >> lambda) -> nil
encoding/base32
module methods:
encode
(encoding/base32 encode string) -> string
decode
(encoding/base32 decode string) -> string
encoding/base64
module methods:
encode
(encoding/base64 encode string) -> string
decode
(encoding/base64 decode string) -> string
encoding/json
module methods:
encode
(encoding/json encode any) -> string
decode
(encoding/json decode string) -> nil|string|int|float|list|dict
crypto/md5
lambda methods:
:
crypto/md5 calculate the md5 result of string.
(crypto/md5: string) -> string
crypto/sha1
lambda methods:
:
crypto/sha1 calculate the sha1 result of string.
(crypto/sha1: string) -> string
crypto/sha256
lambda methods:
:
crypto/sha256 calculate the sha256 result of string.
(crypto/sha256: string) -> string
x
Installation
The latest delivery version is v0.2.3. Different binaries are availiable for Windows, Linux and macOS platforms.
Downloads
| platform | |
|---|---|
| Windows64-bit processor | aquarius.0.2.3.windows.amd64 |
| Linux64-bit processor | aquarius.0.2.3.linux.amd64 |
| Apple macOSM1 64-bit processor | aquarius.0.2.3.darwin.arm64 |
Installation
- Download the
zipresource pack, - and unzip it to your
$HOMEdirectory. - Ensure that decompressed
aqroraqr.exefile has executable permission.
zhoudefa@DefaBook .aquarius % ll ./bin/aqr
-rwxr-xr-x 1 zhoudefa staff 8272496 Dec 18 13:47 aqr
Now, you can call version command to check the installation. If it displays version information correctly, congratulations, the installation is successful.
zhoudefa@DefaBook .aquarius % ./bin/aqr version
aquarius 0.2.3
Commands
There are two main commands: build and run.
We need to pay attention to the flags of each command, which affect the actual performance of the command.
build
We can build a single .aqr file or a direcory.
zhoudefa@DefaBook aquarius % ./bin/aqr build ./ext/test/test.aqr
run
Let's run the aquarius.
zhoudefa@DefaBook aquarius % ./bin/aqr run ./ext/test/test.aqr
help
More commands, please call --help for details.
zhoudefa@DefaBook aquarius % ./bin/aqr --help
NAME:
aquarius(aqr) - aquarius is a funny script.
USAGE:
aqr [global options] command [command options] [arguments...]
AUTHOR:
Defa Zhou <zhoudefa666@163.com>
COMMANDS:
version show aquarius version
build build aquarius source code to binary
run execute an aquarius file
GLOBAL OPTIONS:
--help, -h show help (default: false)
Plugins
VSCode plugin
In order to provide a friendly user experience and improve efficiency, we are going to develop a plugin for the VSCode platform. At present, it is a simple beginning, and we need your help to improve it.
Installation
In the Extensions tab, please fill aquarius- in Search Extension in Marketplace field, search and install it.

Wanted
Sincerely welcome you to participate in the development of plugin and improve functions, to make Aquarius more pleasant to use.