1 2/* is_colour_space str: is a string one of nip's colour space names 3 */ 4is_colour_space str = Image_type.colour_spaces.present 0 str; 5 6/* is_colour_type n: is a number one of VIPS's colour spaces 7 */ 8is_colour_type n = Image_type.colour_spaces.present 1 n; 9 10/* is_number: is a real or a complex number. 11 */ 12is_number a = is_real a || is_complex a; 13 14/* is_int: is an integer 15 */ 16is_int a = is_real a && a == (int) a; 17 18/* is_uint: is an unsigned integer 19 */ 20is_uint a = is_int a && a >= 0; 21 22/* is_pint: is a positive integer 23 */ 24is_pint a = is_int a && a > 0; 25 26/* is_preal: is a positive real 27 */ 28is_preal a = is_real a && a > 0; 29 30/* is_ureal: is an unsigned real 31 */ 32is_ureal a = is_real a && a >= 0; 33 34/* is_letter c: true of character c is an ASCII letter 35 * 36 * is_letter :: char -> bool 37 */ 38is_letter c = ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); 39 40/* is_digit c: true if character c is an ASCII digit 41 * 42 * is_digit :: char->bool 43 */ 44is_digit x = '0' <= x && x <= '9'; 45 46/* A whitespace character. 47 * 48 * is_space :: char->bool 49 */ 50is_space = member " \n\t"; 51 52/* is_listof p s: true if finite list with p true for every element. 53 */ 54is_listof p l = is_list l && land (map p l); 55 56/* is_string s: true if finite list of char. 57 */ 58is_string s = is_listof is_char s; 59 60/* is_real_list l: is l a list of real numbers ... test each element, 61 * so no infinite lists pls. 62 */ 63is_real_list l = is_listof is_real l; 64 65/* is_string_list l: is l a finite list of finite strings. 66 */ 67is_string_list l = is_listof is_string l; 68 69/* is_rectangular l: is l a rectangular data structure 70 */ 71is_rectangular l 72 = true, !is_list l 73 = true, land (map is_obj l) 74 = true, land (map is_list l) && 75 land (map (not @ is_obj) l) && 76 land (map is_rectangular l) && 77 len l > 0 && 78 land (map (equal (hd lengths)) (tl lengths)) 79 = false 80{ 81 // treat strings as a base type, not [char] 82 is_obj x = !is_list x || is_string x; 83 lengths = map len l; 84} 85 86/* is_matrix l: is l a list of lists of real numbers, all the same length 87 */ 88is_matrix l = is_listof is_real_list l && is_rectangular l; 89 90/* is_square_matrix l: is l a matrix with width == height 91 */ 92is_square_matrix l 93 = true, l == [] 94 = is_matrix l && len l == len (hd l); 95 96/* is_oddmatrix l: is l a matrix with odd-length sides 97 */ 98is_oddmatrix l 99 = true, l == [] 100 = is_matrix l && (len l) % 2 == 1 && (len (l?0)) % 2 == 1; 101 102/* is_odd_square_matrix l: is l a square_matrix with odd-length sides 103 */ 104is_odd_square_matrix l = is_square_matrix l && (len l) % 2 == 1; 105 106/* Is an item in a column of a table? 107 */ 108is_incolumn n table x = member (map (extract n) table) x; 109 110/* Is HGuide or VGuide. 111 */ 112is_Guide x = is_instanceof "HGuide" x || is_instanceof "VGuide" x; 113 114is_Point x = is_instanceof "Point" x; 115 116/* A list of the form [[1,2],[3,4],[5,6]...] 117 */ 118is_xy_list l 119 = is_list l && land (map xy l) 120{ 121 xy l = is_real_list l && len l == 2; 122} 123