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