| 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 2 | % |
|---|
| 3 | % Logtalk - Object oriented extension to Prolog |
|---|
| 4 | % Release 2.9.0 |
|---|
| 5 | % |
|---|
| 6 | % initialization file for LPA MacProlog32 1.25 |
|---|
| 7 | % |
|---|
| 8 | % last updated: August 24, 2000 |
|---|
| 9 | % |
|---|
| 10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | :- prolog_flag(syntax_errors, _, error). |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 18 | % |
|---|
| 19 | % ISO Prolog Standard predicates that we must define because they are |
|---|
| 20 | % not built-in |
|---|
| 21 | % |
|---|
| 22 | % add a clause for lgt_iso_predicate/1 declaring each ISO predicate that |
|---|
| 23 | % we must define; there must be at least one clause for this predicate |
|---|
| 24 | % whose call should fail if we don't define any ISO predicates |
|---|
| 25 | % |
|---|
| 26 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | :- dynamic(lgt_exception_/1). |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | % lgt_iso_predicate(?callable). |
|---|
| 33 | |
|---|
| 34 | lgt_iso_predicate(atom_codes(_, _)). |
|---|
| 35 | lgt_iso_predicate(atom_concat(_, _, _)). |
|---|
| 36 | lgt_iso_predicate(catch(_, _, _)). |
|---|
| 37 | lgt_iso_predicate(nl(_)). |
|---|
| 38 | lgt_iso_predicate(number_codes(_, _)). |
|---|
| 39 | lgt_iso_predicate(once(_)). |
|---|
| 40 | lgt_iso_predicate(open(_, _, _)). |
|---|
| 41 | lgt_iso_predicate(read_term(_, _, _)). |
|---|
| 42 | lgt_iso_predicate(throw(_)). |
|---|
| 43 | lgt_iso_predicate(write_term(_, _, _)). |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | atom_codes(Atom, Codes) :- |
|---|
| 47 | name(Atom, Codes). |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | atom_concat(Atom1, Atom2, Atom3) :- |
|---|
| 51 | nonvar(Atom1), nonvar(Atom2), |
|---|
| 52 | !, |
|---|
| 53 | name(Atom1, Codes1), |
|---|
| 54 | name(Atom2, Codes2), |
|---|
| 55 | lgt_append(Codes1, Codes2, Codes3), |
|---|
| 56 | name(Atom3, Codes3). |
|---|
| 57 | |
|---|
| 58 | atom_concat(Atom1, Atom2, Atom3) :- |
|---|
| 59 | nonvar(Atom3), |
|---|
| 60 | !, |
|---|
| 61 | name(Atom3, Codes3), |
|---|
| 62 | lgt_append(Codes1, Codes2, Codes3), |
|---|
| 63 | name(Atom1, Codes1), |
|---|
| 64 | name(Atom2, Codes2). |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | lpa_catch(Error, Goal) :- |
|---|
| 68 | catch(Error, Goal). |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | :- hide(catch). |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | catch(Error, Goal) :- |
|---|
| 75 | lpa_catch(Error, Goal). |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | catch(Goal, Catcher, Recovery) :- |
|---|
| 79 | lpa_catch(Error, Goal), |
|---|
| 80 | (Error = 0 -> |
|---|
| 81 | true |
|---|
| 82 | ; |
|---|
| 83 | (Error = -1 -> |
|---|
| 84 | fail |
|---|
| 85 | ; |
|---|
| 86 | (Error = 999 -> |
|---|
| 87 | retract(lgt_exception_(Ball)), |
|---|
| 88 | !, |
|---|
| 89 | (Catcher = Ball -> |
|---|
| 90 | call(Recovery) |
|---|
| 91 | ; |
|---|
| 92 | throw(Ball)) |
|---|
| 93 | ; |
|---|
| 94 | error_message(Error, Message), |
|---|
| 95 | (Catcher = Message -> |
|---|
| 96 | call(Recovery) |
|---|
| 97 | ; |
|---|
| 98 | write(Message), nl, abort)))). |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | nl(Stream) :- |
|---|
| 102 | nl ~> Stream. |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | number_codes(Number, Codes) :- |
|---|
| 106 | name(Number, Codes). |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | once(Goal) :- |
|---|
| 110 | one(Goal). |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | open(File, Mode, File) :- |
|---|
| 114 | open(File, Mode). |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | read_term(Stream, Term, [singletons([])]) :- |
|---|
| 118 | !, |
|---|
| 119 | read(Term) <~ Stream. |
|---|
| 120 | |
|---|
| 121 | read_term(Stream, Term, _) :- |
|---|
| 122 | read(Term) <~ Stream. |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | throw(Error) :- |
|---|
| 126 | asserta(lgt_exception_(Error)), |
|---|
| 127 | throw(999, Error). |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | write_term(Stream, Term, [quoted(true)]) :- |
|---|
| 131 | !, |
|---|
| 132 | writeq(Term) ~> Stream. |
|---|
| 133 | |
|---|
| 134 | write_term(Stream, Term, _) :- |
|---|
| 135 | write(Term) ~> Stream. |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 140 | % |
|---|
| 141 | % predicate properties |
|---|
| 142 | % |
|---|
| 143 | % this predicate must return at least static, dynamic and built_in |
|---|
| 144 | % properties for an existing predicate |
|---|
| 145 | % |
|---|
| 146 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | % lgt_predicate_property(+callable, ?predicate_property) |
|---|
| 150 | |
|---|
| 151 | lgt_predicate_property(Pred, Prop) :- |
|---|
| 152 | predicate_property(Pred, Prop). |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 157 | % |
|---|
| 158 | % metapredicates |
|---|
| 159 | % |
|---|
| 160 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | % lgt_call/2-8 |
|---|
| 164 | % |
|---|
| 165 | % use these definitions only if your compiler does |
|---|
| 166 | % not provide call/1-8 as built-in predicates |
|---|
| 167 | |
|---|
| 168 | lgt_call(F, A) :- |
|---|
| 169 | F(A). |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | lgt_call(F, A1, A2) :- |
|---|
| 173 | F(A1, A2). |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | lgt_call(F, A1, A2, A3) :- |
|---|
| 177 | F(A1, A2, A3). |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | lgt_call(F, A1, A2, A3, A4) :- |
|---|
| 181 | F(A1, A2, A3, A4). |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | lgt_call(F, A1, A2, A3, A4, A5) :- |
|---|
| 185 | F(A1, A2, A3, A4, A5). |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | lgt_call(F, A1, A2, A3, A4, A5, A6) :- |
|---|
| 189 | F(A1, A2, A3, A4, A5, A6). |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | lgt_call(F, A1, A2, A3, A4, A5, A6, A7) :- |
|---|
| 193 | F(A1, A2, A3, A4, A5, A6, A7). |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | % lgt_once/2-8 |
|---|
| 197 | % |
|---|
| 198 | % if your compiler provides call/1-8 as built-in |
|---|
| 199 | % predicates rewrite these definitions using call(...), !. |
|---|
| 200 | |
|---|
| 201 | lgt_once(F, A) :- |
|---|
| 202 | one(F(A)). |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | lgt_once(F, A1, A2) :- |
|---|
| 206 | one(F(A1, A2)). |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | lgt_once(F, A1, A2, A3) :- |
|---|
| 210 | one(F(A1, A2, A3)). |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | lgt_once(F, A1, A2, A3, A4) :- |
|---|
| 214 | one(F(A1, A2, A3, A4)). |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | lgt_once(F, A1, A2, A3, A4, A5) :- |
|---|
| 218 | one(F(A1, A2, A3, A4, A5)). |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | lgt_once(F, A1, A2, A3, A4, A5, A6) :- |
|---|
| 222 | one(F(A1, A2, A3, A4, A5, A6)). |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | lgt_once(F, A1, A2, A3, A4, A5, A6, A7) :- |
|---|
| 226 | one(F(A1, A2, A3, A4, A5, A6, A7)). |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 231 | % |
|---|
| 232 | % file extension predicates |
|---|
| 233 | % |
|---|
| 234 | % these extensions are used by Logtalk load/compile predicates |
|---|
| 235 | % |
|---|
| 236 | % you may want to change the extension for Prolog files to match |
|---|
| 237 | % the one expected by your Prolog compiler |
|---|
| 238 | % |
|---|
| 239 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | % lgt_file_extension(?atom, ?atom) |
|---|
| 243 | |
|---|
| 244 | lgt_file_extension(logtalk, '.lgt'). |
|---|
| 245 | lgt_file_extension(prolog, '.pl'). |
|---|
| 246 | lgt_file_extension(xml, '.xml'). |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 251 | % |
|---|
| 252 | % default compiler options |
|---|
| 253 | % |
|---|
| 254 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | % lgt_default_compiler_option(?atom, ?atom) |
|---|
| 258 | % |
|---|
| 259 | % default values for all compiler options |
|---|
| 260 | |
|---|
| 261 | lgt_default_compiler_option(iso_initialization_dir, true). |
|---|
| 262 | |
|---|
| 263 | lgt_default_compiler_option(xml, on). |
|---|
| 264 | lgt_default_compiler_option(xsl, 'lgtxml.xsl'). |
|---|
| 265 | |
|---|
| 266 | lgt_default_compiler_option(unknown, warning). |
|---|
| 267 | lgt_default_compiler_option(misspelt, warning). |
|---|
| 268 | lgt_default_compiler_option(singletons, warning). |
|---|
| 269 | lgt_default_compiler_option(lgtredef, warning). |
|---|
| 270 | lgt_default_compiler_option(plredef, silent). |
|---|
| 271 | |
|---|
| 272 | lgt_default_compiler_option(report, on). |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 277 | % |
|---|
| 278 | % list predicates |
|---|
| 279 | % |
|---|
| 280 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | lgt_append([], List, List). |
|---|
| 284 | lgt_append([Head| Tail], List, [Head| Tail2]) :- |
|---|
| 285 | lgt_append(Tail, List, Tail2). |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | lgt_member(Head, [Head| _]). |
|---|
| 289 | lgt_member(Head, [_| Tail]) :- |
|---|
| 290 | lgt_member(Head, Tail). |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | lgt_member_var(V, [H| _]) :- |
|---|
| 294 | V == H. |
|---|
| 295 | lgt_member_var(V, [_| T]) :- |
|---|
| 296 | lgt_member_var(V, T). |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | lgt_proper_list([]). |
|---|
| 300 | lgt_proper_list([_| List]) :- |
|---|
| 301 | lgt_proper_list(List). |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 306 | % |
|---|
| 307 | % file predicates |
|---|
| 308 | % |
|---|
| 309 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | % lgt_file_exists(+atom) |
|---|
| 313 | % |
|---|
| 314 | % see if a file exist in the current directory |
|---|
| 315 | |
|---|
| 316 | lgt_file_exists(File) :- |
|---|
| 317 | catch(absolute_file_name(File, [access(exist)], _), _, fail). |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | % lgt_load_prolog_code(+atom) |
|---|
| 321 | % |
|---|
| 322 | % compile and load a Prolog file |
|---|
| 323 | |
|---|
| 324 | lgt_load_prolog_code(File) :- |
|---|
| 325 | reconsult(File). |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 330 | % |
|---|
| 331 | % sorting predicates |
|---|
| 332 | % |
|---|
| 333 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | % lgt_keysort(+list, -list) |
|---|
| 337 | |
|---|
| 338 | lgt_keysort(List, Sorted) :- |
|---|
| 339 | keysort(List, Sorted). |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | % lgt_sort(+list, -list) |
|---|
| 343 | |
|---|
| 344 | lgt_sort(List, Sorted) :- |
|---|
| 345 | sort(List, Sorted). |
|---|
| 346 | |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 350 | % |
|---|
| 351 | % time and date predicates |
|---|
| 352 | % |
|---|
| 353 | % if your Prolog compiler does not provide access to the operating system |
|---|
| 354 | % time and date just write dummy definitions |
|---|
| 355 | % |
|---|
| 356 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 357 | |
|---|
| 358 | |
|---|
| 359 | % lgt_current_date(?Year, ?Month, ?Day) |
|---|
| 360 | |
|---|
| 361 | lgt_current_date(Year, Month, Day) :- |
|---|
| 362 | date(Day, Month, Year). |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | % lgt_current_time(?Hours, ?Mins, ?Secs) |
|---|
| 366 | |
|---|
| 367 | lgt_current_time(Hours, Mins, Secs) :- |
|---|
| 368 | time(Hours, Mins, Secs, _). |
|---|
| 369 | |
|---|
| 370 | |
|---|
| 371 | |
|---|
| 372 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 373 | % |
|---|
| 374 | % timing predicate |
|---|
| 375 | % |
|---|
| 376 | % if your Prolog compiler does not provide access to a timing predicate |
|---|
| 377 | % just write dummy definition |
|---|
| 378 | % |
|---|
| 379 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | % lgt_cpu_time(-Seconds) |
|---|
| 383 | |
|---|
| 384 | lgt_cpu_time(Seconds) :- |
|---|
| 385 | ticks(Ticks), |
|---|
| 386 | Seconds is Ticks / 60. |
|---|
| 387 | |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 391 | % |
|---|
| 392 | % comparison predicate |
|---|
| 393 | % |
|---|
| 394 | % the usual compare/3 definition |
|---|
| 395 | % |
|---|
| 396 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 397 | |
|---|
| 398 | |
|---|
| 399 | % compare(?atom, @term, @term) -- built-in |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | |
|---|
| 403 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 404 | % |
|---|
| 405 | % end! |
|---|
| 406 | % |
|---|
| 407 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|