| 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 2 | % |
|---|
| 3 | % Logtalk - Open source object-oriented logic programming language |
|---|
| 4 | % Release 2.31.1 |
|---|
| 5 | % |
|---|
| 6 | % configuration file for CIAO Prolog 1.8p2 and later versions |
|---|
| 7 | % |
|---|
| 8 | % last updated: October 24, 2007 |
|---|
| 9 | % |
|---|
| 10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | :- use_package(iso). |
|---|
| 14 | |
|---|
| 15 | :- use_package(runtime_ops). |
|---|
| 16 | :- use_package(hiord). |
|---|
| 17 | |
|---|
| 18 | :- use_module(library(compiler)). |
|---|
| 19 | :- use_module(library(system)). |
|---|
| 20 | :- use_module(library(prolog_sys)). |
|---|
| 21 | :- use_module(library(sort)). |
|---|
| 22 | :- use_module(library(filenames)). |
|---|
| 23 | |
|---|
| 24 | :- include(engine(builtin_exports)). |
|---|
| 25 | |
|---|
| 26 | :- set_prolog_flag(multi_arity_warnings, off). |
|---|
| 27 | |
|---|
| 28 | :- op(1200, xfx, [(-->)]). |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 33 | % |
|---|
| 34 | % ISO Prolog Standard predicates that we must define because they are |
|---|
| 35 | % not built-in |
|---|
| 36 | % |
|---|
| 37 | % add a clause for lgt_iso_predicate/1 declaring each ISO predicate that |
|---|
| 38 | % we must define; there must be at least one clause for this predicate |
|---|
| 39 | % whose call should fail if we don't define any ISO predicates |
|---|
| 40 | % |
|---|
| 41 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | % '$lgt_iso_predicate'(?callable). |
|---|
| 45 | |
|---|
| 46 | '$lgt_iso_predicate'(_) :- |
|---|
| 47 | fail. |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 52 | % |
|---|
| 53 | % predicate properties |
|---|
| 54 | % |
|---|
| 55 | % this predicate must return at least static, dynamic, and built_in |
|---|
| 56 | % properties for an existing predicate |
|---|
| 57 | % |
|---|
| 58 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | % '$lgt_predicate_property'(+callable, ?predicate_property) |
|---|
| 62 | |
|---|
| 63 | '$lgt_predicate_property'(Pred, built_in) :- |
|---|
| 64 | functor(Pred, Functor, Arity), |
|---|
| 65 | builtin_export(_, Functor, Arity, _). |
|---|
| 66 | |
|---|
| 67 | '$lgt_predicate_property'(Pred, built_in) :- |
|---|
| 68 | lgt_ciao_iso_builtin(Pred). |
|---|
| 69 | |
|---|
| 70 | '$lgt_predicate_property'(Pred, static) :- |
|---|
| 71 | predicate_property(Pred, compiled). |
|---|
| 72 | |
|---|
| 73 | '$lgt_predicate_property'(Pred, static) :- |
|---|
| 74 | functor(Pred, Functor, Arity), |
|---|
| 75 | atom_concat('user:', Functor, Functor2), |
|---|
| 76 | functor(Pred2, Functor2, Arity), |
|---|
| 77 | predicate_property(Pred2, compiled). |
|---|
| 78 | |
|---|
| 79 | '$lgt_predicate_property'(Pred, Prop) :- |
|---|
| 80 | predicate_property(Pred, Prop). |
|---|
| 81 | |
|---|
| 82 | '$lgt_predicate_property'(Pred, Prop) :- |
|---|
| 83 | functor(Pred, Functor, Arity), |
|---|
| 84 | atom_concat('user:', Functor, Functor2), |
|---|
| 85 | functor(Pred2, Functor2, Arity), |
|---|
| 86 | predicate_property(Pred2, Prop). |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | lgt_ciao_iso_builtin(write(_)). |
|---|
| 90 | lgt_ciao_iso_builtin(write(_, _)). |
|---|
| 91 | lgt_ciao_iso_builtin(writeq(_)). |
|---|
| 92 | lgt_ciao_iso_builtin(writeq(_, _)). |
|---|
| 93 | lgt_ciao_iso_builtin(write_canonical(_)). |
|---|
| 94 | lgt_ciao_iso_builtin(write_canonical(_, _)). |
|---|
| 95 | lgt_ciao_iso_builtin(write_term(_, _)). |
|---|
| 96 | lgt_ciao_iso_builtin(write_term(_, _, _)). |
|---|
| 97 | |
|---|
| 98 | lgt_ciao_iso_builtin(read(_)). |
|---|
| 99 | lgt_ciao_iso_builtin(read(_, _)). |
|---|
| 100 | lgt_ciao_iso_builtin(read_term(_, _)). |
|---|
| 101 | lgt_ciao_iso_builtin(read_term(_, _, _)). |
|---|
| 102 | |
|---|
| 103 | lgt_ciao_iso_builtin(open(_, _, _, _)). |
|---|
| 104 | lgt_ciao_iso_builtin(close(_, _)). |
|---|
| 105 | lgt_ciao_iso_builtin(stream_property(_, _)). |
|---|
| 106 | |
|---|
| 107 | lgt_ciao_iso_builtin(op(_, _, _)). |
|---|
| 108 | lgt_ciao_iso_builtin(current_op(_, _, _)). |
|---|
| 109 | |
|---|
| 110 | lgt_ciao_iso_builtin(_ \= _). |
|---|
| 111 | lgt_ciao_iso_builtin(once(_)). |
|---|
| 112 | lgt_ciao_iso_builtin(compound(_)). |
|---|
| 113 | lgt_ciao_iso_builtin(sub_atom(_, _, _, _, _)). |
|---|
| 114 | lgt_ciao_iso_builtin(unify_with_occurs_check(_, _)). |
|---|
| 115 | |
|---|
| 116 | lgt_ciao_iso_builtin(char_code(_, _)). |
|---|
| 117 | lgt_ciao_iso_builtin(atom_chars(_, _)). |
|---|
| 118 | lgt_ciao_iso_builtin(number_chars(_, _)). |
|---|
| 119 | lgt_ciao_iso_builtin(get_byte(_)). |
|---|
| 120 | lgt_ciao_iso_builtin(get_byte(_, _)). |
|---|
| 121 | lgt_ciao_iso_builtin(peek_byte(_)). |
|---|
| 122 | lgt_ciao_iso_builtin(peek_byte(_, _)). |
|---|
| 123 | lgt_ciao_iso_builtin(put_byte(_)). |
|---|
| 124 | lgt_ciao_iso_builtin(put_byte(_, _)). |
|---|
| 125 | lgt_ciao_iso_builtin(get_char(_)). |
|---|
| 126 | lgt_ciao_iso_builtin(get_char(_, _)). |
|---|
| 127 | lgt_ciao_iso_builtin(peek_char(_)). |
|---|
| 128 | lgt_ciao_iso_builtin(peek_char(_, _)). |
|---|
| 129 | lgt_ciao_iso_builtin(put_char(_)). |
|---|
| 130 | lgt_ciao_iso_builtin(put_char(_, _)). |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 135 | % |
|---|
| 136 | % meta-predicates |
|---|
| 137 | % |
|---|
| 138 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | % call_cleanup(+callable, +callble) |
|---|
| 142 | |
|---|
| 143 | call_cleanup(_, _) :- |
|---|
| 144 | throw(not_supported(call_cleanup/2)). |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | % forall(+callable, +callble) -- built-in |
|---|
| 148 | |
|---|
| 149 | forall(Generate, Test) :- |
|---|
| 150 | \+ (call(Generate), \+ call(Test)). |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | % retractall(+callable) -- built-in |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | % call_with_args/2-9 |
|---|
| 157 | % |
|---|
| 158 | % use these definitions only if your compiler does |
|---|
| 159 | % not provide call_with_args/2-9 as built-in predicates |
|---|
| 160 | |
|---|
| 161 | call_with_args(F, A) :- |
|---|
| 162 | call(F, A). |
|---|
| 163 | |
|---|
| 164 | call_with_args(F, A1, A2) :- |
|---|
| 165 | call(F, A1, A2). |
|---|
| 166 | |
|---|
| 167 | call_with_args(F, A1, A2, A3) :- |
|---|
| 168 | call(F, A1, A2, A3). |
|---|
| 169 | |
|---|
| 170 | call_with_args(F, A1, A2, A3, A4) :- |
|---|
| 171 | call(F, A1, A2, A3, A4). |
|---|
| 172 | |
|---|
| 173 | call_with_args(F, A1, A2, A3, A4, A5) :- |
|---|
| 174 | call(F, A1, A2, A3, A4, A5). |
|---|
| 175 | |
|---|
| 176 | call_with_args(F, A1, A2, A3, A4, A5, A6) :- |
|---|
| 177 | call(F, A1, A2, A3, A4, A5, A6). |
|---|
| 178 | |
|---|
| 179 | call_with_args(F, A1, A2, A3, A4, A5, A6, A7) :- |
|---|
| 180 | call(F, A1, A2, A3, A4, A5, A6, A7). |
|---|
| 181 | |
|---|
| 182 | call_with_args(F, A1, A2, A3, A4, A5, A6, A7, A8) :- |
|---|
| 183 | call(F, A1, A2, A3, A4, A5, A6, A7, A8). |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 188 | % |
|---|
| 189 | % Prolog built-in meta-predicates |
|---|
| 190 | % |
|---|
| 191 | % (excluding ISO Prolog Standard meta-predicates) |
|---|
| 192 | % |
|---|
| 193 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | % '$lgt_pl_meta_predicate'(?callable). |
|---|
| 197 | |
|---|
| 198 | '$lgt_pl_meta_predicate'(_) :- |
|---|
| 199 | fail. |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 204 | % |
|---|
| 205 | % file extension predicates |
|---|
| 206 | % |
|---|
| 207 | % these extensions are used by Logtalk load/compile predicates |
|---|
| 208 | % |
|---|
| 209 | % you may want to change the extension for Prolog files to match |
|---|
| 210 | % the one expected by your Prolog compiler |
|---|
| 211 | % |
|---|
| 212 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | % '$lgt_file_extension'(?atom, ?atom) |
|---|
| 216 | |
|---|
| 217 | '$lgt_file_extension'(logtalk, '.lgt'). |
|---|
| 218 | '$lgt_file_extension'(prolog, '.pl'). |
|---|
| 219 | '$lgt_file_extension'(xml, '.xml'). |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 224 | % |
|---|
| 225 | % default flag values |
|---|
| 226 | % |
|---|
| 227 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | % '$lgt_default_flag'(?atom, ?atom) |
|---|
| 231 | % |
|---|
| 232 | % default values for all flags |
|---|
| 233 | |
|---|
| 234 | '$lgt_default_flag'(xmldocs, on). |
|---|
| 235 | '$lgt_default_flag'(xslfile, 'lgtxml.xsl'). |
|---|
| 236 | '$lgt_default_flag'(xmlspec, dtd). |
|---|
| 237 | '$lgt_default_flag'(xmlsref, local). |
|---|
| 238 | |
|---|
| 239 | '$lgt_default_flag'(unknown, warning). |
|---|
| 240 | '$lgt_default_flag'(misspelt, warning). |
|---|
| 241 | '$lgt_default_flag'(singletons, warning). |
|---|
| 242 | '$lgt_default_flag'(lgtredef, warning). |
|---|
| 243 | '$lgt_default_flag'(plredef, silent). |
|---|
| 244 | '$lgt_default_flag'(portability, silent). |
|---|
| 245 | |
|---|
| 246 | '$lgt_default_flag'(report, on). |
|---|
| 247 | |
|---|
| 248 | '$lgt_default_flag'(smart_compilation, off). |
|---|
| 249 | '$lgt_default_flag'(reload, always). |
|---|
| 250 | |
|---|
| 251 | '$lgt_default_flag'(startup_message, flags(verbose)). |
|---|
| 252 | |
|---|
| 253 | '$lgt_default_flag'(underscore_variables, dont_care). |
|---|
| 254 | |
|---|
| 255 | '$lgt_default_flag'(code_prefix, ''). |
|---|
| 256 | |
|---|
| 257 | '$lgt_default_flag'(debug, off). |
|---|
| 258 | '$lgt_default_flag'(break_predicate, false). |
|---|
| 259 | |
|---|
| 260 | '$lgt_default_flag'(events, off). |
|---|
| 261 | |
|---|
| 262 | '$lgt_default_flag'(altdirs, off). |
|---|
| 263 | '$lgt_default_flag'(tmpdir, 'lgt_tmp/'). |
|---|
| 264 | '$lgt_default_flag'(xmldir, 'xml_docs/'). |
|---|
| 265 | |
|---|
| 266 | '$lgt_default_flag'(encoding_directive, unsupported). |
|---|
| 267 | '$lgt_default_flag'(threads, unsupported). |
|---|
| 268 | |
|---|
| 269 | '$lgt_default_flag'(context_switching_calls, allow). |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 274 | % |
|---|
| 275 | % list predicates |
|---|
| 276 | % |
|---|
| 277 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | '$lgt_append'([], List, List). |
|---|
| 281 | '$lgt_append'([Head| Tail], List, [Head| Tail2]) :- |
|---|
| 282 | '$lgt_append'(Tail, List, Tail2). |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | '$lgt_member'(Head, List) :- |
|---|
| 286 | member(Head, List). |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | '$lgt_member_var'(V, [H| _]) :- |
|---|
| 290 | V == H. |
|---|
| 291 | '$lgt_member_var'(V, [_| T]) :- |
|---|
| 292 | '$lgt_member_var'(V, T). |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | '$lgt_is_list'([]) :- |
|---|
| 296 | !. |
|---|
| 297 | '$lgt_is_list'([_| Tail]) :- |
|---|
| 298 | '$lgt_is_list'(Tail). |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | '$lgt_is_proper_list'(List) :- |
|---|
| 302 | List == [], !. |
|---|
| 303 | '$lgt_is_proper_list'([_| Tail]) :- |
|---|
| 304 | nonvar(Tail), |
|---|
| 305 | '$lgt_is_proper_list'(Tail). |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 310 | % |
|---|
| 311 | % file predicates |
|---|
| 312 | % |
|---|
| 313 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 314 | |
|---|
| 315 | |
|---|
| 316 | % '$lgt_file_exists'(+atom) |
|---|
| 317 | % |
|---|
| 318 | % see if a file exist in the current directory |
|---|
| 319 | |
|---|
| 320 | '$lgt_file_exists'(File) :- |
|---|
| 321 | file_exists(File). |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | % '$lgt_directory_exists'(+atom) |
|---|
| 325 | % |
|---|
| 326 | % checks if a directory exists |
|---|
| 327 | |
|---|
| 328 | '$lgt_directory_exists'(Directory) :- |
|---|
| 329 | file_exists(Directory), |
|---|
| 330 | file_property(Directory, type(directory)). |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | % '$lgt_current_directory'(-atom) |
|---|
| 334 | % |
|---|
| 335 | % gets current working directory |
|---|
| 336 | |
|---|
| 337 | '$lgt_current_directory'(Directory) :- |
|---|
| 338 | working_directory(Directory, Directory). |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | % '$lgt_change_directory'(+atom) |
|---|
| 342 | % |
|---|
| 343 | % changes current working directory |
|---|
| 344 | |
|---|
| 345 | '$lgt_change_directory'(Directory) :- |
|---|
| 346 | cd(Directory). |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | % '$lgt_make_directory'(+atom) |
|---|
| 350 | % |
|---|
| 351 | % makes a new directory; succeeds if the directory already exists |
|---|
| 352 | |
|---|
| 353 | '$lgt_make_directory'(Directory) :- |
|---|
| 354 | file_exists(Directory) -> |
|---|
| 355 | true |
|---|
| 356 | ; |
|---|
| 357 | make_directory(Directory). |
|---|
| 358 | |
|---|
| 359 | |
|---|
| 360 | % '$lgt_load_prolog_code'(+atom, +atom) |
|---|
| 361 | % |
|---|
| 362 | % compile and load a Prolog file |
|---|
| 363 | |
|---|
| 364 | '$lgt_load_prolog_code'(File, _) :- |
|---|
| 365 | set_prolog_flag(multi_arity_warnings, off), |
|---|
| 366 | ensure_loaded(File). |
|---|
| 367 | |
|---|
| 368 | |
|---|
| 369 | % '$lgt_compare_file_mtimes'(?atom, +atom, +atom) |
|---|
| 370 | % |
|---|
| 371 | % compare file modification times |
|---|
| 372 | |
|---|
| 373 | '$lgt_compare_file_mtimes'(Result, File1, File2) :- |
|---|
| 374 | file_property(File1, mod_time(Time1)), |
|---|
| 375 | file_property(File2, mod_time(Time2)), |
|---|
| 376 | compare(Result, Time1, Time2). |
|---|
| 377 | |
|---|
| 378 | |
|---|
| 379 | |
|---|
| 380 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 381 | % |
|---|
| 382 | % sorting predicate |
|---|
| 383 | % |
|---|
| 384 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 385 | |
|---|
| 386 | |
|---|
| 387 | % '$lgt_keysort'(+list, -list) |
|---|
| 388 | |
|---|
| 389 | '$lgt_keysort'(List, Sorted) :- |
|---|
| 390 | keysort(List, Sorted). |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | % '$lgt_sort'(+list, -list) |
|---|
| 394 | |
|---|
| 395 | '$lgt_sort'(List, Sorted) :- |
|---|
| 396 | sort(List, Sorted). |
|---|
| 397 | |
|---|
| 398 | |
|---|
| 399 | |
|---|
| 400 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 401 | % |
|---|
| 402 | % time and date predicates |
|---|
| 403 | % |
|---|
| 404 | % if your Prolog compiler does not provide access to the operating system |
|---|
| 405 | % time and date just write dummy definitions |
|---|
| 406 | % |
|---|
| 407 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | % '$lgt_current_date'(?Year, ?Month, ?Day) |
|---|
| 411 | |
|---|
| 412 | '$lgt_current_date'(Year, Month, Day) :- |
|---|
| 413 | datime(_, Year, Month, Day, _, _, _, _, _). |
|---|
| 414 | |
|---|
| 415 | |
|---|
| 416 | % '$lgt_current_time'(?Hours, ?Mins, ?Secs) |
|---|
| 417 | |
|---|
| 418 | '$lgt_current_time'(Hours, Mins, Secs) :- |
|---|
| 419 | datime(_, _, _, _, Hours, Mins, Secs, _, _). |
|---|
| 420 | |
|---|
| 421 | |
|---|
| 422 | |
|---|
| 423 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 424 | % |
|---|
| 425 | % timing predicate |
|---|
| 426 | % |
|---|
| 427 | % if your Prolog compiler does not provide access to a timing predicate |
|---|
| 428 | % just write dummy definition |
|---|
| 429 | % |
|---|
| 430 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 431 | |
|---|
| 432 | |
|---|
| 433 | % '$lgt_cpu_time'(-Seconds) |
|---|
| 434 | |
|---|
| 435 | '$lgt_cpu_time'(Seconds) :- |
|---|
| 436 | statistics(runtime, [Miliseconds| _]), |
|---|
| 437 | Seconds is Miliseconds / 1000. |
|---|
| 438 | |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 442 | % |
|---|
| 443 | % comparison predicate |
|---|
| 444 | % |
|---|
| 445 | % the usual compare/3 definition |
|---|
| 446 | % |
|---|
| 447 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 448 | |
|---|
| 449 | |
|---|
| 450 | % compare(?atom, @term, @term) -- built-in |
|---|
| 451 | |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 455 | % |
|---|
| 456 | % callable predicate |
|---|
| 457 | % |
|---|
| 458 | % the usual callable/1 definition |
|---|
| 459 | % |
|---|
| 460 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 461 | |
|---|
| 462 | |
|---|
| 463 | % callable(@term) -- built-in |
|---|
| 464 | |
|---|
| 465 | |
|---|
| 466 | |
|---|
| 467 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 468 | % |
|---|
| 469 | % read character predicate |
|---|
| 470 | % |
|---|
| 471 | % read a single character echoing it and writing a newline after |
|---|
| 472 | % |
|---|
| 473 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 474 | |
|---|
| 475 | |
|---|
| 476 | '$lgt_read_single_char'(Char) :- |
|---|
| 477 | get_char(Char), |
|---|
| 478 | ( peek_code(10) -> % hack to workaround the lack of built-in |
|---|
| 479 | get_code(_) % support for unbuffered character input |
|---|
| 480 | ; true |
|---|
| 481 | ). |
|---|
| 482 | |
|---|
| 483 | |
|---|
| 484 | |
|---|
| 485 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 486 | % |
|---|
| 487 | % pretty print a term by naming its free variables |
|---|
| 488 | % (avoid instantiating variables in term by using double negation if necessary) |
|---|
| 489 | % |
|---|
| 490 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 491 | |
|---|
| 492 | |
|---|
| 493 | '$lgt_pretty_print_vars'(Stream, Term) :- |
|---|
| 494 | \+ \+ ( |
|---|
| 495 | numbervars(Term, 0, _), |
|---|
| 496 | write_term(Stream, Term, [numbervars(true)])). |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | '$lgt_pretty_print_vars_quoted'(Stream, Term) :- |
|---|
| 500 | \+ \+ ( |
|---|
| 501 | numbervars(Term, 0, _), |
|---|
| 502 | write_term(Stream, Term, [numbervars(true), quoted(true)])). |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 507 | % |
|---|
| 508 | % getting stream current line number |
|---|
| 509 | % (needed for improved compiler error messages) |
|---|
| 510 | % |
|---|
| 511 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 512 | |
|---|
| 513 | |
|---|
| 514 | % '$lgt_stream_current_line_number'(@stream, -integer) |
|---|
| 515 | |
|---|
| 516 | '$lgt_stream_current_line_number'(Stream, Line) :- |
|---|
| 517 | line_count(Stream, Last), |
|---|
| 518 | Line is Last + 1. |
|---|
| 519 | |
|---|
| 520 | |
|---|
| 521 | |
|---|
| 522 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 523 | % |
|---|
| 524 | % handling of Prolog-proprietary directives on Logtalk source files |
|---|
| 525 | % |
|---|
| 526 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 527 | |
|---|
| 528 | |
|---|
| 529 | % '$lgt_ignore_pl_directive'(@callable) |
|---|
| 530 | |
|---|
| 531 | '$lgt_ignore_pl_directive'(comment(_, _)). |
|---|
| 532 | |
|---|
| 533 | |
|---|
| 534 | % '$lgt_copy_pl_directive'(@callable, -callable) |
|---|
| 535 | |
|---|
| 536 | '$lgt_rewrite_and_copy_pl_directive'(_, _) :- |
|---|
| 537 | fail. |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | % '$lgt_rewrite_pl_directive'(@callable, -callable) |
|---|
| 541 | |
|---|
| 542 | '$lgt_rewrite_and_recompile_pl_directive'(imports(Module, Imports), uses(Module, Imports)). |
|---|
| 543 | '$lgt_rewrite_and_recompile_pl_directive'(module(Module, Exports, []), module(Module, Exports)) :- |
|---|
| 544 | ( var(Module) -> % module name taken from file name |
|---|
| 545 | '$lgt_ciao_find_module_name'(Module) |
|---|
| 546 | ; true |
|---|
| 547 | ). |
|---|
| 548 | '$lgt_rewrite_and_recompile_pl_directive'(module(Module, Exports, [assertions]), module(Module, Exports)) :- |
|---|
| 549 | ( var(Module) -> % module name taken from file name |
|---|
| 550 | '$lgt_ciao_find_module_name'(Module) |
|---|
| 551 | ; true |
|---|
| 552 | ). |
|---|
| 553 | |
|---|
| 554 | |
|---|
| 555 | '$lgt_ciao_find_module_name'(Module) :- |
|---|
| 556 | stream_property(Stream, mode(read)), |
|---|
| 557 | stream_property(Stream, file_name(Path)), |
|---|
| 558 | no_path_file_name(Path, File), |
|---|
| 559 | extension(File, '.lgt'), |
|---|
| 560 | basename(File, Module), |
|---|
| 561 | !. |
|---|
| 562 | |
|---|
| 563 | |
|---|
| 564 | |
|---|
| 565 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 566 | % |
|---|
| 567 | % Shortcut to the Logtalk built-in predicate logtalk_load/1 |
|---|
| 568 | % |
|---|
| 569 | % defined in the config files in order to be able to comment it out in case |
|---|
| 570 | % of conflict with some Prolog native feature; it implies conformance with |
|---|
| 571 | % the ISO Prolog standard regarding the definition of the {}/1 syntax |
|---|
| 572 | % |
|---|
| 573 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 574 | |
|---|
| 575 | {File, Files} :- |
|---|
| 576 | !, |
|---|
| 577 | logtalk_load(File), |
|---|
| 578 | {Files}. |
|---|
| 579 | {File} :- |
|---|
| 580 | logtalk_load(File). |
|---|
| 581 | |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|
| 585 | % |
|---|
| 586 | % end! |
|---|
| 587 | % |
|---|
| 588 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|---|