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