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