ATSLIB/libats/ML/strarr
The functions declared in this package are primarily for processing strings
in functional programming, where a string is represented as an array of
characters plus its size. Sometimes, the name strarr-value is used
to refer to such a string.
Synopsis
typedef strarr = strarr_type
Synopsis
abstype strarr_type = ptr
Synopsis
castfn
strarr2array
(cs: strarr):<> array0(char)
Description
This cast function turns a strarr-value to an array of characters.
Synopsis
castfn
array2strarr
(cs: array0(char)):<> strarr
Description
This cast function turns an array of characters to a strarr-value.
Synopsis
fun
strarr_make_string
(str: string):<!wrt> strarr
Description
This function, which overloads the symbol strarr, builds
a strarr-value corresponding to a given C-style string.
Synopsis
fun
strarr_make_substring
(str: string, st: size_t, ln: size_t):<!wrt> strarr
Synopsis
overload
strarr_get_at with strarr_get_at_gint of 0
overload
strarr_get_at with strarr_get_at_guint of 0
Synopsis
fun{tk:tk}
strarr_get_at_gint
(str: strarr, i: g0int(tk)):<!exn> char
Description
Given a strarr-value and an integer i, this function returns
character i in the string represented by the strarr-value. It
is O(1)-time.
Synopsis
fun{tk:tk}
strarr_get_at_guint
(str: strarr, i: g0uint(tk)):<!exn> char
Description
This function does the same as strarr_get_at_gint
except for taking as its second argument an unsigned integer.
Synopsis
fun
strarr_get_range
(
strarr, i0: size_t, i1: size_t
) : string
Description
Given a strarr-value str of length n and two sizes i0 and i1 satisfying i0
<= n and i1 <= n, this function returns a string str2 of length n2
satisfying the following conditions: (1) if i0 <= i1, then n2 equals i1-i0
and str2[k] = str[i0+k] for 0 <= k < n2; (2) if i1 < i0, then n2 equals
i0-i1 and str2[k]=str[i0-k-1] for 0 <= k < n2. For instance, if i0 and i1
equal n and 0, respectively, then str2 is the reverse of str. If either
the second or the third argument of the function exceeds n, then it is
replaced with n. The time complexity of the function is O(n2), where n2 is
the length of the returned string.
Synopsis
fun
print_strarr(str: strarr): void
Description
This function prints a given strarr-value onto STDOUT.
Synopsis
fun
prerr_strarr(str: strarr): void
Description
This function prints a given strarr-value onto STDERR.
Synopsis
fun
fprint_strarr
(
out: FILEref, str: strarr
) : void
Synopsis
fun
strarr_copy(str: strarr):<!wrt> strarr
Description
Given a strarr-value, this function returns a copy of it.
Synopsis
fun
strarr_append
(x1: strarr, x2: strarr):<!wrt> strarr
Description
This function, which overload the symbol +, returns the
concatenation of two given strings. It is O(n)-time, where n is the length
of the returned strarr-value.
Synopsis
fun
strarr_tabulate
{n:int}
(
n: size_t(n), f: cfun(sizeLt(n), char)
) : strarr
Description
Given a size n and a function f, this function returns an strarr-value str
of size n such that each str[i] is initialized with the value returned by f(i),
where i ranges from 0 until n-1, inclusive.
Synopsis
fun
strarr_foreach
(str: strarr, fwork: cfun(char, void)): void
Description
This function traverses its first argument (a string) from the start to the
end and applies to each encountered character its second argument (a
closure-function).
Example
The following code prints a given string onto the standard output channel:
staload "libats/ML/SATS/strarr.sats"
implement
main0 () =
{
val out = stdout_ref
val cs = (strarr)"abcdefg"
val () = strarr_foreach (cs, lam (c) => fprint_char (out, c))
val () = fprint_newline (out)
}
Synopsis
fun
strarr_iforeach
(str: strarr, fwork: cfun2(size_t, char, void)): void
Synopsis
fun
strarr_rforeach
(str: strarr, fwork: cfun(char, void)): void
Description
This function traverses its first argument (a string) from the end to the
start and applies to each encountered character its second argument (a
closure-function).
Example
The following code prints the reverse of a given string onto the standard
output channel:
staload "libats/ML/SATS/strarr.sats"
implement
main0 () =
{
val out = stdout_ref
val cs = (strarr)"abcdefg"
val () = strarr_rforeach (cs, lam (c) => fprint_char (out, c))
val () = fprint_newline (out)
}
Synopsis
overload + with strarr_append
Synopsis
overload [] with strarr_get_at_gint of 0
overload [] with strarr_get_at_guint of 0
Synopsis
overload iseqz with strarr_is_empty
Synopsis
overload isneqz with strarr_isnot_empty
Synopsis
overload < with lt_strarr_strarr
Synopsis
overload <= with lte_strarr_strarr
Synopsis
overload > with gt_strarr_strarr
Synopsis
overload >= with gte_strarr_strarr
Synopsis
overload = with eq_strarr_strarr
Synopsis
overload != with neq_strarr_strarr
Synopsis
overload compare with strarr_compare
Synopsis
overload length with strarr_length
Synopsis
overload print with print_strarr
Synopsis
overload prerr with prerr_strarr
Synopsis
overload fprint with fprint_strarr