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.
  • strarr
  • strarr_type
  • strarr2array
  • array2strarr
  • strarr_make_string
  • strarr_make_substring
  • strarr_get_at
  • strarr_get_at_gint
  • strarr_get_at_guint
  • strarr_get_range
  • print_strarr
  • prerr_strarr
  • fprint_strarr
  • strarr_copy
  • strarr_append
  • strarr_tabulate
  • strarr_foreach
  • strarr_iforeach
  • strarr_rforeach
  • Overloaded Symbols
  • +
  • []
  • iseqz
  • isneqz
  • <
  • <=
  • >
  • >=
  • =
  • !=
  • compare
  • length
  • print
  • prerr
  • fprint

  • strarr

    Synopsis

    typedef strarr = strarr_type

    strarr_type

    Synopsis

    abstype strarr_type = ptr

    strarr2array

    Synopsis

    castfn
    strarr2array
      (cs: strarr):<> array0(char)

    Description

    This cast function turns a strarr-value to an array of characters.

    array2strarr

    Synopsis

    castfn
    array2strarr
      (cs: array0(char)):<> strarr

    Description

    This cast function turns an array of characters to a strarr-value.

    strarr_make_string

    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.

    strarr_make_substring

    Synopsis

    fun
    strarr_make_substring
      (str: string, st: size_t, ln: size_t):<!wrt> strarr

    strarr_get_at

    Synopsis

    overload
    strarr_get_at with strarr_get_at_gint of 0
    overload
    strarr_get_at with strarr_get_at_guint of 0

    strarr_get_at_gint

    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.

    strarr_get_at_guint

    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.

    strarr_get_range

    Synopsis

    fun
    strarr_get_range
    (
      strarr, i0: size_t, i1: size_t
    ) : string // end-of-strarr_get_range

    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.

    print_strarr

    Synopsis

    fun
    print_strarr(str: strarr): void

    Description

    This function prints a given strarr-value onto STDOUT.

    prerr_strarr

    Synopsis

    fun
    prerr_strarr(str: strarr): void

    Description

    This function prints a given strarr-value onto STDERR.

    fprint_strarr

    Synopsis

    fun
    fprint_strarr
    (
      out: FILEref, str: strarr
    ) : void // end-of-fprint_strarr

    strarr_copy

    Synopsis

    fun
    strarr_copy(str: strarr):<!wrt> strarr

    Description

    Given a strarr-value, this function returns a copy of it.

    strarr_append

    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.

    strarr_tabulate

    Synopsis

    fun
    strarr_tabulate
      {n:int}
    (
      n: size_t(n), f: cfun(sizeLt(n), char)
    ) : strarr // end of [strarr_tabulate]

    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.

    strarr_foreach

    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)
    } // end of [main0]
    

    strarr_iforeach

    Synopsis

    fun
    strarr_iforeach
      (str: strarr, fwork: cfun2(size_t, char, void)): void

    strarr_rforeach

    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)
    } // end of [main0]
    

    Overloaded Symbols


    +

    Synopsis

    overload + with strarr_append

    []

    Synopsis

    overload [] with strarr_get_at_gint of 0
    overload [] with strarr_get_at_guint of 0

    iseqz

    Synopsis

    overload iseqz with strarr_is_empty

    isneqz

    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

    compare

    Synopsis

    overload compare with strarr_compare

    length

    Synopsis

    overload length with strarr_length

    print

    Synopsis

    overload print with print_strarr

    prerr

    Synopsis

    overload prerr with prerr_strarr

    fprint

    Synopsis

    overload fprint with fprint_strarr

    This page is created with ATS by Hongwei Xi and also maintained by Hongwei Xi. SourceForge.net Logo