| 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 2 | % |
|---|
| 3 | % Logtalk - Open source object-oriented logic programming language |
|---|
| 4 | % Release 2.33.3 |
|---|
| 5 | % |
|---|
| 6 | % Copyright (c) 1998-2008 Paulo Moura. All Rights Reserved. |
|---|
| 7 | % Logtalk is free software. You can redistribute it and/or modify |
|---|
| 8 | % it under the terms of the "Artistic License 2.0" as published by |
|---|
| 9 | % The Perl Foundation. Consult the "LICENSE.txt" file for details. |
|---|
| 10 | % |
|---|
| 11 | % |
|---|
| 12 | % configuration file for ECLiPSe 5.10#26 and later versions |
|---|
| 13 | % |
|---|
| 14 | % last updated: November 7, 2008 |
|---|
| 15 | % |
|---|
| 16 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | :- pragma(system). |
|---|
| 20 | :- pragma(nodebug). |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 25 | % |
|---|
| 26 | % ISO Prolog Standard predicates that we must define because they are |
|---|
| 27 | % not built-in |
|---|
| 28 | % |
|---|
| 29 | % add a clause for lgt_iso_predicate/1 declaring each ISO predicate that |
|---|
| 30 | % we must define; there must be at least one clause for this predicate |
|---|
| 31 | % whose call should fail if we don't define any ISO predicates |
|---|
| 32 | % |
|---|
| 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | :- dynamic(lgt_exception_/1). |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | initialization(Goal) :- |
|---|
| 40 | call(Goal). |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | % '$lgt_iso_predicate'(?callable). |
|---|
| 44 | |
|---|
| 45 | '$lgt_iso_predicate'(assertz(_)). |
|---|
| 46 | '$lgt_iso_predicate'(atom_codes(_, _)). |
|---|
| 47 | '$lgt_iso_predicate'(atom_concat(_, _, _)). |
|---|
| 48 | '$lgt_iso_predicate'(catch(_, _, _)). |
|---|
| 49 | '$lgt_iso_predicate'(current_input(_)). |
|---|
| 50 | '$lgt_iso_predicate'(current_output(_)). |
|---|
| 51 | '$lgt_iso_predicate'(number_codes(_, _)). |
|---|
| 52 | '$lgt_iso_predicate'(throw(_)). |
|---|
| 53 | '$lgt_iso_predicate'(unify_with_occurs_check(_, _)). |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | assertz(Clause) :- |
|---|
| 57 | assert(Clause). |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | atom_codes(Atom, List) :- |
|---|
| 61 | var(Atom), |
|---|
| 62 | string_list(String, List), |
|---|
| 63 | atom_string(Atom, String). |
|---|
| 64 | |
|---|
| 65 | atom_codes(Atom, List) :- |
|---|
| 66 | nonvar(Atom), |
|---|
| 67 | atom_string(Atom, String), |
|---|
| 68 | string_list(String, List). |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | atom_concat(Atom1, Atom2, Atom3) :- |
|---|
| 72 | nonvar(Atom1), nonvar(Atom2), |
|---|
| 73 | !, |
|---|
| 74 | concat_atoms(Atom1, Atom2, Atom3). |
|---|
| 75 | |
|---|
| 76 | atom_concat(Atom1, Atom2, Atom3) :- |
|---|
| 77 | nonvar(Atom3), |
|---|
| 78 | name(Atom3, Codes3), |
|---|
| 79 | '$lgt_append'(Codes1, Codes2, Codes3), |
|---|
| 80 | name(Atom1, Codes1), |
|---|
| 81 | name(Atom2, Codes2). |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | catch(Goal, Catcher, Recovery) :- |
|---|
| 85 | block(Goal, Tag, lgt_catch_recovery(Tag, Catcher, Recovery)). |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | lgt_catch_recovery(Tag, Catcher, Recovery) :- |
|---|
| 89 | ( Tag = lgt_error -> |
|---|
| 90 | retract(lgt_exception_(Ball)), |
|---|
| 91 | !, |
|---|
| 92 | ( Catcher = Ball -> |
|---|
| 93 | call(Recovery) |
|---|
| 94 | ; exit_block(Tag) |
|---|
| 95 | ) |
|---|
| 96 | ; exit_block(Tag) |
|---|
| 97 | ). |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | lgt_uncatched_exception :- |
|---|
| 101 | ( retract(lgt_exception_(Ball)) -> |
|---|
| 102 | writeq(Ball), nl |
|---|
| 103 | ; write('uncatched exception'), nl |
|---|
| 104 | ), |
|---|
| 105 | abort. |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | :- set_error_handler(230, lgt_uncatched_exception/0). |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | current_input(Stream) :- |
|---|
| 112 | get_stream(input, Stream). |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | current_output(Stream) :- |
|---|
| 116 | get_stream(output, Stream). |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | number_codes(Number, Codes) :- |
|---|
| 120 | var(Number), |
|---|
| 121 | string_list(String, Codes), |
|---|
| 122 | number_string(Number, String). |
|---|
| 123 | |
|---|
| 124 | number_codes(Number, Codes) :- |
|---|
| 125 | nonvar(Number), |
|---|
| 126 | number_string(Number, String), |
|---|
| 127 | string_list(String, Codes). |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | throw(Ball) :- |
|---|
| 131 | asserta(lgt_exception_(Ball)), |
|---|
| 132 | exit_block(lgt_error). |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | :- set_flag(occur_check, on). |
|---|
| 136 | unify_with_occurs_check(X, X). |
|---|
| 137 | :- set_flag(occur_check, off). |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 142 | % |
|---|
| 143 | % predicate properties |
|---|
| 144 | % |
|---|
| 145 | % this predicate must return at least static, dynamic, and built_in |
|---|
| 146 | % properties for an existing predicate |
|---|
| 147 | % |
|---|
| 148 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | % '$lgt_predicate_property'(+callable, ?predicate_property) |
|---|
| 152 | |
|---|
| 153 | '$lgt_predicate_property'(Predicate, built_in) :- |
|---|
| 154 | functor(Predicate, Functor, Arity), |
|---|
| 155 | current_built_in(Functor/Arity). |
|---|
| 156 | |
|---|
| 157 | '$lgt_predicate_property'(Predicate, dynamic) :- |
|---|
| 158 | functor(Predicate, Functor, Arity), |
|---|
| 159 | current_predicate(Functor/Arity), |
|---|
| 160 | is_dynamic(Functor/Arity). |
|---|
| 161 | |
|---|
| 162 | '$lgt_predicate_property'(Predicate, static) :- |
|---|
| 163 | functor(Predicate, Functor, Arity), |
|---|
| 164 | current_built_in(Functor/Arity). |
|---|
| 165 | |
|---|
| 166 | '$lgt_predicate_property'(Predicate, static) :- |
|---|
| 167 | functor(Predicate, Functor, Arity), |
|---|
| 168 | current_predicate(Functor/Arity), |
|---|
| 169 | \+ is_dynamic(Functor/Arity). |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 174 | % |
|---|
| 175 | % meta-predicates |
|---|
| 176 | % |
|---|
| 177 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | % call_cleanup(+callable, +callble) |
|---|
| 181 | |
|---|
| 182 | call_cleanup(_, _) :- |
|---|
| 183 | throw(not_supported(call_cleanup/2)). |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | % forall(+callable, +callble) -- built-in |
|---|
| 187 | |
|---|
| 188 | forall(Generate, Test) :- |
|---|
| 189 | \+ (Generate, \+ Test). |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | % retractall(+callable) |
|---|
| 193 | |
|---|
| 194 | retractall(Head) :- |
|---|
| 195 | retract_all(Head). |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | % call_with_args/2-9 |
|---|
| 199 | % |
|---|
| 200 | % use these definitions only if your compiler does |
|---|
| 201 | % not provide call_with_args/2-9 as built-in predicates |
|---|
| 202 | |
|---|
| 203 | call_with_args(F, A) :- |
|---|
| 204 | Call =.. [F, A], |
|---|
| 205 | call(Call). |
|---|
| 206 | |
|---|
| 207 | call_with_args(F, A1, A2) :- |
|---|
| 208 | Call =.. [F, A1, A2], |
|---|
| 209 | call(Call). |
|---|
| 210 | |
|---|
| 211 | call_with_args(F, A1, A2, A3) :- |
|---|
| 212 | Call =.. [F, A1, A2, A3], |
|---|
| 213 | call(Call). |
|---|
| 214 | |
|---|
| 215 | call_with_args(F, A1, A2, A3, A4) :- |
|---|
| 216 | Call =.. [F, A1, A2, A3, A4], |
|---|
| 217 | call(Call). |
|---|
| 218 | |
|---|
| 219 | call_with_args(F, A1, A2, A3, A4, A5) :- |
|---|
| 220 | Call =.. [F, A1, A2, A3, A4, A5], |
|---|
| 221 | call(Call). |
|---|
| 222 | |
|---|
| 223 | call_with_args(F, A1, A2, A3, A4, A5, A6) :- |
|---|
| 224 | Call =.. [F, A1, A2, A3, A4, A5, A6], |
|---|
| 225 | call(Call). |
|---|
| 226 | |
|---|
| 227 | call_with_args(F, A1, A2, A3, A4, A5, A6, A7) :- |
|---|
| 228 | Call =.. [F, A1, A2, A3, A4, A5, A6, A7], |
|---|
| 229 | call(Call). |
|---|
| 230 | |
|---|
| 231 | call_with_args(F, A1, A2, A3, A4, A5, A6, A7, A8) :- |
|---|
| 232 | Call =.. [F, A1, A2, A3, A4, A5, A6, A7, A8], |
|---|
| 233 | call(Call). |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 238 | % |
|---|
| 239 | % Prolog built-in meta-predicates |
|---|
| 240 | % |
|---|
| 241 | % (excluding ISO Prolog Standard meta-predicates) |
|---|
| 242 | % |
|---|
| 243 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | % '$lgt_pl_meta_predicate'(?callable, ?atom). |
|---|
| 247 | |
|---|
| 248 | '$lgt_pl_meta_predicate'(block(::, *, ::), predicate). |
|---|
| 249 | '$lgt_pl_meta_predicate'(call_priority(::, *), predicate). |
|---|
| 250 | '$lgt_pl_meta_predicate'(coverof(*, ::, *), predicate). |
|---|
| 251 | '$lgt_pl_meta_predicate'(do(*, ::), predicate). |
|---|
| 252 | '$lgt_pl_meta_predicate'(event_create(::, *, *), predicate). |
|---|
| 253 | '$lgt_pl_meta_predicate'(make_suspension(::, *, *), predicate). |
|---|
| 254 | '$lgt_pl_meta_predicate'(mutex(*, ::), predicate). |
|---|
| 255 | '$lgt_pl_meta_predicate'(suspend(::, *, *), predicate). |
|---|
| 256 | '$lgt_pl_meta_predicate'(suspend(::, *, *, *), predicate). |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 261 | % |
|---|
| 262 | % file extension predicates |
|---|
| 263 | % |
|---|
| 264 | % these extensions are used by Logtalk load/compile predicates |
|---|
| 265 | % |
|---|
| 266 | % you may want to change the extension for Prolog files to match |
|---|
| 267 | % the one expected by your Prolog compiler |
|---|
| 268 | % |
|---|
| 269 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | % '$lgt_file_extension'(?atom, ?atom) |
|---|
| 273 | |
|---|
| 274 | '$lgt_file_extension'(logtalk, '.lgt'). |
|---|
| 275 | '$lgt_file_extension'(prolog, '.pl'). |
|---|
| 276 | '$lgt_file_extension'(xml, '.xml'). |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 281 | % |
|---|
| 282 | % default flag values |
|---|
| 283 | % |
|---|
| 284 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | % '$lgt_default_flag'(?atom, ?atom) |
|---|
| 288 | % |
|---|
| 289 | % default values for all flags |
|---|
| 290 | |
|---|
| 291 | '$lgt_default_flag'(prolog, eclipse). |
|---|
| 292 | |
|---|
| 293 | '$lgt_default_flag'(xmldocs, on). |
|---|
| 294 | '$lgt_default_flag'(xslfile, 'lgtxml.xsl'). |
|---|
| 295 | '$lgt_default_flag'(xmlspec, dtd). |
|---|
| 296 | '$lgt_default_flag'(xmlsref, local). |
|---|
| 297 | |
|---|
| 298 | '$lgt_default_flag'(unknown, warning). |
|---|
| 299 | '$lgt_default_flag'(misspelt, warning). |
|---|
| 300 | '$lgt_default_flag'(singletons, warning). |
|---|
| 301 | '$lgt_default_flag'(lgtredef, warning). |
|---|
| 302 | '$lgt_default_flag'(plredef, silent). |
|---|
| 303 | '$lgt_default_flag'(portability, silent). |
|---|
| 304 | |
|---|
| 305 | '$lgt_default_flag'(report, on). |
|---|
| 306 | |
|---|
| 307 | '$lgt_default_flag'(smart_compilation, off). |
|---|
| 308 | '$lgt_default_flag'(reload, always). |
|---|
| 309 | |
|---|
| 310 | '$lgt_default_flag'(startup_message, flags(verbose)). |
|---|
| 311 | |
|---|
| 312 | '$lgt_default_flag'(underscore_variables, dont_care). |
|---|
| 313 | |
|---|
| 314 | '$lgt_default_flag'(code_prefix, ''). |
|---|
| 315 | |
|---|
| 316 | '$lgt_default_flag'(debug, off). |
|---|
| 317 | '$lgt_default_flag'(break_predicate, supported). |
|---|
| 318 | |
|---|
| 319 | '$lgt_default_flag'(complements, off). |
|---|
| 320 | '$lgt_default_flag'(dynamic_declarations, off). |
|---|
| 321 | '$lgt_default_flag'(events, off). |
|---|
| 322 | |
|---|
| 323 | '$lgt_default_flag'(altdirs, off). |
|---|
| 324 | '$lgt_default_flag'(tmpdir, 'lgt_tmp/'). |
|---|
| 325 | '$lgt_default_flag'(xmldir, 'xml_docs/'). |
|---|
| 326 | |
|---|
| 327 | '$lgt_default_flag'(encoding_directive, unsupported). |
|---|
| 328 | '$lgt_default_flag'(multifile_directive, unsupported). |
|---|
| 329 | '$lgt_default_flag'(threads, unsupported). |
|---|
| 330 | |
|---|
| 331 | '$lgt_default_flag'(context_switching_calls, allow). |
|---|
| 332 | |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 336 | % |
|---|
| 337 | % list predicates |
|---|
| 338 | % |
|---|
| 339 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | '$lgt_append'([], List, List). |
|---|
| 343 | '$lgt_append'([Head| Tail], List, [Head| Tail2]) :- |
|---|
| 344 | '$lgt_append'(Tail, List, Tail2). |
|---|
| 345 | |
|---|
| 346 | |
|---|
| 347 | '$lgt_member'(Head, [Head| _]). |
|---|
| 348 | '$lgt_member'(Head, [_| Tail]) :- |
|---|
| 349 | '$lgt_member'(Head, Tail). |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | '$lgt_member_var'(V, [H| _]) :- |
|---|
| 353 | V == H. |
|---|
| 354 | '$lgt_member_var'(V, [_| T]) :- |
|---|
| 355 | '$lgt_member_var'(V, T). |
|---|
| 356 | |
|---|
| 357 | |
|---|
| 358 | '$lgt_is_list'([]) :- |
|---|
| 359 | !. |
|---|
| 360 | '$lgt_is_list'([_| Tail]) :- |
|---|
| 361 | '$lgt_is_list'(Tail). |
|---|
| 362 | |
|---|
| 363 | |
|---|
| 364 | '$lgt_is_proper_list'(List) :- |
|---|
| 365 | List == [], !. |
|---|
| 366 | '$lgt_is_proper_list'([_| Tail]) :- |
|---|
| 367 | nonvar(Tail), |
|---|
| 368 | '$lgt_is_proper_list'(Tail). |
|---|
| 369 | |
|---|
| 370 | |
|---|
| 371 | |
|---|
| 372 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 373 | % |
|---|
| 374 | % file predicates |
|---|
| 375 | % |
|---|
| 376 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 377 | |
|---|
| 378 | |
|---|
| 379 | % '$lgt_file_exists'(+atom) |
|---|
| 380 | % |
|---|
| 381 | % see if a file exist in the current directory |
|---|
| 382 | |
|---|
| 383 | '$lgt_file_exists'(File) :- |
|---|
| 384 | exists(File). |
|---|
| 385 | |
|---|
| 386 | |
|---|
| 387 | % '$lgt_directory_exists'(+atom) |
|---|
| 388 | % |
|---|
| 389 | % checks if a directory exists |
|---|
| 390 | |
|---|
| 391 | '$lgt_directory_exists'(Directory) :- |
|---|
| 392 | atom_string(Directory, DirectoryString), |
|---|
| 393 | canonical_path_name(DirectoryString, Path), |
|---|
| 394 | exists(Path). |
|---|
| 395 | |
|---|
| 396 | |
|---|
| 397 | % '$lgt_current_directory'(-atom) |
|---|
| 398 | % |
|---|
| 399 | % gets current working directory |
|---|
| 400 | |
|---|
| 401 | '$lgt_current_directory'(Directory) :- |
|---|
| 402 | getcwd(Directory). |
|---|
| 403 | |
|---|
| 404 | |
|---|
| 405 | % '$lgt_change_directory'(+atom) |
|---|
| 406 | % |
|---|
| 407 | % changes current working directory |
|---|
| 408 | |
|---|
| 409 | '$lgt_change_directory'(Directory) :- |
|---|
| 410 | cd(Directory). |
|---|
| 411 | |
|---|
| 412 | |
|---|
| 413 | % '$lgt_make_directory'(+atom) |
|---|
| 414 | % |
|---|
| 415 | % makes a new directory; succeeds if the directory already exists |
|---|
| 416 | |
|---|
| 417 | '$lgt_make_directory'(Directory) :- |
|---|
| 418 | ( exists(Directory) -> |
|---|
| 419 | true |
|---|
| 420 | ; mkdir(Directory) |
|---|
| 421 | ). |
|---|
| 422 | |
|---|
| 423 | |
|---|
| 424 | % '$lgt_load_prolog_code'(+atom, +atom, +list) |
|---|
| 425 | % |
|---|
| 426 | % compile and load a Prolog file, resulting from a |
|---|
| 427 | % Logtalk source file, given a list of options |
|---|
| 428 | |
|---|
| 429 | '$lgt_load_prolog_code'(File, _, _) :- |
|---|
| 430 | get_flag(debug_compile, Current), |
|---|
| 431 | set_flag(debug_compile, off), |
|---|
| 432 | compile(File), |
|---|
| 433 | set_flag(debug_compile, Current). |
|---|
| 434 | |
|---|
| 435 | |
|---|
| 436 | % '$lgt_compare_file_mtimes'(?atom, +atom, +atom) |
|---|
| 437 | % |
|---|
| 438 | % compare file modification times |
|---|
| 439 | |
|---|
| 440 | '$lgt_compare_file_mtimes'(Result, File1, File2) :- |
|---|
| 441 | get_file_info(File1, mtime, Time1), |
|---|
| 442 | get_file_info(File2, mtime, Time2), |
|---|
| 443 | compare(Result, Time1, Time2). |
|---|
| 444 | |
|---|
| 445 | |
|---|
| 446 | |
|---|
| 447 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 448 | % |
|---|
| 449 | % sorting predicates |
|---|
| 450 | % |
|---|
| 451 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | % '$lgt_keysort'(+list, -list) |
|---|
| 455 | |
|---|
| 456 | '$lgt_keysort'(List, Sorted) :- |
|---|
| 457 | keysort(List, Sorted). |
|---|
| 458 | |
|---|
| 459 | |
|---|
| 460 | % '$lgt_sort'(+list, -list) |
|---|
| 461 | |
|---|
| 462 | '$lgt_sort'(List, Sorted) :- |
|---|
| 463 | sort(List, Sorted). |
|---|
| 464 | |
|---|
| 465 | |
|---|
| 466 | |
|---|
| 467 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 468 | % |
|---|
| 469 | % time and date predicates |
|---|
| 470 | % |
|---|
| 471 | % if your Prolog compiler does not provide access to the operating system |
|---|
| 472 | % time and date just write dummy definitions |
|---|
| 473 | % |
|---|
| 474 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 475 | |
|---|
| 476 | |
|---|
| 477 | :- use_module(library(calendar)). |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | % '$lgt_current_date'(?Year, ?Month, ?Day) |
|---|
| 481 | |
|---|
| 482 | '$lgt_current_date'(Year, Month, Day) :- |
|---|
| 483 | mjd_now(MJD), |
|---|
| 484 | mjd_to_date(MJD, Day/Month/Year). |
|---|
| 485 | |
|---|
| 486 | |
|---|
| 487 | % '$lgt_current_time'(?Hours, ?Mins, ?Secs) |
|---|
| 488 | |
|---|
| 489 | '$lgt_current_time'(Hours, Mins, Secs) :- |
|---|
| 490 | mjd_now(MJD), |
|---|
| 491 | mjd_to_time(MJD, Hours:Mins:Secs). |
|---|
| 492 | |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 496 | % |
|---|
| 497 | % timing predicate |
|---|
| 498 | % |
|---|
| 499 | % if your Prolog compiler does not provide access to a timing predicate |
|---|
| 500 | % just write dummy definition |
|---|
| 501 | % |
|---|
| 502 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | % '$lgt_cpu_time'(-Seconds) |
|---|
| 506 | |
|---|
| 507 | '$lgt_cpu_time'(Seconds) :- |
|---|
| 508 | cputime(Seconds). |
|---|
| 509 | |
|---|
| 510 | |
|---|
| 511 | |
|---|
| 512 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 513 | % |
|---|
| 514 | % comparison predicate |
|---|
| 515 | % |
|---|
| 516 | % the usual compare/3 definition |
|---|
| 517 | % |
|---|
| 518 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 519 | |
|---|
| 520 | |
|---|
| 521 | % compare(?atom, @term, @term) -- built-in |
|---|
| 522 | |
|---|
| 523 | |
|---|
| 524 | |
|---|
| 525 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 526 | % |
|---|
| 527 | % callable predicate |
|---|
| 528 | % |
|---|
| 529 | % the usual callable/1 definition |
|---|
| 530 | % |
|---|
| 531 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 532 | |
|---|
| 533 | |
|---|
| 534 | % callable(@term) |
|---|
| 535 | |
|---|
| 536 | callable(Term) :- |
|---|
| 537 | nonvar(Term), |
|---|
| 538 | functor(Term, Functor, _), |
|---|
| 539 | atom(Functor). |
|---|
| 540 | |
|---|
| 541 | |
|---|
| 542 | |
|---|
| 543 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 544 | % |
|---|
| 545 | % read character predicate |
|---|
| 546 | % |
|---|
| 547 | % read a single character echoing it and writing a newline after |
|---|
| 548 | % |
|---|
| 549 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 550 | |
|---|
| 551 | |
|---|
| 552 | '$lgt_read_single_char'(Char) :- |
|---|
| 553 | flush(user), tyi(Code), put(Code), nl, char_code(Char, Code). |
|---|
| 554 | |
|---|
| 555 | |
|---|
| 556 | |
|---|
| 557 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 558 | % |
|---|
| 559 | % pretty print a term by naming its free variables |
|---|
| 560 | % (avoid instantiating variables in term by using double negation if necessary) |
|---|
| 561 | % |
|---|
| 562 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 563 | |
|---|
| 564 | |
|---|
| 565 | '$lgt_pretty_print_vars'(Stream, Term) :- |
|---|
| 566 | write_term(Stream, Term, [numbervars(true)]). |
|---|
| 567 | |
|---|
| 568 | |
|---|
| 569 | '$lgt_pretty_print_vars_quoted'(Stream, Term) :- |
|---|
| 570 | write_term(Stream, Term, [numbervars(true), quoted(true)]). |
|---|
| 571 | |
|---|
| 572 | |
|---|
| 573 | |
|---|
| 574 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 575 | % |
|---|
| 576 | % getting stream current line number |
|---|
| 577 | % (needed for improved compiler error messages) |
|---|
| 578 | % |
|---|
| 579 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 580 | |
|---|
| 581 | |
|---|
| 582 | % '$lgt_stream_current_line_number'(@stream, -integer) |
|---|
| 583 | |
|---|
| 584 | '$lgt_stream_current_line_number'(Stream, Line) :- |
|---|
| 585 | get_stream_info(Stream, line, Last), |
|---|
| 586 | Line is Last + 1. |
|---|
| 587 | |
|---|
| 588 | |
|---|
| 589 | |
|---|
| 590 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 591 | % |
|---|
| 592 | % customized version of the read_term/3 predicate for returning the line |
|---|
| 593 | % where the term starts (needed for improved compiler error messages) |
|---|
| 594 | % |
|---|
| 595 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 596 | |
|---|
| 597 | |
|---|
| 598 | % '$lgt_read_term'(@stream, -term, +list, -integer) |
|---|
| 599 | |
|---|
| 600 | '$lgt_read_term'(Stream, Term, Options, -1) :- |
|---|
| 601 | read_term(Stream, Term, Options). |
|---|
| 602 | |
|---|
| 603 | |
|---|
| 604 | |
|---|
| 605 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 606 | % |
|---|
| 607 | % handling of Prolog-proprietary directives on Logtalk source files |
|---|
| 608 | % |
|---|
| 609 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 610 | |
|---|
| 611 | |
|---|
| 612 | % '$lgt_ignore_pl_directive'(@callable) |
|---|
| 613 | |
|---|
| 614 | '$lgt_ignore_pl_directive'(mode(_)). |
|---|
| 615 | |
|---|
| 616 | |
|---|
| 617 | % '$lgt_rewrite_and_copy_pl_directive'(@callable, -callable) |
|---|
| 618 | |
|---|
| 619 | '$lgt_rewrite_and_copy_pl_directive'(_, _) :- |
|---|
| 620 | fail. |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | % '$lgt_rewrite_and_recompile_pl_directive'(@callable, -callable) |
|---|
| 624 | |
|---|
| 625 | '$lgt_rewrite_and_recompile_pl_directive'(local(Functor/Arity), private(Functor/Arity)). |
|---|
| 626 | |
|---|
| 627 | '$lgt_rewrite_and_recompile_pl_directive'(lib(Library), use_module(library(Library), Exports)) :- |
|---|
| 628 | '$lgt_eclipse_list_of_exports'(library(Library), Exports). |
|---|
| 629 | |
|---|
| 630 | '$lgt_rewrite_and_recompile_pl_directive'(use_module(Library), use_module(Library, Exports)) :- |
|---|
| 631 | '$lgt_eclipse_list_of_exports'(Library, Exports). |
|---|
| 632 | |
|---|
| 633 | |
|---|
| 634 | '$lgt_eclipse_list_of_exports'(Library, Exports) :- |
|---|
| 635 | ( atom(Library) -> |
|---|
| 636 | Module = Library |
|---|
| 637 | ; Library =..[_, Module] |
|---|
| 638 | ), |
|---|
| 639 | current_module(Module), |
|---|
| 640 | get_module_info(Module, interface, Interface), |
|---|
| 641 | '$lgt_eclipse_filter_exports'(Interface, Exports). |
|---|
| 642 | |
|---|
| 643 | |
|---|
| 644 | '$lgt_eclipse_filter_exports'([], []). |
|---|
| 645 | |
|---|
| 646 | '$lgt_eclipse_filter_exports'([export(Predicate)| Interface], [Predicate| Exports]) :- |
|---|
| 647 | '$lgt_eclipse_filter_exports'(Interface, Exports). |
|---|
| 648 | |
|---|
| 649 | |
|---|
| 650 | |
|---|
| 651 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 652 | % |
|---|
| 653 | % Shortcut to the Logtalk built-in predicate logtalk_load/1 |
|---|
| 654 | % |
|---|
| 655 | % defined in the config files in order to be able to comment it out in case |
|---|
| 656 | % of conflict with some Prolog native feature; it implies conformance with |
|---|
| 657 | % the ISO Prolog standard regarding the definition of the {}/1 syntax |
|---|
| 658 | % |
|---|
| 659 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 660 | |
|---|
| 661 | {File, Files} :- |
|---|
| 662 | !, |
|---|
| 663 | logtalk_load(File), |
|---|
| 664 | {Files}. |
|---|
| 665 | {File} :- |
|---|
| 666 | logtalk_load(File). |
|---|
| 667 | |
|---|
| 668 | |
|---|
| 669 | |
|---|
| 670 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 671 | % |
|---|
| 672 | % end! |
|---|
| 673 | % |
|---|
| 674 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|