Types
Integer type. On 64 bit platforms it's a 61 bit signed integer
- Eachable1
-
Eachable which each() calls the callback with one argument
- Num
Constructors
Int(r:Real)
Convert Real (floating) number to Int. Floating part is truncated.
Int(s:Str)
Convert base-10 string to Int.
Throws InvalidArgument if the number in s is not well-formatted.
Methods
*(arr:Arr, n:Int)
Repeat all elements in arr n times
*(cb:Fun, n:Int)
Call cb n times without any parameters and accumulate the results.
<=(a:Int, b:Int)
Less-than-or-equal comparison
>=(a:Int, b:Int)
Greater-than-or-equal comparison
[](al:ArrLike, idx:Int)
Set element in the underlying array.
[](arr:Arr, idx:Int)
Get array element by index from the end
[](s:Str, i:Int)
Get given character (currently byte) of the string
[](s:Str, i:Int)
Get given character (currently byte) of the string.
TODO: Document InvalidArgument exception.
[](my:MatchY, idx:Int)
Convenience method to access matches in MatchY
c_pcre_exec(regexp:RegExp, subject:Str, offset:Int, options:Int)
Search string for regular expression. Uses PCRE_EXEC(3). Do not use this function directly!
chr(code:Int)
Get character (byte) by it's ordinal value.
code(n:Int)
Convert an Int to NGS code that would produce the integer when executed. Not fully functional yet.
collector(n:Int, body:Fun)
Defines collector { ... collect(...) ... } behaviour for integers (summarizes collected items).
drop(i:Iter, n:Int)
Fetch and drop next n values from iterator i.
each(arr:Arr, n:Int, cb:Fun)
Process each N elements of an Array at a time.
Throws InvalidArgument if number of items in arr is not divisible by n.
cb is called as cb(eltI, ..., eltJ) where I is multiple of n and J is I+n-1
each(n:Int, cb:Fun)
Iterate from zero up to but not including n
echo(fd:Int, s:Str)
Print given string and a newline to a file referenced by descriptor.
init(pipe:Pipe, direction:Int)
Pipe constructor. Create UNIX pipe using PIPE(2). Throws PipeCreateFail if pipe can not be created.
isatty(fd:Int)
Check whether given fd represents a TTY. Uses ISATTY(3).
Throws TtyCheckFail.
kill(pid:Int, sig:Int=15)
Send signal to a process. Uses KILL(2). Throws KillFail on error.
kill(p:Process, sig:Int=15)
Send signal to a Process. Uses KILL(2).
Throws InvalidArgument if Process does not have "pid".
Throws KillFail on error.
limit(a:Arr, l:Int)
Truncate an array if necessary so it would have maximum l elements.
limit(h:Hash, l:Int)
Truncate a Hash if necessary so it would have maximum l key-value pairs.
limit(s:Str, n:Int, marker:Str=)
Truncate a string if necessary so it would have maximum n characters (currently bytes).
map(arr:Arr, n:Int, mapper:Fun)
Map each N elements of an Array at a time.
mapper is called as cb(eltI, ..., eltJ) where I is multiple of n and J is I+n-1
Throws InvalidArgument if number of items in arr is not divisible by n.
mapper is called as mapper(eltI, ..., eltJ) where I is multiple of n and J is I+n-1
map_base_idx(base:Any, n:Int, mapper:Fun)
EXPERIMENTAL!
Map when there is more than one element. If there is exactly one element, it's left as is
ord(s:Str, idx:Int)
Get character (byte) ordinal value. Throws InvalidArgument if idx is not pointing into s.
rand(something:Any, n:Int)
Pick n elements from something. Uniqueness of picked elements is not guaranteed.
rand(n:Int)
Pick random number from 0 up to but not including n
rand_uniq(something:Any, n:Int)
Pick n random unique elements from something
read(fd:Int)
Read all data from a file referenced by file descriptor without parsing it.
retry(times:Int=60, sleep:Any=1, logger:Fun=(a function), success_predicate:Any=(a function), catch_exceptions:Bool=true, title:Any=<retry>, progress_cb:Fun=(a function), success_cb:Fun=(a function), fail_cb:Any=null, body:Fun=(a function))
Retry. Executes given "body" "times" times. Throws RetryFail if all calls fail and fail_cb is not provided.
srand(seed:Int)
Seed random generator. Uses SRANDOM(3).
Str(x:Any, target_width:Int)
Convert anything to Str of a given width
Str(s:Str, target_width:Int)
Pad a string to given width with spaces
Str(n:Int, target_width:Int)
Convert a number to a string and pad it
take(i:Iter, n:Int)
Fetch and convert to array next n values from iterator i.
times(n:Int, cb:Fun)
Call cb n times without arguments.
write(s:Str, fd:Int)
Write data to a file referenced by file descriptor.
WARNING: Incomplete implementation.
TODO: handle errors, throw exceptions.
TODO: handle possible EINTR.
~(s:Str, r:RegExp, offset:Int=0, options:Int=0)
Find PCRE regular expression in s. Empty string without options returns MatchN. Throws Error if more than 20 captures are used or if there is an error during matching.