ATSLIB/prelude/checkast

This package contains functions that rely on dynamic checks to perform casting. These functions are introduced solely for bringing some convenience into programming.


  • checkast_gintLt
  • checkast_gintLte
  • checkast_gintGt
  • checkast_gintGte
  • checkast_gintBtw
  • checkast_gintBtwe
  • ckastloc_gintLt
  • ckastloc_gintLte
  • ckastloc_gintGt
  • ckastloc_gintGte
  • ckastloc_gintBtw
  • ckastloc_gintBtwe
  • checkast_Ptr1
  • ckastloc_Ptr1
  • checkast_Strptr1
  • ckastloc_Strptr1

  • checkast_gintLt

    Synopsis

    fun{tk:tk}
    checkast_gintLt{i:int}
      (x: g0int(tk), i: int i, msg: RD(string)): g1intLt(tk, i)

    Description

    Given an integer x, another integer i and a string msg, this function returns x if x is less than i. Otherwise, it prints the string msg onto STDERR and then exits with the code 1.

    checkast_gintLte

    Synopsis

    fun{tk:tk}
    checkast_gintLte{i:int}
      (x: g0int(tk), i: int i, msg: RD(string)): g1intLte(tk, i)

    checkast_gintGt

    Synopsis

    fun{tk:tk}
    checkast_gintGt{i:int}
      (x: g0int(tk), i: int i, msg: RD(string)): g1intGt(tk, i)

    checkast_gintGte

    Synopsis

    fun{tk:tk}
    checkast_gintGte{i:int}
      (x: g0int(tk), i: int i, msg: RD(string)): g1intGte(tk, i)

    checkast_gintBtw

    Synopsis

    fun{tk:tk}
    checkast_gintBtw{i,j:int}
      (x: g0int(tk), i: int i, j: int j, msg: RD(string)): g1intBtw(tk, i, j)

    checkast_gintBtwe

    Synopsis

    fun{tk:tk}
    checkast_gintBtwe{i,j:int}
      (x: g0int(tk), i: int i, j: int j, msg: RD(string)): g1intBtwe(tk, i, j)

    ckastloc_gintLt

    Synopsis

    macdef
    ckastloc_gintLt(x, i) = checkast_gintLt(,(x), ,(i), $mylocation)

    ckastloc_gintLte

    Synopsis

    macdef
    ckastloc_gintLte(x, i) = checkast_gintLte(,(x), ,(i), $mylocation)

    ckastloc_gintGt

    Synopsis

    macdef
    ckastloc_gintGt(x, i) = checkast_gintGt(,(x), ,(i), $mylocation)

    ckastloc_gintGte

    Synopsis

    macdef
    ckastloc_gintGte(x, i) = checkast_gintGte(,(x), ,(i), $mylocation)

    Example

    The following code make a typical use of ckastloc_gintGte:
    implement
    main0 (argc, argv) =
    {
    //
    fun
    fact{n:nat}
      (n: int n): int =
      if n > 0 then n * fact(n-1) else 1
    //
    val n =
    (
      if argc >= 2 then g0string2int(argv[1]) else 10
    ) : int
    //
    val n = ckastloc_gintGte (n, 0) // assert: n >= 0
    //
    val () = println! ("fact(", n, ") = ", fact(n))
    //
    } (* end pf [main0] *)
    

    ckastloc_gintBtw

    Synopsis

    macdef
    ckastloc_gintBtw(x, i, j) = checkast_gintBtw(,(x), ,(i), ,(j), $mylocation)

    ckastloc_gintBtwe

    Synopsis

    macdef
    ckastloc_gintBtwe(x, i, j) = checkast_gintBtwe(,(x), ,(i), ,(j), $mylocation)

    checkast_Ptr1

    Synopsis

    fun{}
    checkast_Ptr1(x: ptr, msg: RD(string)): Ptr1

    Description

    Given a pointer x and a string msg, this function returns x if x is non-null. Otherwise, it prints the string msg onto STDERR and then exits with the code 1.

    ckastloc_Ptr1

    Synopsis

    macdef
    ckastloc_Ptr1(x) = checkast_Ptr1(,(x), $mylocation)

    checkast_Strptr1

    Synopsis

    fun{}
    checkast_Strptr1(x: Strptr0, msg: RD(string)): Strptr1

    Description

    Given a strptr-value x and a string msg, this function returns x if x is non-null. Otherwise, it prints the string msg onto STDERR and then exits with the code 1.

    ckastloc_Strptr1

    Synopsis

    macdef
    ckastloc_Strptr1(x) = checkast_Strptr1(,(x), $mylocation)

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