kibi-swipl-linux-x64-gnu 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (550) hide show
  1. package/README.md +29 -0
  2. package/bin/swipl +0 -0
  3. package/bin/swipl-win +0 -0
  4. package/build-manifest.json +70 -0
  5. package/lib/cmake/swipl/SWIPLConfig.cmake +21 -0
  6. package/lib/cmake/swipl/SWIPLConfigVersion.cmake +65 -0
  7. package/lib/cmake/swipl/SWIPLTargets-release.cmake +28 -0
  8. package/lib/cmake/swipl/SWIPLTargets.cmake +109 -0
  9. package/lib/swipl/ABI +1 -0
  10. package/lib/swipl/LICENSE +41 -0
  11. package/lib/swipl/README.md +116 -0
  12. package/lib/swipl/app/README.md +25 -0
  13. package/lib/swipl/app/app.pl +87 -0
  14. package/lib/swipl/app/pack.pl +350 -0
  15. package/lib/swipl/app/qlf.pl +521 -0
  16. package/lib/swipl/app/splfr.pl +177 -0
  17. package/lib/swipl/app/sys.pl +310 -0
  18. package/lib/swipl/bin/swipl.home +1 -0
  19. package/lib/swipl/boot/apply.pl +73 -0
  20. package/lib/swipl/boot/attvar.pl +344 -0
  21. package/lib/swipl/boot/autoload.pl +1226 -0
  22. package/lib/swipl/boot/bags.pl +283 -0
  23. package/lib/swipl/boot/dcg.pl +388 -0
  24. package/lib/swipl/boot/dicts.pl +193 -0
  25. package/lib/swipl/boot/dwim.pl +485 -0
  26. package/lib/swipl/boot/engines.pl +152 -0
  27. package/lib/swipl/boot/expand.pl +1628 -0
  28. package/lib/swipl/boot/gc.pl +65 -0
  29. package/lib/swipl/boot/history.pl +304 -0
  30. package/lib/swipl/boot/init.pl +4682 -0
  31. package/lib/swipl/boot/iri.pl +64 -0
  32. package/lib/swipl/boot/license.pl +390 -0
  33. package/lib/swipl/boot/load.pl +81 -0
  34. package/lib/swipl/boot/messages.pl +2521 -0
  35. package/lib/swipl/boot/packs.pl +306 -0
  36. package/lib/swipl/boot/predopts.pl +154 -0
  37. package/lib/swipl/boot/qlf.pl +141 -0
  38. package/lib/swipl/boot/rc.pl +263 -0
  39. package/lib/swipl/boot/syspred.pl +1634 -0
  40. package/lib/swipl/boot/tabling.pl +2321 -0
  41. package/lib/swipl/boot/threads.pl +42 -0
  42. package/lib/swipl/boot/toplevel.pl +2248 -0
  43. package/lib/swipl/boot/topvars.pl +261 -0
  44. package/lib/swipl/boot.prc +0 -0
  45. package/lib/swipl/cmake/swipl.cmake +131 -0
  46. package/lib/swipl/customize/README.md +23 -0
  47. package/lib/swipl/customize/edit +101 -0
  48. package/lib/swipl/customize/init.pl +164 -0
  49. package/lib/swipl/demo/README.md +33 -0
  50. package/lib/swipl/demo/likes.pl +44 -0
  51. package/lib/swipl/doc/packages/examples/chr/bool.chr +281 -0
  52. package/lib/swipl/doc/packages/examples/chr/chrdif.chr +87 -0
  53. package/lib/swipl/doc/packages/examples/chr/chrfreeze.chr +6 -0
  54. package/lib/swipl/doc/packages/examples/chr/family.chr +116 -0
  55. package/lib/swipl/doc/packages/examples/chr/fib.chr +24 -0
  56. package/lib/swipl/doc/packages/examples/chr/fibonacci.chr +31 -0
  57. package/lib/swipl/doc/packages/examples/chr/gcd.chr +28 -0
  58. package/lib/swipl/doc/packages/examples/chr/leq.chr +34 -0
  59. package/lib/swipl/doc/packages/examples/chr/listdom.chr +138 -0
  60. package/lib/swipl/doc/packages/examples/chr/primes.chr +29 -0
  61. package/lib/swipl/doc/packages/examples/http/README.md +98 -0
  62. package/lib/swipl/doc/packages/examples/http/calc.pl +92 -0
  63. package/lib/swipl/doc/packages/examples/http/demo_body.pl +232 -0
  64. package/lib/swipl/doc/packages/examples/http/demo_client.pl +165 -0
  65. package/lib/swipl/doc/packages/examples/http/demo_daemon.pl +38 -0
  66. package/lib/swipl/doc/packages/examples/http/demo_files.pl +50 -0
  67. package/lib/swipl/doc/packages/examples/http/demo_hello.pl +15 -0
  68. package/lib/swipl/doc/packages/examples/http/demo_login.pl +280 -0
  69. package/lib/swipl/doc/packages/examples/http/demo_openid.pl +177 -0
  70. package/lib/swipl/doc/packages/examples/http/demo_pwp.pl +20 -0
  71. package/lib/swipl/doc/packages/examples/http/demo_rest.pl +56 -0
  72. package/lib/swipl/doc/packages/examples/http/demo_threads.pl +52 -0
  73. package/lib/swipl/doc/packages/examples/http/linux-init-script +126 -0
  74. package/lib/swipl/doc/packages/examples/http/pwp/context.pwp +23 -0
  75. package/lib/swipl/doc/packages/examples/http/pwp/index.pwp +25 -0
  76. package/lib/swipl/doc/packages/examples/http/pwp/pwp1.pwp +12 -0
  77. package/lib/swipl/doc/packages/examples/http/pwp/pwp2.pwp +10 -0
  78. package/lib/swipl/doc/packages/examples/http/pwp/pwp3.pwp +25 -0
  79. package/lib/swipl/doc/packages/examples/http/pwp/pwp4.pwp +23 -0
  80. package/lib/swipl/doc/packages/examples/http/pwp/pwp5.pwp +11 -0
  81. package/lib/swipl/doc/packages/examples/http/pwp/pwp6.pwp +3 -0
  82. package/lib/swipl/doc/packages/examples/http/pwp/pwp7.pwp +3 -0
  83. package/lib/swipl/doc/packages/examples/http/pwp/pwp8.pwp +3 -0
  84. package/lib/swipl/doc/packages/examples/http/pwp/pwpdb.pl +12 -0
  85. package/lib/swipl/doc/packages/examples/http/systemd-script.service +18 -0
  86. package/lib/swipl/doc/packages/examples/http/upstart-script.conf +20 -0
  87. package/lib/swipl/doc/packages/examples/plunit/read.pl +17 -0
  88. package/lib/swipl/doc/packages/examples/plunit/simple.pl +33 -0
  89. package/lib/swipl/doc/packages/examples/ssl/client.pl +83 -0
  90. package/lib/swipl/doc/packages/examples/ssl/etc/README +52 -0
  91. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-cert.p12 +0 -0
  92. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-cert.pem +85 -0
  93. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-key.pem +30 -0
  94. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/cacert.pem +82 -0
  95. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/careq.pem +18 -0
  96. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/crlnumber +1 -0
  97. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/index.txt +3 -0
  98. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/index.txt.attr +1 -0
  99. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/newcerts/9DC08797A0F63F7C.pem +85 -0
  100. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/newcerts/9DC08797A0F63F7D.pem +85 -0
  101. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/private/cakey.pem +30 -0
  102. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/serial +1 -0
  103. package/lib/swipl/doc/packages/examples/ssl/etc/server/server-cert.pem +85 -0
  104. package/lib/swipl/doc/packages/examples/ssl/etc/server/server-key.pem +30 -0
  105. package/lib/swipl/doc/packages/examples/ssl/https.pl +267 -0
  106. package/lib/swipl/doc/packages/examples/ssl/server.pl +106 -0
  107. package/lib/swipl/include/SWI-Prolog.h +1544 -0
  108. package/lib/swipl/include/SWI-Stream.h +537 -0
  109. package/lib/swipl/include/Yap/YapInterface.h +283 -0
  110. package/lib/swipl/include/sicstus/sicstus.h +452 -0
  111. package/lib/swipl/lib/x86_64-linux/cgi.so +0 -0
  112. package/lib/swipl/lib/x86_64-linux/crypt.so +0 -0
  113. package/lib/swipl/lib/x86_64-linux/crypto4pl.so +0 -0
  114. package/lib/swipl/lib/x86_64-linux/double_metaphone.so +0 -0
  115. package/lib/swipl/lib/x86_64-linux/files.so +0 -0
  116. package/lib/swipl/lib/x86_64-linux/hashstream.so +0 -0
  117. package/lib/swipl/lib/x86_64-linux/http_stream.so +0 -0
  118. package/lib/swipl/lib/x86_64-linux/isub.so +0 -0
  119. package/lib/swipl/lib/x86_64-linux/json.so +0 -0
  120. package/lib/swipl/lib/x86_64-linux/libswipl.so.10 +0 -0
  121. package/lib/swipl/lib/x86_64-linux/mallocinfo.so +0 -0
  122. package/lib/swipl/lib/x86_64-linux/md54pl.so +0 -0
  123. package/lib/swipl/lib/x86_64-linux/memfile.so +0 -0
  124. package/lib/swipl/lib/x86_64-linux/ntriples.so +0 -0
  125. package/lib/swipl/lib/x86_64-linux/pcre4pl.so +0 -0
  126. package/lib/swipl/lib/x86_64-linux/porter_stem.so +0 -0
  127. package/lib/swipl/lib/x86_64-linux/process.so +0 -0
  128. package/lib/swipl/lib/x86_64-linux/prolog_stream.so +0 -0
  129. package/lib/swipl/lib/x86_64-linux/rdf_db.so +0 -0
  130. package/lib/swipl/lib/x86_64-linux/readutil.so +0 -0
  131. package/lib/swipl/lib/x86_64-linux/rlimit.so +0 -0
  132. package/lib/swipl/lib/x86_64-linux/sched.so +0 -0
  133. package/lib/swipl/lib/x86_64-linux/sgml2pl.so +0 -0
  134. package/lib/swipl/lib/x86_64-linux/sha4pl.so +0 -0
  135. package/lib/swipl/lib/x86_64-linux/snowball.so +0 -0
  136. package/lib/swipl/lib/x86_64-linux/socket.so +0 -0
  137. package/lib/swipl/lib/x86_64-linux/ssl4pl.so +0 -0
  138. package/lib/swipl/lib/x86_64-linux/streaminfo.so +0 -0
  139. package/lib/swipl/lib/x86_64-linux/syslog.so +0 -0
  140. package/lib/swipl/lib/x86_64-linux/time.so +0 -0
  141. package/lib/swipl/lib/x86_64-linux/turtle.so +0 -0
  142. package/lib/swipl/lib/x86_64-linux/uid.so +0 -0
  143. package/lib/swipl/lib/x86_64-linux/unix.so +0 -0
  144. package/lib/swipl/lib/x86_64-linux/uri.so +0 -0
  145. package/lib/swipl/lib/x86_64-linux/websocket.so +0 -0
  146. package/lib/swipl/lib/x86_64-linux/zlib4pl.so +0 -0
  147. package/lib/swipl/library/INDEX.pl +1020 -0
  148. package/lib/swipl/library/aggregate.pl +755 -0
  149. package/lib/swipl/library/ansi_term.pl +653 -0
  150. package/lib/swipl/library/apply.pl +426 -0
  151. package/lib/swipl/library/apply_macros.pl +497 -0
  152. package/lib/swipl/library/arithmetic.pl +320 -0
  153. package/lib/swipl/library/assoc.pl +522 -0
  154. package/lib/swipl/library/atom.pl +169 -0
  155. package/lib/swipl/library/backcomp.pl +688 -0
  156. package/lib/swipl/library/base32.pl +291 -0
  157. package/lib/swipl/library/base64.pl +441 -0
  158. package/lib/swipl/library/broadcast.pl +161 -0
  159. package/lib/swipl/library/build/cmake.pl +137 -0
  160. package/lib/swipl/library/build/conan.pl +232 -0
  161. package/lib/swipl/library/build/make.pl +168 -0
  162. package/lib/swipl/library/build/tools.pl +825 -0
  163. package/lib/swipl/library/charsio.pl +195 -0
  164. package/lib/swipl/library/check.pl +1097 -0
  165. package/lib/swipl/library/check_installation.pl +912 -0
  166. package/lib/swipl/library/clp/INDEX.pl +157 -0
  167. package/lib/swipl/library/clp/bounds.pl +2036 -0
  168. package/lib/swipl/library/clp/clp_distinct.pl +263 -0
  169. package/lib/swipl/library/clp/clp_events.pl +92 -0
  170. package/lib/swipl/library/clp/clpb.pl +1896 -0
  171. package/lib/swipl/library/clp/clpfd.pl +7906 -0
  172. package/lib/swipl/library/clp/simplex.pl +1580 -0
  173. package/lib/swipl/library/codesio.pl +182 -0
  174. package/lib/swipl/library/coinduction.pl +183 -0
  175. package/lib/swipl/library/console_input.pl +289 -0
  176. package/lib/swipl/library/csv.pl +611 -0
  177. package/lib/swipl/library/ctypes.pl +161 -0
  178. package/lib/swipl/library/date.pl +370 -0
  179. package/lib/swipl/library/dcg/INDEX.pl +35 -0
  180. package/lib/swipl/library/dcg/basics.pl +514 -0
  181. package/lib/swipl/library/dcg/high_order.pl +227 -0
  182. package/lib/swipl/library/debug.pl +499 -0
  183. package/lib/swipl/library/dialect/bim.pl +186 -0
  184. package/lib/swipl/library/dialect/commons.pl +77 -0
  185. package/lib/swipl/library/dialect/eclipse/test_util_iso.pl +355 -0
  186. package/lib/swipl/library/dialect/hprolog/format.pl +44 -0
  187. package/lib/swipl/library/dialect/hprolog.pl +314 -0
  188. package/lib/swipl/library/dialect/ifprolog.pl +1317 -0
  189. package/lib/swipl/library/dialect/iso/iso_predicates.pl +277 -0
  190. package/lib/swipl/library/dialect/sicstus/README.TXT +1 -0
  191. package/lib/swipl/library/dialect/sicstus/arrays.pl +121 -0
  192. package/lib/swipl/library/dialect/sicstus/block.pl +278 -0
  193. package/lib/swipl/library/dialect/sicstus/lists.pl +167 -0
  194. package/lib/swipl/library/dialect/sicstus/ordsets.pl +52 -0
  195. package/lib/swipl/library/dialect/sicstus/sockets.pl +174 -0
  196. package/lib/swipl/library/dialect/sicstus/system.pl +262 -0
  197. package/lib/swipl/library/dialect/sicstus/terms.pl +57 -0
  198. package/lib/swipl/library/dialect/sicstus/timeout.pl +92 -0
  199. package/lib/swipl/library/dialect/sicstus.pl +582 -0
  200. package/lib/swipl/library/dialect/sicstus4/aggregate.pl +60 -0
  201. package/lib/swipl/library/dialect/sicstus4/between.pl +62 -0
  202. package/lib/swipl/library/dialect/sicstus4/clpfd.pl +75 -0
  203. package/lib/swipl/library/dialect/sicstus4/file_systems.pl +413 -0
  204. package/lib/swipl/library/dialect/sicstus4/lists.pl +274 -0
  205. package/lib/swipl/library/dialect/sicstus4/ordsets.pl +54 -0
  206. package/lib/swipl/library/dialect/sicstus4/samsort.pl +86 -0
  207. package/lib/swipl/library/dialect/sicstus4/sets.pl +124 -0
  208. package/lib/swipl/library/dialect/sicstus4/sockets.pl +164 -0
  209. package/lib/swipl/library/dialect/sicstus4/system.pl +80 -0
  210. package/lib/swipl/library/dialect/sicstus4/terms.pl +89 -0
  211. package/lib/swipl/library/dialect/sicstus4/timeout.pl +43 -0
  212. package/lib/swipl/library/dialect/sicstus4/types.pl +103 -0
  213. package/lib/swipl/library/dialect/sicstus4.pl +200 -0
  214. package/lib/swipl/library/dialect/swi/syspred_options.pl +250 -0
  215. package/lib/swipl/library/dialect/xsb/README.md +20 -0
  216. package/lib/swipl/library/dialect/xsb/basics.pl +318 -0
  217. package/lib/swipl/library/dialect/xsb/consult.pl +87 -0
  218. package/lib/swipl/library/dialect/xsb/curr_sym.pl +57 -0
  219. package/lib/swipl/library/dialect/xsb/error_handler.pl +111 -0
  220. package/lib/swipl/library/dialect/xsb/gensym.pl +53 -0
  221. package/lib/swipl/library/dialect/xsb/gpp.pl +138 -0
  222. package/lib/swipl/library/dialect/xsb/intern.pl +48 -0
  223. package/lib/swipl/library/dialect/xsb/lists.pl +47 -0
  224. package/lib/swipl/library/dialect/xsb/machine.pl +295 -0
  225. package/lib/swipl/library/dialect/xsb/ordsets.pl +53 -0
  226. package/lib/swipl/library/dialect/xsb/setof.pl +54 -0
  227. package/lib/swipl/library/dialect/xsb/source.pl +308 -0
  228. package/lib/swipl/library/dialect/xsb/standard.pl +169 -0
  229. package/lib/swipl/library/dialect/xsb/storage.pl +70 -0
  230. package/lib/swipl/library/dialect/xsb/string.pl +76 -0
  231. package/lib/swipl/library/dialect/xsb/thread.pl +62 -0
  232. package/lib/swipl/library/dialect/xsb/timed_call.pl +158 -0
  233. package/lib/swipl/library/dialect/xsb.pl +688 -0
  234. package/lib/swipl/library/dialect/yap/README.TXT +8 -0
  235. package/lib/swipl/library/dialect/yap.pl +283 -0
  236. package/lib/swipl/library/dialect.pl +123 -0
  237. package/lib/swipl/library/dicts.pl +399 -0
  238. package/lib/swipl/library/dif.pl +426 -0
  239. package/lib/swipl/library/edinburgh.pl +138 -0
  240. package/lib/swipl/library/edit.pl +783 -0
  241. package/lib/swipl/library/error.pl +495 -0
  242. package/lib/swipl/library/exceptions.pl +231 -0
  243. package/lib/swipl/library/explain.pl +543 -0
  244. package/lib/swipl/library/ext/RDF/INDEX.pl +25 -0
  245. package/lib/swipl/library/ext/RDF/rdf.pl +450 -0
  246. package/lib/swipl/library/ext/RDF/rdf_parser.pl +649 -0
  247. package/lib/swipl/library/ext/RDF/rdf_triple.pl +448 -0
  248. package/lib/swipl/library/ext/RDF/rdf_write.pl +701 -0
  249. package/lib/swipl/library/ext/RDF/rewrite_term.pl +177 -0
  250. package/lib/swipl/library/ext/chr/chr/a_star.pl +80 -0
  251. package/lib/swipl/library/ext/chr/chr/binomialheap.pl +142 -0
  252. package/lib/swipl/library/ext/chr/chr/builtins.pl +629 -0
  253. package/lib/swipl/library/ext/chr/chr/chr_compiler_errors.pl +179 -0
  254. package/lib/swipl/library/ext/chr/chr/chr_compiler_options.pl +382 -0
  255. package/lib/swipl/library/ext/chr/chr/chr_compiler_utility.pl +338 -0
  256. package/lib/swipl/library/ext/chr/chr/chr_debug.pl +59 -0
  257. package/lib/swipl/library/ext/chr/chr/chr_hashtable_store.pl +425 -0
  258. package/lib/swipl/library/ext/chr/chr/chr_integertable_store.pl +139 -0
  259. package/lib/swipl/library/ext/chr/chr/chr_messages.pl +176 -0
  260. package/lib/swipl/library/ext/chr/chr/chr_op.pl +53 -0
  261. package/lib/swipl/library/ext/chr/chr/chr_runtime.pl +1016 -0
  262. package/lib/swipl/library/ext/chr/chr/chr_translate.pl +25424 -0
  263. package/lib/swipl/library/ext/chr/chr/clean_code.pl +252 -0
  264. package/lib/swipl/library/ext/chr/chr/find.pl +78 -0
  265. package/lib/swipl/library/ext/chr/chr/guard_entailment.pl +19432 -0
  266. package/lib/swipl/library/ext/chr/chr/listmap.pl +108 -0
  267. package/lib/swipl/library/ext/chr/chr/pairlist.pl +78 -0
  268. package/lib/swipl/library/ext/chr/chr.pl +686 -0
  269. package/lib/swipl/library/ext/clib/INDEX.pl +158 -0
  270. package/lib/swipl/library/ext/clib/cgi.pl +86 -0
  271. package/lib/swipl/library/ext/clib/crypt.pl +44 -0
  272. package/lib/swipl/library/ext/clib/filesex.pl +644 -0
  273. package/lib/swipl/library/ext/clib/hash_stream.pl +119 -0
  274. package/lib/swipl/library/ext/clib/mallocinfo.pl +138 -0
  275. package/lib/swipl/library/ext/clib/md5.pl +68 -0
  276. package/lib/swipl/library/ext/clib/memfile.pl +61 -0
  277. package/lib/swipl/library/ext/clib/process.pl +573 -0
  278. package/lib/swipl/library/ext/clib/prolog_server.pl +157 -0
  279. package/lib/swipl/library/ext/clib/prolog_stream.pl +80 -0
  280. package/lib/swipl/library/ext/clib/rlimit.pl +54 -0
  281. package/lib/swipl/library/ext/clib/sched.pl +85 -0
  282. package/lib/swipl/library/ext/clib/sha.pl +162 -0
  283. package/lib/swipl/library/ext/clib/socket.pl +1102 -0
  284. package/lib/swipl/library/ext/clib/streaminfo.pl +103 -0
  285. package/lib/swipl/library/ext/clib/streampool.pl +136 -0
  286. package/lib/swipl/library/ext/clib/syslog.pl +180 -0
  287. package/lib/swipl/library/ext/clib/time.pl +194 -0
  288. package/lib/swipl/library/ext/clib/udp_broadcast.pl +975 -0
  289. package/lib/swipl/library/ext/clib/uid.pl +220 -0
  290. package/lib/swipl/library/ext/clib/unix.pl +317 -0
  291. package/lib/swipl/library/ext/clib/uri.pl +530 -0
  292. package/lib/swipl/library/ext/clib/uuid.pl +207 -0
  293. package/lib/swipl/library/ext/http/http/INDEX.pl +266 -0
  294. package/lib/swipl/library/ext/http/http/README.md +34 -0
  295. package/lib/swipl/library/ext/http/http/ax.pl +189 -0
  296. package/lib/swipl/library/ext/http/http/dcg_basics.pl +49 -0
  297. package/lib/swipl/library/ext/http/http/graphql.pl +1367 -0
  298. package/lib/swipl/library/ext/http/http/html_decl.pl +416 -0
  299. package/lib/swipl/library/ext/http/http/html_head.pl +654 -0
  300. package/lib/swipl/library/ext/http/http/html_quasiquotations.pl +120 -0
  301. package/lib/swipl/library/ext/http/http/html_write.pl +1425 -0
  302. package/lib/swipl/library/ext/http/http/htmx.pl +139 -0
  303. package/lib/swipl/library/ext/http/http/http_authenticate.pl +364 -0
  304. package/lib/swipl/library/ext/http/http/http_client.pl +412 -0
  305. package/lib/swipl/library/ext/http/http/http_cookie.pl +245 -0
  306. package/lib/swipl/library/ext/http/http/http_cors.pl +176 -0
  307. package/lib/swipl/library/ext/http/http/http_digest.pl +820 -0
  308. package/lib/swipl/library/ext/http/http/http_dirindex.pl +296 -0
  309. package/lib/swipl/library/ext/http/http/http_dispatch.pl +1552 -0
  310. package/lib/swipl/library/ext/http/http/http_dyn_workers.pl +214 -0
  311. package/lib/swipl/library/ext/http/http/http_error.pl +126 -0
  312. package/lib/swipl/library/ext/http/http/http_exception.pl +225 -0
  313. package/lib/swipl/library/ext/http/http/http_files.pl +163 -0
  314. package/lib/swipl/library/ext/http/http/http_header.pl +2820 -0
  315. package/lib/swipl/library/ext/http/http/http_hook.pl +106 -0
  316. package/lib/swipl/library/ext/http/http/http_host.pl +204 -0
  317. package/lib/swipl/library/ext/http/http/http_load.pl +113 -0
  318. package/lib/swipl/library/ext/http/http/http_log.pl +738 -0
  319. package/lib/swipl/library/ext/http/http/http_multipart_plugin.pl +232 -0
  320. package/lib/swipl/library/ext/http/http/http_open.pl +1821 -0
  321. package/lib/swipl/library/ext/http/http/http_openid.pl +1561 -0
  322. package/lib/swipl/library/ext/http/http/http_parameters.pl +504 -0
  323. package/lib/swipl/library/ext/http/http/http_path.pl +380 -0
  324. package/lib/swipl/library/ext/http/http/http_proxy.pl +80 -0
  325. package/lib/swipl/library/ext/http/http/http_pwp.pl +351 -0
  326. package/lib/swipl/library/ext/http/http/http_redis_plugin.pl +332 -0
  327. package/lib/swipl/library/ext/http/http/http_server.pl +105 -0
  328. package/lib/swipl/library/ext/http/http/http_server_files.pl +126 -0
  329. package/lib/swipl/library/ext/http/http/http_server_health.pl +186 -0
  330. package/lib/swipl/library/ext/http/http/http_session.pl +1040 -0
  331. package/lib/swipl/library/ext/http/http/http_sgml_plugin.pl +137 -0
  332. package/lib/swipl/library/ext/http/http/http_stream.pl +376 -0
  333. package/lib/swipl/library/ext/http/http/http_unix_daemon.pl +989 -0
  334. package/lib/swipl/library/ext/http/http/http_wrapper.pl +559 -0
  335. package/lib/swipl/library/ext/http/http/hub.pl +600 -0
  336. package/lib/swipl/library/ext/http/http/js_write.pl +461 -0
  337. package/lib/swipl/library/ext/http/http/mimepack.pl +224 -0
  338. package/lib/swipl/library/ext/http/http/mimetype.pl +276 -0
  339. package/lib/swipl/library/ext/http/http/term_html.pl +797 -0
  340. package/lib/swipl/library/ext/http/http/thread_httpd.pl +1181 -0
  341. package/lib/swipl/library/ext/http/http/web/css/dirindex.css +24 -0
  342. package/lib/swipl/library/ext/http/http/web/css/openid.css +57 -0
  343. package/lib/swipl/library/ext/http/http/web/icons/back.png +0 -0
  344. package/lib/swipl/library/ext/http/http/web/icons/c.png +0 -0
  345. package/lib/swipl/library/ext/http/http/web/icons/compressed.png +0 -0
  346. package/lib/swipl/library/ext/http/http/web/icons/folder.png +0 -0
  347. package/lib/swipl/library/ext/http/http/web/icons/generic.png +0 -0
  348. package/lib/swipl/library/ext/http/http/web/icons/layout.png +0 -0
  349. package/lib/swipl/library/ext/http/http/web/icons/openid-logo-square.png +0 -0
  350. package/lib/swipl/library/ext/http/http/web/icons/openid-logo-tiny.png +0 -0
  351. package/lib/swipl/library/ext/http/http/websocket.pl +729 -0
  352. package/lib/swipl/library/ext/http/http/yadis.pl +205 -0
  353. package/lib/swipl/library/ext/json/INDEX.pl +36 -0
  354. package/lib/swipl/library/ext/json/http/INDEX.pl +16 -0
  355. package/lib/swipl/library/ext/json/http/http_json.pl +490 -0
  356. package/lib/swipl/library/ext/json/http/js_grammar.pl +53 -0
  357. package/lib/swipl/library/ext/json/http/json.pl +48 -0
  358. package/lib/swipl/library/ext/json/http/json_convert.pl +48 -0
  359. package/lib/swipl/library/ext/json/json.pl +1215 -0
  360. package/lib/swipl/library/ext/json/json_convert.pl +681 -0
  361. package/lib/swipl/library/ext/json/json_grammar.pl +349 -0
  362. package/lib/swipl/library/ext/json/json_rpc_client.pl +423 -0
  363. package/lib/swipl/library/ext/json/json_rpc_common.pl +104 -0
  364. package/lib/swipl/library/ext/json/json_rpc_server.pl +489 -0
  365. package/lib/swipl/library/ext/json/json_schema.pl +2111 -0
  366. package/lib/swipl/library/ext/nlp/INDEX.pl +15 -0
  367. package/lib/swipl/library/ext/nlp/double_metaphone.pl +86 -0
  368. package/lib/swipl/library/ext/nlp/isub.pl +162 -0
  369. package/lib/swipl/library/ext/nlp/porter_stem.pl +50 -0
  370. package/lib/swipl/library/ext/nlp/snowball.pl +97 -0
  371. package/lib/swipl/library/ext/pcre/INDEX.pl +17 -0
  372. package/lib/swipl/library/ext/pcre/pcre.pl +974 -0
  373. package/lib/swipl/library/ext/plunit/INDEX.pl +20 -0
  374. package/lib/swipl/library/ext/plunit/plunit.pl +2631 -0
  375. package/lib/swipl/library/ext/plunit/test_wizard.pl +249 -0
  376. package/lib/swipl/library/ext/semweb/semweb/INDEX.pl +288 -0
  377. package/lib/swipl/library/ext/semweb/semweb/rdf11.pl +2106 -0
  378. package/lib/swipl/library/ext/semweb/semweb/rdf11_containers.pl +299 -0
  379. package/lib/swipl/library/ext/semweb/semweb/rdf_cache.pl +278 -0
  380. package/lib/swipl/library/ext/semweb/semweb/rdf_compare.pl +132 -0
  381. package/lib/swipl/library/ext/semweb/semweb/rdf_db.pl +3468 -0
  382. package/lib/swipl/library/ext/semweb/semweb/rdf_edit.pl +1145 -0
  383. package/lib/swipl/library/ext/semweb/semweb/rdf_http_plugin.pl +274 -0
  384. package/lib/swipl/library/ext/semweb/semweb/rdf_library.pl +1021 -0
  385. package/lib/swipl/library/ext/semweb/semweb/rdf_litindex.pl +1035 -0
  386. package/lib/swipl/library/ext/semweb/semweb/rdf_ntriples.pl +422 -0
  387. package/lib/swipl/library/ext/semweb/semweb/rdf_persistency.pl +1576 -0
  388. package/lib/swipl/library/ext/semweb/semweb/rdf_portray.pl +182 -0
  389. package/lib/swipl/library/ext/semweb/semweb/rdf_prefixes.pl +681 -0
  390. package/lib/swipl/library/ext/semweb/semweb/rdf_sandbox.pl +153 -0
  391. package/lib/swipl/library/ext/semweb/semweb/rdf_turtle.pl +54 -0
  392. package/lib/swipl/library/ext/semweb/semweb/rdf_turtle_write.pl +1587 -0
  393. package/lib/swipl/library/ext/semweb/semweb/rdf_zlib_plugin.pl +52 -0
  394. package/lib/swipl/library/ext/semweb/semweb/rdfa.pl +1510 -0
  395. package/lib/swipl/library/ext/semweb/semweb/rdfs.pl +475 -0
  396. package/lib/swipl/library/ext/semweb/semweb/sparql_client.pl +643 -0
  397. package/lib/swipl/library/ext/semweb/semweb/turtle.pl +455 -0
  398. package/lib/swipl/library/ext/sgml/DTD/HTML4.dcl +88 -0
  399. package/lib/swipl/library/ext/sgml/DTD/HTML4.dtd +1092 -0
  400. package/lib/swipl/library/ext/sgml/DTD/HTML4.soc +6 -0
  401. package/lib/swipl/library/ext/sgml/DTD/HTML5.dtd +906 -0
  402. package/lib/swipl/library/ext/sgml/DTD/HTMLlat1.ent +195 -0
  403. package/lib/swipl/library/ext/sgml/DTD/HTMLspec.ent +77 -0
  404. package/lib/swipl/library/ext/sgml/DTD/HTMLsym.ent +241 -0
  405. package/lib/swipl/library/ext/sgml/INDEX.pl +64 -0
  406. package/lib/swipl/library/ext/sgml/c14n2.pl +203 -0
  407. package/lib/swipl/library/ext/sgml/iso_639.pl +631 -0
  408. package/lib/swipl/library/ext/sgml/pwp.pl +705 -0
  409. package/lib/swipl/library/ext/sgml/sgml.pl +815 -0
  410. package/lib/swipl/library/ext/sgml/sgml_write.pl +1003 -0
  411. package/lib/swipl/library/ext/sgml/xpath.pl +620 -0
  412. package/lib/swipl/library/ext/sgml/xsdp_types.pl +232 -0
  413. package/lib/swipl/library/ext/ssl/INDEX.pl +60 -0
  414. package/lib/swipl/library/ext/ssl/crypto.pl +1015 -0
  415. package/lib/swipl/library/ext/ssl/http/INDEX.pl +5 -0
  416. package/lib/swipl/library/ext/ssl/http/http_ssl_plugin.pl +296 -0
  417. package/lib/swipl/library/ext/ssl/saml.pl +609 -0
  418. package/lib/swipl/library/ext/ssl/ssl.pl +647 -0
  419. package/lib/swipl/library/ext/ssl/xmldsig.pl +391 -0
  420. package/lib/swipl/library/ext/ssl/xmlenc.pl +354 -0
  421. package/lib/swipl/library/ext/zlib/INDEX.pl +8 -0
  422. package/lib/swipl/library/ext/zlib/zlib.pl +112 -0
  423. package/lib/swipl/library/fastrw.pl +105 -0
  424. package/lib/swipl/library/files.pl +80 -0
  425. package/lib/swipl/library/gensym.pl +111 -0
  426. package/lib/swipl/library/git.pl +1027 -0
  427. package/lib/swipl/library/hashtable.pl +365 -0
  428. package/lib/swipl/library/heaps.pl +252 -0
  429. package/lib/swipl/library/hotfix.pl +239 -0
  430. package/lib/swipl/library/http/jquery.pl +103 -0
  431. package/lib/swipl/library/http/web/js/jquery-3.6.0.min.js +2 -0
  432. package/lib/swipl/library/increval.pl +217 -0
  433. package/lib/swipl/library/intercept.pl +263 -0
  434. package/lib/swipl/library/iostream.pl +237 -0
  435. package/lib/swipl/library/iri_scheme/file.pl +70 -0
  436. package/lib/swipl/library/lazy_lists.pl +481 -0
  437. package/lib/swipl/library/listing.pl +1362 -0
  438. package/lib/swipl/library/lists.pl +860 -0
  439. package/lib/swipl/library/lynx/INDEX.pl +14 -0
  440. package/lib/swipl/library/lynx/format.pl +380 -0
  441. package/lib/swipl/library/lynx/html_style.pl +129 -0
  442. package/lib/swipl/library/lynx/html_text.pl +865 -0
  443. package/lib/swipl/library/lynx/pldoc_style.pl +87 -0
  444. package/lib/swipl/library/macros.pl +451 -0
  445. package/lib/swipl/library/main.pl +1200 -0
  446. package/lib/swipl/library/make.pl +197 -0
  447. package/lib/swipl/library/modules.pl +129 -0
  448. package/lib/swipl/library/nb_rbtrees.pl +267 -0
  449. package/lib/swipl/library/nb_set.pl +203 -0
  450. package/lib/swipl/library/obfuscate.pl +115 -0
  451. package/lib/swipl/library/occurs.pl +241 -0
  452. package/lib/swipl/library/operators.pl +182 -0
  453. package/lib/swipl/library/option.pl +388 -0
  454. package/lib/swipl/library/optparse.pl +966 -0
  455. package/lib/swipl/library/ordsets.pl +518 -0
  456. package/lib/swipl/library/oset.pl +160 -0
  457. package/lib/swipl/library/pairs.pl +187 -0
  458. package/lib/swipl/library/persistency.pl +713 -0
  459. package/lib/swipl/library/pio.pl +47 -0
  460. package/lib/swipl/library/portray_text.pl +277 -0
  461. package/lib/swipl/library/pprint.pl +940 -0
  462. package/lib/swipl/library/predicate_options.pl +975 -0
  463. package/lib/swipl/library/prolog_autoload.pl +233 -0
  464. package/lib/swipl/library/prolog_breakpoints.pl +396 -0
  465. package/lib/swipl/library/prolog_clause.pl +1104 -0
  466. package/lib/swipl/library/prolog_code.pl +416 -0
  467. package/lib/swipl/library/prolog_codewalk.pl +1248 -0
  468. package/lib/swipl/library/prolog_colour.pl +3301 -0
  469. package/lib/swipl/library/prolog_colour.qlf +0 -0
  470. package/lib/swipl/library/prolog_config.pl +154 -0
  471. package/lib/swipl/library/prolog_coverage.pl +1333 -0
  472. package/lib/swipl/library/prolog_debug.pl +404 -0
  473. package/lib/swipl/library/prolog_deps.pl +675 -0
  474. package/lib/swipl/library/prolog_evaluable.pl +234 -0
  475. package/lib/swipl/library/prolog_format.pl +219 -0
  476. package/lib/swipl/library/prolog_history.pl +161 -0
  477. package/lib/swipl/library/prolog_jiti.pl +333 -0
  478. package/lib/swipl/library/prolog_locale.pl +61 -0
  479. package/lib/swipl/library/prolog_metainference.pl +307 -0
  480. package/lib/swipl/library/prolog_pack.pl +3906 -0
  481. package/lib/swipl/library/prolog_profile.pl +346 -0
  482. package/lib/swipl/library/prolog_qlfmake.pl +533 -0
  483. package/lib/swipl/library/prolog_source.pl +1188 -0
  484. package/lib/swipl/library/prolog_stack.pl +794 -0
  485. package/lib/swipl/library/prolog_trace.pl +365 -0
  486. package/lib/swipl/library/prolog_versions.pl +347 -0
  487. package/lib/swipl/library/prolog_wrap.pl +164 -0
  488. package/lib/swipl/library/prolog_xref.pl +3090 -0
  489. package/lib/swipl/library/prolog_xref.qlf +0 -0
  490. package/lib/swipl/library/pure_input.pl +266 -0
  491. package/lib/swipl/library/qpforeign.pl +695 -0
  492. package/lib/swipl/library/qsave.pl +1516 -0
  493. package/lib/swipl/library/quasi_quotations.pl +300 -0
  494. package/lib/swipl/library/quintus.pl +437 -0
  495. package/lib/swipl/library/random.pl +459 -0
  496. package/lib/swipl/library/rbtrees.pl +1153 -0
  497. package/lib/swipl/library/readln.pl +256 -0
  498. package/lib/swipl/library/readutil.pl +304 -0
  499. package/lib/swipl/library/record.pl +544 -0
  500. package/lib/swipl/library/rwlocks.pl +172 -0
  501. package/lib/swipl/library/sandbox.pl +1384 -0
  502. package/lib/swipl/library/semweb/dc.rdfs +198 -0
  503. package/lib/swipl/library/semweb/eor.rdfs +95 -0
  504. package/lib/swipl/library/semweb/owl.owl +287 -0
  505. package/lib/swipl/library/semweb/rdf_library.ttl +90 -0
  506. package/lib/swipl/library/semweb/rdfs.rdfs +251 -0
  507. package/lib/swipl/library/settings.pl +755 -0
  508. package/lib/swipl/library/shell.pl +462 -0
  509. package/lib/swipl/library/shlib.pl +670 -0
  510. package/lib/swipl/library/solution_sequences.pl +439 -0
  511. package/lib/swipl/library/sort.pl +119 -0
  512. package/lib/swipl/library/statistics.pl +541 -0
  513. package/lib/swipl/library/streams.pl +118 -0
  514. package/lib/swipl/library/strings.pl +469 -0
  515. package/lib/swipl/library/system.pl +95 -0
  516. package/lib/swipl/library/tables.pl +381 -0
  517. package/lib/swipl/library/tableutil.pl +771 -0
  518. package/lib/swipl/library/tabling.pl +42 -0
  519. package/lib/swipl/library/terms.pl +457 -0
  520. package/lib/swipl/library/theme/auto.pl +61 -0
  521. package/lib/swipl/library/theme/dark.pl +455 -0
  522. package/lib/swipl/library/theme/light.pl +45 -0
  523. package/lib/swipl/library/thread.pl +810 -0
  524. package/lib/swipl/library/thread_pool.pl +508 -0
  525. package/lib/swipl/library/threadutil.pl +574 -0
  526. package/lib/swipl/library/tty.pl +316 -0
  527. package/lib/swipl/library/ugraphs.pl +644 -0
  528. package/lib/swipl/library/unicode/INDEX.pl +6 -0
  529. package/lib/swipl/library/unicode/blocks.pl +414 -0
  530. package/lib/swipl/library/url.pl +1129 -0
  531. package/lib/swipl/library/utf8.pl +145 -0
  532. package/lib/swipl/library/varnumbers.pl +221 -0
  533. package/lib/swipl/library/vm.pl +251 -0
  534. package/lib/swipl/library/wfs.pl +205 -0
  535. package/lib/swipl/library/when.pl +263 -0
  536. package/lib/swipl/library/writef.pl +278 -0
  537. package/lib/swipl/library/www_browser.pl +251 -0
  538. package/lib/swipl/library/yall.pl +574 -0
  539. package/lib/swipl/library/zip.pl +211 -0
  540. package/lib/swipl/swipl.home +1 -0
  541. package/lib/vendor/libcrypto.so.3 +0 -0
  542. package/lib/vendor/libpcre2-8.so.0 +0 -0
  543. package/lib/vendor/libssl.so.3 +0 -0
  544. package/lib/vendor/libz.so.1 +0 -0
  545. package/licenses/OpenSSL-LICENSE.txt +177 -0
  546. package/licenses/PCRE2-COPYING +5 -0
  547. package/licenses/README.md +12 -0
  548. package/licenses/SWI-Prolog-LICENSE +41 -0
  549. package/licenses/zlib-LICENSE +22 -0
  550. package/package.json +27 -0
@@ -0,0 +1,2248 @@
1
+ /* Part of SWI-Prolog
2
+
3
+ Author: Jan Wielemaker
4
+ E-mail: J.Wielemaker@vu.nl
5
+ WWW: http://www.swi-prolog.org
6
+ Copyright (c) 1985-2026, University of Amsterdam
7
+ VU University Amsterdam
8
+ SWI-Prolog Solutions b.v.
9
+ All rights reserved.
10
+
11
+ Redistribution and use in source and binary forms, with or without
12
+ modification, are permitted provided that the following conditions
13
+ are met:
14
+
15
+ 1. Redistributions of source code must retain the above copyright
16
+ notice, this list of conditions and the following disclaimer.
17
+
18
+ 2. Redistributions in binary form must reproduce the above copyright
19
+ notice, this list of conditions and the following disclaimer in
20
+ the documentation and/or other materials provided with the
21
+ distribution.
22
+
23
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33
+ ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
+ POSSIBILITY OF SUCH DAMAGE.
35
+ */
36
+
37
+ :- module('$toplevel',
38
+ [ '$initialise'/0, % start Prolog
39
+ '$toplevel'/0, % Prolog top-level (re-entrant)
40
+ '$compile'/0, % `-c' toplevel
41
+ '$config'/0, % --dump-runtime-variables toplevel
42
+ initialize/0, % Run program initialization
43
+ version/0, % Write initial banner
44
+ version/1, % Add message to the banner
45
+ prolog/0, % user toplevel predicate
46
+ '$query_loop'/0, % toplevel predicate
47
+ '$execute_query'/3, % +Query, +Bindings, -Truth
48
+ residual_goals/1, % +Callable
49
+ (initialization)/1, % initialization goal (directive)
50
+ '$thread_init'/0, % initialise thread
51
+ (thread_initialization)/1 % thread initialization goal
52
+ ]).
53
+
54
+
55
+ /*******************************
56
+ * VERSION BANNER *
57
+ *******************************/
58
+
59
+ :- dynamic prolog:version_msg/1.
60
+ :- multifile prolog:version_msg/1.
61
+
62
+ %! version is det.
63
+ %
64
+ % Print the Prolog banner message and messages registered using
65
+ % version/1.
66
+
67
+ version :-
68
+ print_message(banner, welcome).
69
+
70
+ %! version(+Message) is det.
71
+ %
72
+ % Add message to version/0
73
+
74
+ :- multifile
75
+ system:term_expansion/2.
76
+
77
+ system:term_expansion((:- version(Message)),
78
+ prolog:version_msg(Message)).
79
+
80
+ version(Message) :-
81
+ ( prolog:version_msg(Message)
82
+ -> true
83
+ ; assertz(prolog:version_msg(Message))
84
+ ).
85
+
86
+
87
+ /********************************
88
+ * INITIALISATION *
89
+ *********************************/
90
+
91
+ %! load_init_file(+ScriptMode) is det.
92
+ %
93
+ % Load the user customization file. This can be done using ``swipl -f
94
+ % file`` or simply using ``swipl``. In the first case we search the
95
+ % file both directly and over the alias `user_app_config`. In the
96
+ % latter case we only use the alias.
97
+
98
+ load_init_file(_) :-
99
+ '$cmd_option_val'(init_file, OsFile),
100
+ !,
101
+ prolog_to_os_filename(File, OsFile),
102
+ load_init_file(File, explicit).
103
+ load_init_file(prolog) :-
104
+ !,
105
+ load_init_file('init.pl', implicit).
106
+ load_init_file(none) :-
107
+ !,
108
+ load_init_file('init.pl', implicit).
109
+ load_init_file(_).
110
+
111
+ %! loaded_init_file(?Base, ?AbsFile)
112
+ %
113
+ % Used by prolog_load_context/2 to confirm we are loading a script.
114
+
115
+ :- dynamic
116
+ loaded_init_file/2. % already loaded init files
117
+
118
+ load_init_file(none, _) :- !.
119
+ load_init_file(Base, _) :-
120
+ loaded_init_file(Base, _),
121
+ !.
122
+ load_init_file(InitFile, explicit) :-
123
+ exists_file(InitFile),
124
+ !,
125
+ ensure_loaded(user:InitFile).
126
+ load_init_file(Base, _) :-
127
+ absolute_file_name(user_app_config(Base), InitFile,
128
+ [ access(read),
129
+ file_errors(fail)
130
+ ]),
131
+ !,
132
+ asserta(loaded_init_file(Base, InitFile)),
133
+ load_files(user:InitFile,
134
+ [ scope_settings(false)
135
+ ]).
136
+ load_init_file('init.pl', implicit) :-
137
+ ( current_prolog_flag(windows, true),
138
+ absolute_file_name(user_profile('swipl.ini'), InitFile,
139
+ [ access(read),
140
+ file_errors(fail)
141
+ ])
142
+ ; expand_file_name('~/.swiplrc', [InitFile]),
143
+ exists_file(InitFile)
144
+ ),
145
+ !,
146
+ print_message(warning, backcomp(init_file_moved(InitFile))).
147
+ load_init_file(_, _).
148
+
149
+ '$load_system_init_file' :-
150
+ loaded_init_file(system, _),
151
+ !.
152
+ '$load_system_init_file' :-
153
+ '$cmd_option_val'(system_init_file, Base),
154
+ Base \== none,
155
+ current_prolog_flag(home, Home),
156
+ file_name_extension(Base, rc, Name),
157
+ atomic_list_concat([Home, '/', Name], File),
158
+ absolute_file_name(File, Path,
159
+ [ file_type(prolog),
160
+ access(read),
161
+ file_errors(fail)
162
+ ]),
163
+ asserta(loaded_init_file(system, Path)),
164
+ load_files(user:Path,
165
+ [ silent(true),
166
+ scope_settings(false)
167
+ ]),
168
+ !.
169
+ '$load_system_init_file'.
170
+
171
+ '$load_script_file' :-
172
+ loaded_init_file(script, _),
173
+ !.
174
+ '$load_script_file' :-
175
+ '$cmd_option_val'(script_file, OsFiles),
176
+ load_script_files(OsFiles).
177
+
178
+ load_script_files([]).
179
+ load_script_files([OsFile|More]) :-
180
+ prolog_to_os_filename(File, OsFile),
181
+ ( absolute_file_name(File, Path,
182
+ [ file_type(prolog),
183
+ access(read),
184
+ file_errors(fail)
185
+ ])
186
+ -> asserta(loaded_init_file(script, Path)),
187
+ load_files(user:Path),
188
+ load_files(user:More)
189
+ ; throw(error(existence_error(script_file, File), _))
190
+ ).
191
+
192
+
193
+ /*******************************
194
+ * AT_INITIALISATION *
195
+ *******************************/
196
+
197
+ :- meta_predicate
198
+ initialization(0).
199
+
200
+ :- '$iso'((initialization)/1).
201
+
202
+ %! initialization(:Goal)
203
+ %
204
+ % Runs Goal after loading the file in which this directive
205
+ % appears as well as after restoring a saved state.
206
+ %
207
+ % @see initialization/2
208
+
209
+ initialization(Goal) :-
210
+ Goal = _:G,
211
+ prolog:initialize_now(G, Use),
212
+ !,
213
+ print_message(warning, initialize_now(G, Use)),
214
+ initialization(Goal, now).
215
+ initialization(Goal) :-
216
+ initialization(Goal, after_load).
217
+
218
+ :- multifile
219
+ prolog:initialize_now/2,
220
+ prolog:message//1.
221
+
222
+ prolog:initialize_now(load_foreign_library(_),
223
+ 'use :- use_foreign_library/1 instead').
224
+ prolog:initialize_now(load_foreign_library(_,_),
225
+ 'use :- use_foreign_library/2 instead').
226
+
227
+ prolog:message(initialize_now(Goal, Use)) -->
228
+ [ 'Initialization goal ~p will be executed'-[Goal],nl,
229
+ 'immediately for backward compatibility reasons', nl,
230
+ '~w'-[Use]
231
+ ].
232
+
233
+ '$run_initialization' :-
234
+ '$set_prolog_file_extension',
235
+ '$run_initialization'(_, []),
236
+ '$thread_init'.
237
+
238
+ %! initialize
239
+ %
240
+ % Run goals registered with `:- initialization(Goal, program).`. Stop
241
+ % with an exception if a goal fails or raises an exception.
242
+
243
+ initialize :-
244
+ forall('$init_goal'(when(program), Goal, Ctx),
245
+ run_initialize(Goal, Ctx)).
246
+
247
+ run_initialize(Goal, Ctx) :-
248
+ ( catch(Goal, E, true),
249
+ ( var(E)
250
+ -> true
251
+ ; throw(error(initialization_error(E, Goal, Ctx), _))
252
+ )
253
+ ; throw(error(initialization_error(failed, Goal, Ctx), _))
254
+ ).
255
+
256
+
257
+ /*******************************
258
+ * THREAD INITIALIZATION *
259
+ *******************************/
260
+
261
+ :- meta_predicate
262
+ thread_initialization(0).
263
+ :- dynamic
264
+ '$at_thread_initialization'/1.
265
+
266
+ %! thread_initialization(:Goal)
267
+ %
268
+ % Run Goal now and everytime a new thread is created.
269
+
270
+ thread_initialization(Goal) :-
271
+ assert('$at_thread_initialization'(Goal)),
272
+ call(Goal),
273
+ !.
274
+
275
+ %! '$thread_init'
276
+ %
277
+ % Called by start_thread() from pl-thread.c before the thread's goal.
278
+
279
+ '$thread_init' :-
280
+ set_prolog_flag(toplevel_thread, false),
281
+ ( '$at_thread_initialization'(Goal),
282
+ ( call(Goal)
283
+ -> fail
284
+ ; fail
285
+ )
286
+ ; true
287
+ ).
288
+
289
+
290
+ /*******************************
291
+ * FILE SEARCH PATH (-p) *
292
+ *******************************/
293
+
294
+ %! '$set_file_search_paths' is det.
295
+ %
296
+ % Process -p PathSpec options.
297
+
298
+ '$set_file_search_paths' :-
299
+ '$cmd_option_val'(search_paths, Paths),
300
+ ( '$member'(Path, Paths),
301
+ atom_chars(Path, Chars),
302
+ ( phrase('$search_path'(Name, Aliases), Chars)
303
+ -> '$reverse'(Aliases, Aliases1),
304
+ forall('$member'(Alias, Aliases1),
305
+ asserta(user:file_search_path(Name, Alias)))
306
+ ; print_message(error, commandline_arg_type(p, Path))
307
+ ),
308
+ fail ; true
309
+ ).
310
+
311
+ '$search_path'(Name, Aliases) -->
312
+ '$string'(NameChars),
313
+ [=],
314
+ !,
315
+ {atom_chars(Name, NameChars)},
316
+ '$search_aliases'(Aliases).
317
+
318
+ '$search_aliases'([Alias|More]) -->
319
+ '$string'(AliasChars),
320
+ path_sep,
321
+ !,
322
+ { '$make_alias'(AliasChars, Alias) },
323
+ '$search_aliases'(More).
324
+ '$search_aliases'([Alias]) -->
325
+ '$string'(AliasChars),
326
+ '$eos',
327
+ !,
328
+ { '$make_alias'(AliasChars, Alias) }.
329
+
330
+ path_sep -->
331
+ { current_prolog_flag(path_sep, Sep) },
332
+ [Sep].
333
+
334
+ '$string'([]) --> [].
335
+ '$string'([H|T]) --> [H], '$string'(T).
336
+
337
+ '$eos'([], []).
338
+
339
+ '$make_alias'(Chars, Alias) :-
340
+ catch(term_to_atom(Alias, Chars), _, fail),
341
+ ( atom(Alias)
342
+ ; functor(Alias, F, 1),
343
+ F \== /
344
+ ),
345
+ !.
346
+ '$make_alias'(Chars, Alias) :-
347
+ atom_chars(Alias, Chars).
348
+
349
+
350
+ /*******************************
351
+ * LOADING ASSIOCIATED FILES *
352
+ *******************************/
353
+
354
+ %! argv_prolog_files(-Files, -ScriptMode) is det.
355
+ %
356
+ % Update the Prolog flag `argv`, extracting the leading script files.
357
+ % This is called after the C based parser removed Prolog options such
358
+ % as ``-q``, ``-f none``, etc. These options are available through
359
+ % '$cmd_option_val'/2.
360
+ %
361
+ % Our task is to update the Prolog flag `argv` and return a list of
362
+ % the files to be loaded. The rules are:
363
+ %
364
+ % - If we find ``--`` all remaining options must go to `argv`
365
+ % - If we find *.pl files, these are added to Files and possibly
366
+ % remaining arguments are "script" arguments.
367
+ % - If we find an existing file, this is Files and possibly
368
+ % remaining arguments are "script" arguments.
369
+ % - File we find [search:]name, find search(name) as Prolog file,
370
+ % make this the content of `Files` and pass the remainder as
371
+ % options to `argv`.
372
+ %
373
+ % @arg ScriptMode is one of
374
+ %
375
+ % - exe
376
+ % Program is a saved state
377
+ % - prolog
378
+ % One or more *.pl files on commandline
379
+ % - script
380
+ % Single existing file on commandline
381
+ % - app
382
+ % [path:]cli-name on commandline
383
+ % - none
384
+ % Normal interactive session
385
+
386
+ argv_prolog_files([], exe) :-
387
+ current_prolog_flag(saved_program_class, runtime),
388
+ !,
389
+ clean_argv.
390
+ argv_prolog_files(Files, ScriptMode) :-
391
+ current_prolog_flag(argv, Argv),
392
+ no_option_files(Argv, Argv1, Files, ScriptMode),
393
+ ( ( nonvar(ScriptMode)
394
+ ; Argv1 == []
395
+ )
396
+ -> ( Argv1 \== Argv
397
+ -> set_prolog_flag(argv, Argv1)
398
+ ; true
399
+ )
400
+ ; '$usage',
401
+ halt(1)
402
+ ).
403
+
404
+ no_option_files([--|Argv], Argv, [], ScriptMode) :-
405
+ !,
406
+ ( ScriptMode = none
407
+ -> true
408
+ ; true
409
+ ).
410
+ no_option_files([Opt|_], _, _, ScriptMode) :-
411
+ var(ScriptMode),
412
+ sub_atom(Opt, 0, _, _, '-'),
413
+ !,
414
+ '$usage',
415
+ halt(1).
416
+ no_option_files([OsFile|Argv0], Argv, [File|T], ScriptMode) :-
417
+ file_name_extension(_, Ext, OsFile),
418
+ user:prolog_file_type(Ext, prolog),
419
+ !,
420
+ ScriptMode = prolog,
421
+ prolog_to_os_filename(File, OsFile),
422
+ no_option_files(Argv0, Argv, T, ScriptMode).
423
+ no_option_files([OsScript|Argv], Argv, [Script], ScriptMode) :-
424
+ var(ScriptMode),
425
+ !,
426
+ prolog_to_os_filename(PlScript, OsScript),
427
+ ( exists_file(PlScript)
428
+ -> Script = PlScript,
429
+ ScriptMode = script
430
+ ; cli_script(OsScript, Script)
431
+ -> ScriptMode = app,
432
+ set_prolog_flag(app_name, OsScript)
433
+ ; '$existence_error'(file, PlScript)
434
+ ).
435
+ no_option_files(Argv, Argv, [], ScriptMode) :-
436
+ ( ScriptMode = none
437
+ -> true
438
+ ; true
439
+ ).
440
+
441
+ cli_script(CLI, Script) :-
442
+ ( sub_atom(CLI, Pre, _, Post, ':')
443
+ -> sub_atom(CLI, 0, Pre, _, SearchPath),
444
+ sub_atom(CLI, _, Post, 0, Base),
445
+ Spec =.. [SearchPath, Base]
446
+ ; Spec = app(CLI)
447
+ ),
448
+ absolute_file_name(Spec, Script,
449
+ [ file_type(prolog),
450
+ access(exist),
451
+ file_errors(fail)
452
+ ]).
453
+
454
+ clean_argv :-
455
+ ( current_prolog_flag(argv, [--|Argv])
456
+ -> set_prolog_flag(argv, Argv)
457
+ ; true
458
+ ).
459
+
460
+ %! win_associated_files(+Files)
461
+ %
462
+ % If SWI-Prolog is started as <exe> <file>.<ext>, where <ext> is
463
+ % the extension registered for associated files, set the Prolog
464
+ % flag associated_file, switch to the directory holding the file
465
+ % and -if possible- adjust the window title.
466
+
467
+ win_associated_files(Files) :-
468
+ ( Files = [File|_]
469
+ -> absolute_file_name(File, AbsFile),
470
+ set_prolog_flag(associated_file, AbsFile),
471
+ forall(prolog:set_app_file_config(Files), true)
472
+ ; true
473
+ ).
474
+
475
+ :- multifile
476
+ prolog:set_app_file_config/1. % +Files
477
+
478
+ %! start_pldoc
479
+ %
480
+ % If the option ``--pldoc[=port]`` is given, load the PlDoc system.
481
+
482
+ start_pldoc :-
483
+ '$cmd_option_val'(pldoc_server, Server),
484
+ ( Server == ''
485
+ -> call((doc_server(_), doc_browser))
486
+ ; catch(atom_number(Server, Port), _, fail)
487
+ -> call(doc_server(Port))
488
+ ; print_message(error, option_usage(pldoc)),
489
+ halt(1)
490
+ ).
491
+ start_pldoc.
492
+
493
+
494
+ %! load_associated_files(+Files)
495
+ %
496
+ % Load Prolog files specified from the commandline.
497
+
498
+ load_associated_files(Files) :-
499
+ load_files(user:Files).
500
+
501
+ hkey('HKEY_CURRENT_USER/Software/SWI/Prolog').
502
+ hkey('HKEY_LOCAL_MACHINE/Software/SWI/Prolog').
503
+
504
+ '$set_prolog_file_extension' :-
505
+ current_prolog_flag(windows, true),
506
+ hkey(Key),
507
+ catch(win_registry_get_value(Key, fileExtension, Ext0),
508
+ _, fail),
509
+ !,
510
+ ( atom_concat('.', Ext, Ext0)
511
+ -> true
512
+ ; Ext = Ext0
513
+ ),
514
+ ( user:prolog_file_type(Ext, prolog)
515
+ -> true
516
+ ; asserta(user:prolog_file_type(Ext, prolog))
517
+ ).
518
+ '$set_prolog_file_extension'.
519
+
520
+
521
+ /********************************
522
+ * TOPLEVEL GOALS *
523
+ *********************************/
524
+
525
+ %! '$initialise' is semidet.
526
+ %
527
+ % Called from PL_initialise() to do the Prolog part of the
528
+ % initialization. If an exception occurs, this is printed and
529
+ % '$initialise' fails.
530
+
531
+ '$initialise' :-
532
+ catch(initialise_prolog, E, initialise_error(E)).
533
+
534
+ initialise_error(unwind(abort)) :- !.
535
+ initialise_error(unwind(halt(_))) :- !.
536
+ initialise_error(E) :-
537
+ print_message(error, initialization_exception(E)),
538
+ fail.
539
+
540
+ initialise_prolog :-
541
+ apply_defines,
542
+ init_optimise,
543
+ '$run_initialization',
544
+ '$load_system_init_file', % -F file
545
+ set_toplevel, % set `toplevel_goal` flag from -t
546
+ '$set_file_search_paths', % handle -p alias=dir[:dir]*
547
+ init_debug_flags,
548
+ setup_app,
549
+ start_pldoc, % handle --pldoc[=port]
550
+ main_thread_init.
551
+
552
+ %! main_thread_init
553
+ %
554
+ % Deal with the _Epilog_ toplevel. If the flag `epilog` is set and
555
+ % xpce is around, create an epilog window and complete the user part
556
+ % of the initialization in the epilog thread.
557
+
558
+ :- if(current_prolog_flag(threads, true)).
559
+ main_thread_init :-
560
+ current_prolog_flag(epilog, true),
561
+ thread_self(main),
562
+ current_prolog_flag(xpce, true),
563
+ exists_source(library(epilog)),
564
+ !,
565
+ setup_theme,
566
+ catch(setup_backtrace, E, print_message(warning, E)),
567
+ use_module(library(epilog)),
568
+ set_thread(main, class(system)),
569
+ call(epilog([ init(user_thread_init),
570
+ main(true)
571
+ ])).
572
+ main_thread_init :-
573
+ set_thread(main, class(console)),
574
+ setup_theme,
575
+ user_thread_init.
576
+ :- else.
577
+ main_thread_init :-
578
+ setup_theme,
579
+ user_thread_init.
580
+ :- endif.
581
+
582
+
583
+ %! user_thread_init
584
+ %
585
+ % Complete the toplevel startup. This may run in a separate thread.
586
+
587
+ user_thread_init :-
588
+ opt_attach_packs,
589
+ argv_prolog_files(Files, ScriptMode),
590
+ load_init_file(ScriptMode), % -f file
591
+ catch(setup_colors, E, print_message(warning, E)),
592
+ win_associated_files(Files), % swipl-win: cd and update title
593
+ '$load_script_file', % -s file (may be repeated)
594
+ load_associated_files(Files),
595
+ '$cmd_option_val'(goals, Goals), % -g goal (may be repeated)
596
+ ( ScriptMode == app
597
+ -> run_program_init, % initialization(Goal, program)
598
+ run_main_init(true)
599
+ ; Goals == [],
600
+ \+ '$init_goal'(when(_), _, _) % no -g or -t or initialization(program)
601
+ -> version % default interactive run
602
+ ; run_init_goals(Goals), % run -g goals
603
+ ( load_only % used -l to load
604
+ -> version
605
+ ; run_program_init, % initialization(Goal, program)
606
+ run_main_init(false) % initialization(Goal, main)
607
+ )
608
+ ).
609
+
610
+ %! setup_theme
611
+
612
+ :- multifile
613
+ prolog:theme/1.
614
+
615
+ setup_theme :-
616
+ current_prolog_flag(theme, Theme),
617
+ exists_source(library(theme/Theme)),
618
+ !,
619
+ use_module(library(theme/Theme)).
620
+ setup_theme.
621
+
622
+ %! apply_defines
623
+ %
624
+ % Handle -Dflag[=value] options
625
+
626
+ apply_defines :-
627
+ '$cmd_option_val'(defines, Defs),
628
+ apply_defines(Defs).
629
+
630
+ apply_defines([]).
631
+ apply_defines([H|T]) :-
632
+ apply_define(H),
633
+ apply_defines(T).
634
+
635
+ apply_define(Def) :-
636
+ sub_atom(Def, B, _, A, '='),
637
+ !,
638
+ sub_atom(Def, 0, B, _, Flag),
639
+ sub_atom(Def, _, A, 0, Value0),
640
+ ( '$current_prolog_flag'(Flag, Value0, _Scope, Access, Type)
641
+ -> ( Access \== write
642
+ -> '$permission_error'(set, prolog_flag, Flag)
643
+ ; text_flag_value(Type, Value0, Value)
644
+ ),
645
+ set_prolog_flag(Flag, Value)
646
+ ; ( atom_number(Value0, Value)
647
+ -> true
648
+ ; Value = Value0
649
+ ),
650
+ set_defined(Flag, Value)
651
+ ).
652
+ apply_define(Def) :-
653
+ atom_concat('no-', Flag, Def),
654
+ !,
655
+ set_user_boolean_flag(Flag, false).
656
+ apply_define(Def) :-
657
+ set_user_boolean_flag(Def, true).
658
+
659
+ set_user_boolean_flag(Flag, Value) :-
660
+ current_prolog_flag(Flag, Old),
661
+ !,
662
+ ( Old == Value
663
+ -> true
664
+ ; set_prolog_flag(Flag, Value)
665
+ ).
666
+ set_user_boolean_flag(Flag, Value) :-
667
+ set_defined(Flag, Value).
668
+
669
+ text_flag_value(integer, Text, Int) :-
670
+ atom_number(Text, Int),
671
+ !.
672
+ text_flag_value(float, Text, Float) :-
673
+ atom_number(Text, Float),
674
+ !.
675
+ text_flag_value(term, Text, Term) :-
676
+ term_string(Term, Text, []),
677
+ !.
678
+ text_flag_value(_, Value, Value).
679
+
680
+ set_defined(Flag, Value) :-
681
+ define_options(Flag, Options), !,
682
+ create_prolog_flag(Flag, Value, Options).
683
+
684
+ %! define_options(+Flag, -Options)
685
+ %
686
+ % Define the options with which to create Flag. This can be used for
687
+ % known flags to control -for example- their type.
688
+
689
+ define_options('SDL_VIDEODRIVER', []).
690
+ define_options(_, [warn_not_accessed(true)]).
691
+
692
+ %! init_optimise
693
+ %
694
+ % Load library(apply_macros) if ``-O`` is effective.
695
+
696
+ init_optimise :-
697
+ current_prolog_flag(optimise, true),
698
+ !,
699
+ use_module(user:library(apply_macros)).
700
+ init_optimise.
701
+
702
+ opt_attach_packs :-
703
+ current_prolog_flag(packs, true),
704
+ !,
705
+ attach_packs.
706
+ opt_attach_packs.
707
+
708
+ set_toplevel :-
709
+ '$cmd_option_val'(toplevel, TopLevelAtom),
710
+ catch(term_to_atom(TopLevel, TopLevelAtom), E,
711
+ (print_message(error, E),
712
+ halt(1))),
713
+ create_prolog_flag(toplevel_goal, TopLevel, [type(term)]).
714
+
715
+ load_only :-
716
+ current_prolog_flag(os_argv, OSArgv),
717
+ memberchk('-l', OSArgv),
718
+ current_prolog_flag(argv, Argv),
719
+ \+ memberchk('-l', Argv).
720
+
721
+ %! run_init_goals(+Goals) is det.
722
+ %
723
+ % Run registered initialization goals on order. If a goal fails,
724
+ % execution is halted.
725
+
726
+ run_init_goals([]).
727
+ run_init_goals([H|T]) :-
728
+ run_init_goal(H),
729
+ run_init_goals(T).
730
+
731
+ run_init_goal(Text) :-
732
+ catch(term_to_atom(Goal, Text), E,
733
+ ( print_message(error, init_goal_syntax(E, Text)),
734
+ halt(2)
735
+ )),
736
+ run_init_goal(Goal, Text).
737
+
738
+ %! run_program_init is det.
739
+ %
740
+ % Run goals registered using
741
+
742
+ run_program_init :-
743
+ forall('$init_goal'(when(program), Goal, Ctx),
744
+ run_init_goal(Goal, @(Goal,Ctx))).
745
+
746
+ run_main_init(_) :-
747
+ findall(Goal-Ctx, '$init_goal'(when(main), Goal, Ctx), Pairs),
748
+ '$last'(Pairs, Goal-Ctx),
749
+ !,
750
+ ( current_prolog_flag(toplevel_goal, default)
751
+ -> set_prolog_flag(toplevel_goal, halt)
752
+ ; true
753
+ ),
754
+ run_init_goal(Goal, @(Goal,Ctx)).
755
+ run_main_init(true) :-
756
+ '$existence_error'(initialization, main).
757
+ run_main_init(_).
758
+
759
+ run_init_goal(Goal, Ctx) :-
760
+ ( catch_with_backtrace(user:Goal, E, true)
761
+ -> ( var(E)
762
+ -> true
763
+ ; init_goal_failed(E, Ctx)
764
+ )
765
+ ; ( current_prolog_flag(verbose, silent)
766
+ -> Level = silent
767
+ ; Level = error
768
+ ),
769
+ print_message(Level, init_goal_failed(failed, Ctx)),
770
+ halt(1)
771
+ ).
772
+
773
+ init_goal_failed(E, Ctx) :-
774
+ print_message(error, init_goal_failed(E, Ctx)),
775
+ init_goal_failed(E).
776
+
777
+ init_goal_failed(_) :-
778
+ thread_self(main),
779
+ !,
780
+ halt(2).
781
+ init_goal_failed(_).
782
+
783
+ %! init_debug_flags is det.
784
+ %
785
+ % Initialize the various Prolog flags that control the debugger and
786
+ % toplevel.
787
+
788
+ init_debug_flags :-
789
+ Keep = [keep(true)],
790
+ create_prolog_flag(answer_write_options,
791
+ [ quoted(true), portray(true), max_depth(10),
792
+ spacing(next_argument)], Keep),
793
+ create_prolog_flag(prompt_alternatives_on, determinism, Keep),
794
+ create_prolog_flag(toplevel_extra_white_line, true, Keep),
795
+ create_prolog_flag(toplevel_print_factorized, false, Keep),
796
+ create_prolog_flag(print_write_options,
797
+ [ portray(true), quoted(true), numbervars(true) ],
798
+ Keep),
799
+ create_prolog_flag(toplevel_residue_vars, false, Keep),
800
+ create_prolog_flag(toplevel_list_wfs_residual_program, true, Keep),
801
+ '$set_debugger_write_options'(print).
802
+
803
+ %! setup_backtrace
804
+ %
805
+ % Initialise printing a backtrace.
806
+
807
+ setup_backtrace :-
808
+ ( \+ current_prolog_flag(backtrace, false),
809
+ load_setup_file(library(prolog_stack))
810
+ -> true
811
+ ; true
812
+ ).
813
+
814
+ %! setup_colors is det.
815
+ %
816
+ % Setup interactive usage by enabling colored output.
817
+
818
+ setup_colors :-
819
+ ( \+ current_prolog_flag(color_term, false),
820
+ stream_property(user_input, tty(true)),
821
+ stream_property(user_error, tty(true)),
822
+ stream_property(user_output, tty(true)),
823
+ \+ getenv('TERM', dumb),
824
+ load_setup_file(user:library(ansi_term))
825
+ -> true
826
+ ; true
827
+ ).
828
+
829
+ %! setup_history
830
+ %
831
+ % Enable per-directory persistent history.
832
+
833
+ setup_history :-
834
+ ( \+ current_prolog_flag(save_history, false),
835
+ stream_property(user_input, tty(true)),
836
+ \+ current_prolog_flag(readline, false),
837
+ load_setup_file(library(prolog_history))
838
+ -> prolog_history(enable)
839
+ ; true
840
+ ).
841
+
842
+ %! setup_readline
843
+ %
844
+ % Setup line editing.
845
+
846
+ setup_readline :-
847
+ ( stream_property(user_input, tty(true)),
848
+ current_prolog_flag(tty_control, true),
849
+ \+ getenv('TERM', dumb),
850
+ ( current_prolog_flag(readline, ReadLine)
851
+ -> true
852
+ ; ReadLine = true
853
+ ),
854
+ readline_library(ReadLine, Library),
855
+ ( load_setup_file(library(Library))
856
+ -> true
857
+ ; current_prolog_flag(epilog, true),
858
+ print_message(warning,
859
+ error(existence_error(library, library(Library)),
860
+ _)),
861
+ fail
862
+ )
863
+ -> set_prolog_flag(readline, Library)
864
+ ; set_prolog_flag(readline, false)
865
+ ).
866
+
867
+ readline_library(true, Library) :-
868
+ !,
869
+ preferred_readline(Library).
870
+ readline_library(false, _) :-
871
+ !,
872
+ fail.
873
+ readline_library(Library, Library).
874
+
875
+ preferred_readline(editline).
876
+
877
+ %! load_setup_file(+File) is semidet.
878
+ %
879
+ % Load a file and fail silently if the file does not exist.
880
+
881
+ load_setup_file(File) :-
882
+ catch(load_files(File,
883
+ [ silent(true),
884
+ if(not_loaded)
885
+ ]), error(_,_), fail).
886
+
887
+
888
+ %! setup_app is det.
889
+ %
890
+ % When running as an "app", behave as such. The behaviour depends on
891
+ % the platform.
892
+ %
893
+ % - Windows
894
+ % If Prolog is started using --win_app, try to change directory
895
+ % to <My Documents>\Prolog.
896
+
897
+ :- if(current_prolog_flag(windows,true)).
898
+
899
+ setup_app :-
900
+ current_prolog_flag(associated_file, _),
901
+ !.
902
+ setup_app :-
903
+ '$cmd_option_val'(win_app, true),
904
+ !,
905
+ catch(my_prolog, E, print_message(warning, E)).
906
+ setup_app.
907
+
908
+ my_prolog :-
909
+ win_folder(personal, MyDocs),
910
+ atom_concat(MyDocs, '/Prolog', PrologDir),
911
+ ( ensure_dir(PrologDir)
912
+ -> working_directory(_, PrologDir)
913
+ ; working_directory(_, MyDocs)
914
+ ).
915
+
916
+ ensure_dir(Dir) :-
917
+ exists_directory(Dir),
918
+ !.
919
+ ensure_dir(Dir) :-
920
+ catch(make_directory(Dir), E, (print_message(warning, E), fail)).
921
+
922
+ :- elif(current_prolog_flag(apple, true)).
923
+ use_app_settings(true). % Indicate we need app settings
924
+
925
+ setup_app :-
926
+ apple_set_locale,
927
+ current_prolog_flag(associated_file, _),
928
+ !.
929
+ setup_app :-
930
+ current_prolog_flag(bundle, true),
931
+ current_prolog_flag(executable, Exe),
932
+ file_base_name(Exe, 'SWI-Prolog'),
933
+ !,
934
+ setup_macos_app.
935
+ setup_app.
936
+
937
+ apple_set_locale :-
938
+ ( getenv('LC_CTYPE', 'UTF-8'),
939
+ apple_current_locale_identifier(LocaleID),
940
+ atom_concat(LocaleID, '.UTF-8', Locale),
941
+ catch(setlocale(ctype, _Old, Locale), _, fail)
942
+ -> setenv('LANG', Locale),
943
+ unsetenv('LC_CTYPE')
944
+ ; true
945
+ ).
946
+
947
+ setup_macos_app :-
948
+ restore_working_directory,
949
+ !.
950
+ setup_macos_app :-
951
+ expand_file_name('~/Prolog', [PrologDir]),
952
+ ( exists_directory(PrologDir)
953
+ -> true
954
+ ; catch(make_directory(PrologDir), MkDirError,
955
+ print_message(warning, MkDirError))
956
+ ),
957
+ catch(working_directory(_, PrologDir), CdError,
958
+ print_message(warning, CdError)),
959
+ !.
960
+ setup_macos_app.
961
+
962
+ :- elif(current_prolog_flag(emscripten, true)).
963
+ setup_app.
964
+ :- else.
965
+ use_app_settings(true). % Indicate we need app settings
966
+
967
+ % Other (Unix-like) platforms.
968
+ setup_app :-
969
+ running_as_app,
970
+ restore_working_directory,
971
+ !.
972
+ setup_app.
973
+
974
+ %! running_as_app is semidet.
975
+ %
976
+ % True if we were started from the dock.
977
+
978
+ running_as_app :-
979
+ % getenv('FLATPAK_SANDBOX_DIR', _),
980
+ current_prolog_flag(epilog, true),
981
+ stream_property(In, file_no(0)),
982
+ \+ stream_property(In, tty(true)),
983
+ !.
984
+
985
+ :- endif.
986
+
987
+
988
+ :- if((current_predicate(use_app_settings/1),
989
+ use_app_settings(true))).
990
+
991
+
992
+ /*******************************
993
+ * APP WORKING DIRECTORY *
994
+ *******************************/
995
+
996
+ save_working_directory :-
997
+ working_directory(WD, WD),
998
+ app_settings(Settings),
999
+ ( Settings.get(working_directory) == WD
1000
+ -> true
1001
+ ; app_save_settings(Settings.put(working_directory, WD))
1002
+ ).
1003
+
1004
+ restore_working_directory :-
1005
+ at_halt(save_working_directory),
1006
+ app_settings(Settings),
1007
+ WD = Settings.get(working_directory),
1008
+ catch(working_directory(_, WD), _, fail),
1009
+ !.
1010
+
1011
+ /*******************************
1012
+ * SETTINGS *
1013
+ *******************************/
1014
+
1015
+ %! app_settings(-Settings:dict) is det.
1016
+ %
1017
+ % Get a dict holding the persistent application settings.
1018
+
1019
+ app_settings(Settings) :-
1020
+ app_settings_file(File),
1021
+ access_file(File, read),
1022
+ catch(setup_call_cleanup(
1023
+ open(File, read, In, [encoding(utf8)]),
1024
+ read_term(In, Settings, []),
1025
+ close(In)),
1026
+ Error,
1027
+ (print_message(warning, Error), fail)),
1028
+ !.
1029
+ app_settings(#{}).
1030
+
1031
+ %! app_save_settings(+Settings:dict) is det.
1032
+ %
1033
+ % Save the given application settings dict.
1034
+
1035
+ app_save_settings(Settings) :-
1036
+ app_settings_file(File),
1037
+ catch(setup_call_cleanup(
1038
+ open(File, write, Out, [encoding(utf8)]),
1039
+ write_term(Out, Settings,
1040
+ [ quoted(true),
1041
+ module(system), % default operators
1042
+ fullstop(true),
1043
+ nl(true)
1044
+ ]),
1045
+ close(Out)),
1046
+ Error,
1047
+ (print_message(warning, Error), fail)).
1048
+
1049
+
1050
+ app_settings_file(File) :-
1051
+ absolute_file_name(user_app_config('app_settings.pl'), File,
1052
+ [ access(write),
1053
+ file_errors(fail)
1054
+ ]).
1055
+ :- endif.% app_settings
1056
+
1057
+ /*******************************
1058
+ * TOPLEVEL *
1059
+ *******************************/
1060
+
1061
+ :- '$hide'('$toplevel'/0). % avoid in the GUI stacktrace
1062
+
1063
+ %! '$toplevel'
1064
+ %
1065
+ % Called from PL_toplevel()
1066
+
1067
+ '$toplevel' :-
1068
+ '$runtoplevel',
1069
+ print_message(informational, halt).
1070
+
1071
+ %! '$runtoplevel'
1072
+ %
1073
+ % Actually run the toplevel. The values `default` and `prolog` both
1074
+ % start the interactive toplevel, where `prolog` implies the user gave
1075
+ % =|-t prolog|=.
1076
+ %
1077
+ % @see prolog/0 is the default interactive toplevel
1078
+
1079
+ '$runtoplevel' :-
1080
+ current_prolog_flag(toplevel_goal, TopLevel0),
1081
+ toplevel_goal(TopLevel0, TopLevel),
1082
+ user:TopLevel.
1083
+
1084
+ :- dynamic setup_done/0.
1085
+ :- volatile setup_done/0.
1086
+
1087
+ toplevel_goal(default, '$query_loop') :-
1088
+ !,
1089
+ setup_interactive.
1090
+ toplevel_goal(prolog, '$query_loop') :-
1091
+ !,
1092
+ setup_interactive.
1093
+ toplevel_goal(Goal, Goal).
1094
+
1095
+ setup_interactive :-
1096
+ setup_done,
1097
+ !.
1098
+ setup_interactive :-
1099
+ asserta(setup_done),
1100
+ catch(setup_backtrace, E, print_message(warning, E)),
1101
+ catch(setup_readline, E, print_message(warning, E)),
1102
+ catch(setup_history, E, print_message(warning, E)).
1103
+
1104
+ %! '$compile'
1105
+ %
1106
+ % Toplevel called when invoked with -c option.
1107
+
1108
+ '$compile' :-
1109
+ ( catch('$compile_', E, (print_message(error, E), halt(1)))
1110
+ -> true
1111
+ ; print_message(error, error(goal_failed('$compile'), _)),
1112
+ halt(1)
1113
+ ),
1114
+ halt. % set exit code
1115
+
1116
+ '$compile_' :-
1117
+ '$load_system_init_file',
1118
+ catch(setup_colors, _, true),
1119
+ '$set_file_search_paths',
1120
+ init_debug_flags,
1121
+ '$run_initialization',
1122
+ opt_attach_packs,
1123
+ use_module(library(qsave)),
1124
+ qsave:qsave_toplevel.
1125
+
1126
+ %! '$config'
1127
+ %
1128
+ % Toplevel when invoked with --dump-runtime-variables
1129
+
1130
+ '$config' :-
1131
+ '$load_system_init_file',
1132
+ '$set_file_search_paths',
1133
+ init_debug_flags,
1134
+ '$run_initialization',
1135
+ load_files(library(prolog_config)),
1136
+ ( catch(prolog_dump_runtime_variables, E,
1137
+ (print_message(error, E), halt(1)))
1138
+ -> true
1139
+ ; print_message(error, error(goal_failed(prolog_dump_runtime_variables),_))
1140
+ ).
1141
+
1142
+
1143
+ /********************************
1144
+ * USER INTERACTIVE LOOP *
1145
+ *********************************/
1146
+
1147
+ %! prolog:repl_loop_hook(+BeginEnd, +BreakLevel) is nondet.
1148
+ %
1149
+ % Multifile hook that allows acting on starting/stopping the
1150
+ % interactive REPL loop. Called as
1151
+ %
1152
+ % forall(prolog:repl_loop_hook(BeginEnd, BreakLevel), true)
1153
+ %
1154
+ % @arg BeginEnd is one of `begin` or `end`
1155
+ % @arg BreakLevel is 0 for the normal toplevel, -1 when
1156
+ % non-interactive and >0 for _break environments_.
1157
+
1158
+ :- multifile
1159
+ prolog:repl_loop_hook/2.
1160
+
1161
+ %! prolog
1162
+ %
1163
+ % Run the Prolog toplevel. This is now the same as break/0, which
1164
+ % pretends to be in a break-level if there is a parent
1165
+ % environment.
1166
+
1167
+ prolog :-
1168
+ break.
1169
+
1170
+ :- create_prolog_flag(toplevel_mode, backtracking, []).
1171
+
1172
+ %! '$query_loop'
1173
+ %
1174
+ % Run the normal Prolog query loop. Note that the query is not
1175
+ % protected by catch/3. Dealing with unhandled exceptions is done
1176
+ % by the C-function query_loop(). This ensures that unhandled
1177
+ % exceptions are really unhandled (in Prolog).
1178
+
1179
+ '$query_loop' :-
1180
+ break_level(BreakLev),
1181
+ setup_call_cleanup(
1182
+ notrace(call_repl_loop_hook(begin, BreakLev, IsToplevel)),
1183
+ '$query_loop'(BreakLev),
1184
+ notrace(call_repl_loop_hook(end, BreakLev, IsToplevel))).
1185
+
1186
+ call_repl_loop_hook(begin, BreakLev, IsToplevel) =>
1187
+ ( current_prolog_flag(toplevel_thread, IsToplevel)
1188
+ -> true
1189
+ ; IsToplevel = false
1190
+ ),
1191
+ set_prolog_flag(toplevel_thread, true),
1192
+ call_repl_loop_hook_(begin, BreakLev).
1193
+ call_repl_loop_hook(end, BreakLev, IsToplevel) =>
1194
+ set_prolog_flag(toplevel_thread, IsToplevel),
1195
+ call_repl_loop_hook_(end, BreakLev).
1196
+
1197
+ call_repl_loop_hook_(BeginEnd, BreakLev) :-
1198
+ forall(prolog:repl_loop_hook(BeginEnd, BreakLev), true).
1199
+
1200
+
1201
+ '$query_loop'(BreakLev) :-
1202
+ current_prolog_flag(toplevel_mode, recursive),
1203
+ !,
1204
+ read_expanded_query(BreakLev, Query, Bindings),
1205
+ ( Query == end_of_file
1206
+ -> print_message(query, query(eof))
1207
+ ; '$call_no_catch'('$execute_query'(Query, Bindings, _)),
1208
+ ( current_prolog_flag(toplevel_mode, recursive)
1209
+ -> '$query_loop'(BreakLev)
1210
+ ; '$switch_toplevel_mode'(backtracking),
1211
+ '$query_loop'(BreakLev) % Maybe throw('$switch_toplevel_mode')?
1212
+ )
1213
+ ).
1214
+ '$query_loop'(BreakLev) :-
1215
+ repeat,
1216
+ read_expanded_query(BreakLev, Query, Bindings),
1217
+ ( Query == end_of_file
1218
+ -> !, print_message(query, query(eof))
1219
+ ; '$execute_query'(Query, Bindings, _),
1220
+ ( current_prolog_flag(toplevel_mode, recursive)
1221
+ -> !,
1222
+ '$switch_toplevel_mode'(recursive),
1223
+ '$query_loop'(BreakLev)
1224
+ ; fail
1225
+ )
1226
+ ).
1227
+
1228
+ break_level(BreakLev) :-
1229
+ ( current_prolog_flag(break_level, BreakLev)
1230
+ -> true
1231
+ ; BreakLev = -1
1232
+ ).
1233
+
1234
+ read_expanded_query(BreakLev, ExpandedQuery, ExpandedBindings) :-
1235
+ '$current_typein_module'(TypeIn),
1236
+ ( stream_property(user_input, tty(true))
1237
+ -> '$system_prompt'(TypeIn, BreakLev, Prompt),
1238
+ prompt(Old, '| ')
1239
+ ; Prompt = '',
1240
+ prompt(Old, '')
1241
+ ),
1242
+ trim_stacks,
1243
+ trim_heap,
1244
+ repeat,
1245
+ ( catch(read_query(Prompt, Query, Bindings),
1246
+ error(io_error(_,_),_), fail)
1247
+ -> prompt(_, Old),
1248
+ catch(call_expand_query(Query, ExpandedQuery,
1249
+ Bindings, ExpandedBindings),
1250
+ Error,
1251
+ (print_message(error, Error), fail))
1252
+ ; set_prolog_flag(debug_on_error, false),
1253
+ thread_exit(io_error)
1254
+ ),
1255
+ !.
1256
+
1257
+
1258
+ %! read_query(+Prompt, -Goal, -Bindings) is det.
1259
+ %
1260
+ % Read the next query. The first clause deals with the case where
1261
+ % !-based history is enabled. The second is used if we have command
1262
+ % line editing.
1263
+
1264
+ :- multifile
1265
+ prolog:history/2.
1266
+
1267
+ :- if(current_prolog_flag(emscripten, true)).
1268
+ read_query(_Prompt, Goal, Bindings) :-
1269
+ '$can_yield',
1270
+ !,
1271
+ await(query, GoalString),
1272
+ term_string(Goal, GoalString, [variable_names(Bindings)]).
1273
+ :- endif.
1274
+ read_query(Prompt, Goal, Bindings) :-
1275
+ prolog:history(current_input, enabled),
1276
+ !,
1277
+ read_term_with_history(
1278
+ Goal,
1279
+ [ show(h),
1280
+ help('!h'),
1281
+ no_save([trace]),
1282
+ prompt(Prompt),
1283
+ variable_names(Bindings)
1284
+ ]).
1285
+ read_query(Prompt, Goal, Bindings) :-
1286
+ remove_history_prompt(Prompt, Prompt1),
1287
+ repeat, % over syntax errors
1288
+ prompt1(Prompt1),
1289
+ read_query_line(user_input, Line),
1290
+ '$current_typein_module'(TypeIn),
1291
+ catch(read_term_from_atom(Line, Goal,
1292
+ [ variable_names(Bindings),
1293
+ module(TypeIn)
1294
+ ]), E,
1295
+ ( print_message(error, E),
1296
+ fail
1297
+ )),
1298
+ !.
1299
+
1300
+ %! read_query_line(+Input, -Query:atom) is det.
1301
+ %
1302
+ % Read a query as an atom. If Query is '$silent'(Goal), execute `Goal`
1303
+ % in module `user` and read the next query. This supports injecting
1304
+ % goals in some GNU-Emacs modes.
1305
+
1306
+ read_query_line(Input, Line) :-
1307
+ stream_property(Input, error(true)),
1308
+ !,
1309
+ Line = end_of_file.
1310
+ read_query_line(Input, Line) :-
1311
+ catch(read_term_as_atom(Input, Line0), Error, true),
1312
+ save_debug_after_read,
1313
+ ( var(Error)
1314
+ -> ( catch(term_string(Goal, Line0), error(_,_), fail),
1315
+ Goal = '$silent'(SilentGoal)
1316
+ -> Error = error(_,_),
1317
+ catch_with_backtrace(ignore(SilentGoal), Error,
1318
+ print_message(error, Error)),
1319
+ read_query_line(Input, Line)
1320
+ ; Line = Line0
1321
+ )
1322
+ ; catch(print_message(error, Error), _, true),
1323
+ ( Error = error(syntax_error(_),_)
1324
+ -> fail
1325
+ ; throw(Error)
1326
+ )
1327
+ ).
1328
+
1329
+ %! read_term_as_atom(+Input, -Line)
1330
+ %
1331
+ % Read the next term as an atom and skip to the newline or a
1332
+ % non-space character.
1333
+
1334
+ read_term_as_atom(In, Line) :-
1335
+ '$raw_read'(In, Line),
1336
+ ( Line == end_of_file
1337
+ -> true
1338
+ ; skip_to_nl(In)
1339
+ ).
1340
+
1341
+ %! skip_to_nl(+Input) is det.
1342
+ %
1343
+ % Read input after the term. Skips white space and %... comment
1344
+ % until the end of the line or a non-blank character.
1345
+
1346
+ skip_to_nl(In) :-
1347
+ repeat,
1348
+ peek_char(In, C),
1349
+ ( C == '%'
1350
+ -> skip(In, '\n')
1351
+ ; char_type(C, space)
1352
+ -> get_char(In, _),
1353
+ C == '\n'
1354
+ ; true
1355
+ ),
1356
+ !.
1357
+
1358
+ remove_history_prompt('', '') :- !.
1359
+ remove_history_prompt(Prompt0, Prompt) :-
1360
+ atom_chars(Prompt0, Chars0),
1361
+ clean_history_prompt_chars(Chars0, Chars1),
1362
+ delete_leading_blanks(Chars1, Chars),
1363
+ atom_chars(Prompt, Chars).
1364
+
1365
+ clean_history_prompt_chars([], []).
1366
+ clean_history_prompt_chars(['~', !|T], T) :- !.
1367
+ clean_history_prompt_chars([H|T0], [H|T]) :-
1368
+ clean_history_prompt_chars(T0, T).
1369
+
1370
+ delete_leading_blanks([' '|T0], T) :-
1371
+ !,
1372
+ delete_leading_blanks(T0, T).
1373
+ delete_leading_blanks(L, L).
1374
+
1375
+
1376
+ /*******************************
1377
+ * TOPLEVEL DEBUG *
1378
+ *******************************/
1379
+
1380
+ %! save_debug_after_read
1381
+ %
1382
+ % Called right after the toplevel read to save the debug status if
1383
+ % it was modified from the GUI thread using e.g.
1384
+ %
1385
+ % ==
1386
+ % thread_signal(main, gdebug)
1387
+ % ==
1388
+ %
1389
+ % @bug Ideally, the prompt would change if debug mode is enabled.
1390
+ % That is hard to realise with all the different console
1391
+ % interfaces supported by SWI-Prolog.
1392
+
1393
+ save_debug_after_read :-
1394
+ current_prolog_flag(debug, true),
1395
+ !,
1396
+ save_debug.
1397
+ save_debug_after_read.
1398
+
1399
+ save_debug :-
1400
+ ( tracing,
1401
+ notrace
1402
+ -> Tracing = true
1403
+ ; Tracing = false
1404
+ ),
1405
+ current_prolog_flag(debug, Debugging),
1406
+ set_prolog_flag(debug, false),
1407
+ create_prolog_flag(query_debug_settings,
1408
+ debug(Debugging, Tracing), []).
1409
+
1410
+ restore_debug :-
1411
+ current_prolog_flag(query_debug_settings, debug(Debugging, Tracing)),
1412
+ set_prolog_flag(debug, Debugging),
1413
+ ( Tracing == true
1414
+ -> trace
1415
+ ; true
1416
+ ).
1417
+
1418
+ :- initialization
1419
+ create_prolog_flag(query_debug_settings, debug(false, false), []).
1420
+
1421
+
1422
+ /********************************
1423
+ * PROMPTING *
1424
+ ********************************/
1425
+
1426
+ '$system_prompt'(Module, BrekLev, Prompt) :-
1427
+ current_prolog_flag(toplevel_prompt, PAtom),
1428
+ atom_codes(PAtom, P0),
1429
+ ( Module \== user
1430
+ -> '$substitute'('~m', [Module, ': '], P0, P1)
1431
+ ; '$substitute'('~m', [], P0, P1)
1432
+ ),
1433
+ ( BrekLev > 0
1434
+ -> '$substitute'('~l', ['[', BrekLev, '] '], P1, P2)
1435
+ ; '$substitute'('~l', [], P1, P2)
1436
+ ),
1437
+ current_prolog_flag(query_debug_settings, debug(Debugging, Tracing)),
1438
+ ( Tracing == true
1439
+ -> '$substitute'('~d', ['[trace] '], P2, P3)
1440
+ ; Debugging == true
1441
+ -> '$substitute'('~d', ['[debug] '], P2, P3)
1442
+ ; '$substitute'('~d', [], P2, P3)
1443
+ ),
1444
+ atom_chars(Prompt, P3).
1445
+
1446
+ '$substitute'(From, T, Old, New) :-
1447
+ atom_codes(From, FromCodes),
1448
+ phrase(subst_chars(T), T0),
1449
+ '$append'(Pre, S0, Old),
1450
+ '$append'(FromCodes, Post, S0) ->
1451
+ '$append'(Pre, T0, S1),
1452
+ '$append'(S1, Post, New),
1453
+ !.
1454
+ '$substitute'(_, _, Old, Old).
1455
+
1456
+ subst_chars([]) -->
1457
+ [].
1458
+ subst_chars([H|T]) -->
1459
+ { atomic(H),
1460
+ !,
1461
+ atom_codes(H, Codes)
1462
+ },
1463
+ Codes,
1464
+ subst_chars(T).
1465
+ subst_chars([H|T]) -->
1466
+ H,
1467
+ subst_chars(T).
1468
+
1469
+
1470
+ /********************************
1471
+ * EXECUTION *
1472
+ ********************************/
1473
+
1474
+ %! '$execute_query'(Goal, Bindings, -Truth) is det.
1475
+ %
1476
+ % Execute Goal using Bindings.
1477
+
1478
+ '$execute_query'(Var, _, true) :-
1479
+ var(Var),
1480
+ !,
1481
+ print_message(informational, var_query(Var)).
1482
+ '$execute_query'(Goal, Bindings, Truth) :-
1483
+ '$current_typein_module'(TypeIn),
1484
+ '$dwim_correct_goal'(TypeIn:Goal, Bindings, Corrected),
1485
+ !,
1486
+ setup_call_cleanup(
1487
+ '$set_source_module'(M0, TypeIn),
1488
+ expand_goal(Corrected, Expanded),
1489
+ '$set_source_module'(M0)),
1490
+ print_message(silent, toplevel_goal(Expanded, Bindings)),
1491
+ '$execute_goal2'(Expanded, Bindings, Truth).
1492
+ '$execute_query'(_, _, false) :-
1493
+ notrace,
1494
+ print_message(query, query(no)).
1495
+
1496
+ '$execute_goal2'(Goal, Bindings, true) :-
1497
+ restore_debug,
1498
+ '$current_typein_module'(TypeIn),
1499
+ residue_vars(TypeIn:Goal, Vars, TypeIn:Delays, Chp),
1500
+ deterministic(Det),
1501
+ ( save_debug
1502
+ ; restore_debug, fail
1503
+ ),
1504
+ flush_output(user_output),
1505
+ ( Det == true
1506
+ -> DetOrChp = true
1507
+ ; DetOrChp = Chp
1508
+ ),
1509
+ call_expand_answer(Goal, Bindings, NewBindings),
1510
+ ( \+ \+ write_bindings(NewBindings, Vars, Delays, DetOrChp)
1511
+ -> !
1512
+ ).
1513
+ '$execute_goal2'(_, _, false) :-
1514
+ save_debug,
1515
+ print_message(query, query(no)).
1516
+
1517
+ residue_vars(Goal, Vars, Delays, Chp) :-
1518
+ current_prolog_flag(toplevel_residue_vars, true),
1519
+ !,
1520
+ '$wfs_call'(call_residue_vars(stop_backtrace(Goal, Chp), Vars), Delays).
1521
+ residue_vars(Goal, [], Delays, Chp) :-
1522
+ '$wfs_call'(stop_backtrace(Goal, Chp), Delays).
1523
+
1524
+ stop_backtrace(Goal, Chp) :-
1525
+ toplevel_call(Goal),
1526
+ prolog_current_choice(Chp).
1527
+
1528
+ toplevel_call(Goal) :-
1529
+ call(Goal),
1530
+ no_lco.
1531
+
1532
+ no_lco.
1533
+
1534
+ %! write_bindings(+Bindings, +ResidueVars, +Delays, +DetOrChp)
1535
+ %! is semidet.
1536
+ %
1537
+ % Write bindings resulting from a query. The flag
1538
+ % prompt_alternatives_on determines whether the user is prompted
1539
+ % for alternatives. =groundness= gives the classical behaviour,
1540
+ % =determinism= is considered more adequate and informative.
1541
+ %
1542
+ % Succeeds if the user accepts the answer and fails otherwise.
1543
+ %
1544
+ % @arg ResidueVars are the residual constraints and provided if
1545
+ % the prolog flag `toplevel_residue_vars` is set to
1546
+ % `project`.
1547
+
1548
+ write_bindings(Bindings, ResidueVars, Delays, DetOrChp) :-
1549
+ '$current_typein_module'(TypeIn),
1550
+ translate_bindings(Bindings, Bindings1, ResidueVars, TypeIn:Residuals),
1551
+ omit_qualifier(Delays, TypeIn, Delays1),
1552
+ write_bindings2(Bindings, Bindings1, Residuals, Delays1, DetOrChp).
1553
+
1554
+ write_bindings2(OrgBindings, [], Residuals, Delays, _) :-
1555
+ current_prolog_flag(prompt_alternatives_on, groundness),
1556
+ !,
1557
+ name_vars(OrgBindings, [], t(Residuals, Delays)),
1558
+ print_message(query, query(yes(Delays, Residuals))).
1559
+ write_bindings2(OrgBindings, Bindings, Residuals, Delays, true) :-
1560
+ current_prolog_flag(prompt_alternatives_on, determinism),
1561
+ !,
1562
+ name_vars(OrgBindings, Bindings, t(Residuals, Delays)),
1563
+ print_message(query, query(yes(Bindings, Delays, Residuals))).
1564
+ write_bindings2(OrgBindings, Bindings, Residuals, Delays, Chp) :-
1565
+ repeat,
1566
+ name_vars(OrgBindings, Bindings, t(Residuals, Delays)),
1567
+ print_message(query, query(more(Bindings, Delays, Residuals))),
1568
+ get_respons(Action, Chp),
1569
+ ( Action == redo
1570
+ -> !, fail
1571
+ ; Action == show_again
1572
+ -> fail
1573
+ ; !,
1574
+ print_message(query, query(done))
1575
+ ).
1576
+
1577
+ %! name_vars(+OrgBinding, +Bindings, +Term) is det.
1578
+ %
1579
+ % Give a name ``_[A-Z][0-9]*`` to all variables in Term, that do not
1580
+ % have a name due to Bindings. Singleton variables in Term are named
1581
+ % `_`. The behavior depends on these Prolog flags:
1582
+ %
1583
+ % - toplevel_name_variables
1584
+ % Only act when `true`, else name_vars/3 is a no-op.
1585
+ % - toplevel_print_anon
1586
+ %
1587
+ % Variables are named by unifying them to `'$VAR'(Name)`
1588
+ %
1589
+ % @arg Bindings is a list Name=Value
1590
+
1591
+ name_vars(OrgBindings, Bindings, Term) :-
1592
+ current_prolog_flag(toplevel_name_variables, true),
1593
+ answer_flags_imply_numbervars,
1594
+ !,
1595
+ '$term_multitons'(t(Bindings,Term), Vars),
1596
+ bindings_var_names(OrgBindings, Bindings, VarNames),
1597
+ name_vars_(Vars, VarNames, 0),
1598
+ term_variables(t(Bindings,Term), SVars),
1599
+ anon_vars(SVars).
1600
+ name_vars(_OrgBindings, _Bindings, _Term).
1601
+
1602
+ name_vars_([], _, _).
1603
+ name_vars_([H|T], Bindings, N) :-
1604
+ name_var(Bindings, Name, N, N1),
1605
+ H = '$VAR'(Name),
1606
+ name_vars_(T, Bindings, N1).
1607
+
1608
+ anon_vars([]).
1609
+ anon_vars(['$VAR'('_')|T]) :-
1610
+ anon_vars(T).
1611
+
1612
+ %! name_var(+Reserved, -Name, +N0, -N) is det.
1613
+ %
1614
+ % True when Name is a valid name for a new variable where the search
1615
+ % is guided by the number N0. Name may not appear in Reserved.
1616
+
1617
+ name_var(Reserved, Name, N0, N) :-
1618
+ between(N0, infinite, N1),
1619
+ I is N1//26,
1620
+ J is 0'A + N1 mod 26,
1621
+ ( I == 0
1622
+ -> format(atom(Name), '_~c', [J])
1623
+ ; format(atom(Name), '_~c~d', [J, I])
1624
+ ),
1625
+ \+ memberchk(Name, Reserved),
1626
+ !,
1627
+ N is N1+1.
1628
+
1629
+ %! bindings_var_names(+OrgBindings, +TransBindings, -VarNames) is det.
1630
+ %
1631
+ % Find the joined set of variable names in the original bindings and
1632
+ % translated bindings. When generating new names, we better also omit
1633
+ % names that appear in the original bindings (but not in the
1634
+ % translated bindigns).
1635
+
1636
+ bindings_var_names(OrgBindings, TransBindings, VarNames) :-
1637
+ phrase(bindings_var_names_(OrgBindings), VarNames0, Tail),
1638
+ phrase(bindings_var_names_(TransBindings), Tail, []),
1639
+ sort(VarNames0, VarNames).
1640
+
1641
+ %! bindings_var_names_(+Bindings)// is det.
1642
+ %
1643
+ % Produce a list of variable names that appear in Bindings. This deals
1644
+ % both with the single and joined representation of bindings.
1645
+
1646
+ bindings_var_names_([]) --> [].
1647
+ bindings_var_names_([H|T]) -->
1648
+ binding_var_names(H),
1649
+ bindings_var_names_(T).
1650
+
1651
+ binding_var_names(binding(Vars,_Value,_Subst)) ==>
1652
+ var_names(Vars).
1653
+ binding_var_names(Name=_Value) ==>
1654
+ [Name].
1655
+
1656
+ var_names([]) --> [].
1657
+ var_names([H|T]) --> [H], var_names(T).
1658
+
1659
+
1660
+ %! answer_flags_imply_numbervars
1661
+ %
1662
+ % True when the answer will be written recognising '$VAR'(N). If this
1663
+ % is not the case we should not try to name the variables.
1664
+
1665
+ answer_flags_imply_numbervars :-
1666
+ current_prolog_flag(answer_write_options, Options),
1667
+ numbervars_option(Opt),
1668
+ memberchk(Opt, Options),
1669
+ !.
1670
+
1671
+ numbervars_option(portray(true)).
1672
+ numbervars_option(portrayed(true)).
1673
+ numbervars_option(numbervars(true)).
1674
+
1675
+ %! residual_goals(:NonTerminal)
1676
+ %
1677
+ % Directive that registers NonTerminal as a collector for residual
1678
+ % goals.
1679
+
1680
+ :- multifile
1681
+ residual_goal_collector/1.
1682
+
1683
+ :- meta_predicate
1684
+ residual_goals(2).
1685
+
1686
+ residual_goals(NonTerminal) :-
1687
+ throw(error(context_error(nodirective, residual_goals(NonTerminal)), _)).
1688
+
1689
+ system:term_expansion((:- residual_goals(NonTerminal)),
1690
+ '$toplevel':residual_goal_collector(M2:Head)) :-
1691
+ \+ current_prolog_flag(xref, true),
1692
+ prolog_load_context(module, M),
1693
+ strip_module(M:NonTerminal, M2, Head),
1694
+ '$must_be'(callable, Head).
1695
+
1696
+ %! prolog:residual_goals// is det.
1697
+ %
1698
+ % DCG that collects residual goals that are not associated with
1699
+ % the answer through attributed variables.
1700
+
1701
+ :- public prolog:residual_goals//0.
1702
+
1703
+ prolog:residual_goals -->
1704
+ { findall(NT, residual_goal_collector(NT), NTL) },
1705
+ collect_residual_goals(NTL).
1706
+
1707
+ collect_residual_goals([]) --> [].
1708
+ collect_residual_goals([H|T]) -->
1709
+ ( call(H) -> [] ; [] ),
1710
+ collect_residual_goals(T).
1711
+
1712
+
1713
+
1714
+ %! prolog:translate_bindings(+Bindings0, -Bindings, +ResidueVars,
1715
+ %! +ResidualGoals, -Residuals) is det.
1716
+ %
1717
+ % Translate the raw variable bindings resulting from successfully
1718
+ % completing a query into a binding list and list of residual
1719
+ % goals suitable for human consumption.
1720
+ %
1721
+ % @arg Bindings is a list of binding(Vars,Value,Substitutions),
1722
+ % where Vars is a list of variable names. E.g.
1723
+ % binding(['A','B'],42,[])` means that both the variable
1724
+ % A and B have the value 42. Values may contain terms
1725
+ % '$VAR'(Name) to indicate sharing with a given variable.
1726
+ % Value is always an acyclic term. If cycles appear in the
1727
+ % answer, Substitutions contains a list of substitutions
1728
+ % that restore the original term.
1729
+ %
1730
+ % @arg Residuals is a pair of two lists representing residual
1731
+ % goals. The first element of the pair are residuals
1732
+ % related to the query variables and the second are
1733
+ % related that are disconnected from the query.
1734
+
1735
+ :- public
1736
+ prolog:translate_bindings/5.
1737
+ :- meta_predicate
1738
+ prolog:translate_bindings(+, -, +, +, :).
1739
+
1740
+ prolog:translate_bindings(Bindings0, Bindings, ResVars, ResGoals, Residuals) :-
1741
+ translate_bindings(Bindings0, Bindings, ResVars, ResGoals, Residuals),
1742
+ name_vars(Bindings0, Bindings, t(ResVars, ResGoals, Residuals)).
1743
+
1744
+ % should not be required.
1745
+ prolog:name_vars(Bindings, Term) :- name_vars([], Bindings, Term).
1746
+ prolog:name_vars(Bindings0, Bindings, Term) :- name_vars(Bindings0, Bindings, Term).
1747
+
1748
+ translate_bindings(Bindings0, Bindings, ResidueVars, Residuals) :-
1749
+ prolog:residual_goals(ResidueGoals, []),
1750
+ translate_bindings(Bindings0, Bindings, ResidueVars, ResidueGoals,
1751
+ Residuals).
1752
+
1753
+ translate_bindings(Bindings0, Bindings, [], [], _:[]-[]) :-
1754
+ term_attvars(Bindings0, []),
1755
+ !,
1756
+ join_same_bindings(Bindings0, Bindings1),
1757
+ factorize_bindings(Bindings1, Bindings2),
1758
+ bind_vars(Bindings2, Bindings3),
1759
+ filter_bindings(Bindings3, Bindings).
1760
+ translate_bindings(Bindings0, Bindings, ResidueVars, ResGoals0,
1761
+ TypeIn:Residuals-HiddenResiduals) :-
1762
+ project_constraints(Bindings0, ResidueVars),
1763
+ hidden_residuals(ResidueVars, Bindings0, HiddenResiduals0),
1764
+ omit_qualifiers(HiddenResiduals0, TypeIn, HiddenResiduals),
1765
+ copy_term(Bindings0+ResGoals0, Bindings1+ResGoals1, Residuals0),
1766
+ '$append'(ResGoals1, Residuals0, Residuals1),
1767
+ omit_qualifiers(Residuals1, TypeIn, Residuals),
1768
+ join_same_bindings(Bindings1, Bindings2),
1769
+ factorize_bindings(Bindings2, Bindings3),
1770
+ bind_vars(Bindings3, Bindings4),
1771
+ filter_bindings(Bindings4, Bindings).
1772
+
1773
+ hidden_residuals(ResidueVars, Bindings, Goal) :-
1774
+ term_attvars(ResidueVars, Remaining),
1775
+ term_attvars(Bindings, QueryVars),
1776
+ subtract_vars(Remaining, QueryVars, HiddenVars),
1777
+ copy_term(HiddenVars, _, Goal).
1778
+
1779
+ subtract_vars(All, Subtract, Remaining) :-
1780
+ sort(All, AllSorted),
1781
+ sort(Subtract, SubtractSorted),
1782
+ ord_subtract(AllSorted, SubtractSorted, Remaining).
1783
+
1784
+ ord_subtract([], _Not, []).
1785
+ ord_subtract([H1|T1], L2, Diff) :-
1786
+ diff21(L2, H1, T1, Diff).
1787
+
1788
+ diff21([], H1, T1, [H1|T1]).
1789
+ diff21([H2|T2], H1, T1, Diff) :-
1790
+ compare(Order, H1, H2),
1791
+ diff3(Order, H1, T1, H2, T2, Diff).
1792
+
1793
+ diff12([], _H2, _T2, []).
1794
+ diff12([H1|T1], H2, T2, Diff) :-
1795
+ compare(Order, H1, H2),
1796
+ diff3(Order, H1, T1, H2, T2, Diff).
1797
+
1798
+ diff3(<, H1, T1, H2, T2, [H1|Diff]) :-
1799
+ diff12(T1, H2, T2, Diff).
1800
+ diff3(=, _H1, T1, _H2, T2, Diff) :-
1801
+ ord_subtract(T1, T2, Diff).
1802
+ diff3(>, H1, T1, _H2, T2, Diff) :-
1803
+ diff21(T2, H1, T1, Diff).
1804
+
1805
+
1806
+ %! project_constraints(+Bindings, +ResidueVars) is det.
1807
+ %
1808
+ % Call <module>:project_attributes/2 if the Prolog flag
1809
+ % `toplevel_residue_vars` is set to `project`.
1810
+
1811
+ project_constraints(Bindings, ResidueVars) :-
1812
+ !,
1813
+ term_attvars(Bindings, AttVars),
1814
+ phrase(attribute_modules(AttVars), Modules0),
1815
+ sort(Modules0, Modules),
1816
+ term_variables(Bindings, QueryVars),
1817
+ project_attributes(Modules, QueryVars, ResidueVars).
1818
+ project_constraints(_, _).
1819
+
1820
+ project_attributes([], _, _).
1821
+ project_attributes([M|T], QueryVars, ResidueVars) :-
1822
+ ( current_predicate(M:project_attributes/2),
1823
+ catch(M:project_attributes(QueryVars, ResidueVars), E,
1824
+ print_message(error, E))
1825
+ -> true
1826
+ ; true
1827
+ ),
1828
+ project_attributes(T, QueryVars, ResidueVars).
1829
+
1830
+ attribute_modules([]) --> [].
1831
+ attribute_modules([H|T]) -->
1832
+ { get_attrs(H, Attrs) },
1833
+ attrs_modules(Attrs),
1834
+ attribute_modules(T).
1835
+
1836
+ attrs_modules([]) --> [].
1837
+ attrs_modules(att(Module, _, More)) -->
1838
+ [Module],
1839
+ attrs_modules(More).
1840
+
1841
+
1842
+ %! join_same_bindings(Bindings0, Bindings)
1843
+ %
1844
+ % Join variables that are bound to the same value. Note that we
1845
+ % return the _last_ value. This is because the factorization may
1846
+ % be different and ultimately the names will be printed as V1 =
1847
+ % V2, ... VN = Value. Using the last, Value has the factorization
1848
+ % of VN.
1849
+
1850
+ join_same_bindings([], []).
1851
+ join_same_bindings([Name=V0|T0], [[Name|Names]=V|T]) :-
1852
+ take_same_bindings(T0, V0, V, Names, T1),
1853
+ join_same_bindings(T1, T).
1854
+
1855
+ take_same_bindings([], Val, Val, [], []).
1856
+ take_same_bindings([Name=V1|T0], V0, V, [Name|Names], T) :-
1857
+ V0 == V1,
1858
+ !,
1859
+ take_same_bindings(T0, V1, V, Names, T).
1860
+ take_same_bindings([Pair|T0], V0, V, Names, [Pair|T]) :-
1861
+ take_same_bindings(T0, V0, V, Names, T).
1862
+
1863
+
1864
+ %! omit_qualifiers(+QGoals, +TypeIn, -Goals) is det.
1865
+ %
1866
+ % Omit unneeded module qualifiers from QGoals relative to the
1867
+ % given module TypeIn.
1868
+
1869
+
1870
+ omit_qualifiers([], _, []).
1871
+ omit_qualifiers([Goal0|Goals0], TypeIn, [Goal|Goals]) :-
1872
+ omit_qualifier(Goal0, TypeIn, Goal),
1873
+ omit_qualifiers(Goals0, TypeIn, Goals).
1874
+
1875
+ omit_qualifier(M:G0, TypeIn, G) :-
1876
+ M == TypeIn,
1877
+ !,
1878
+ omit_meta_qualifiers(G0, TypeIn, G).
1879
+ omit_qualifier(M:G0, TypeIn, G) :-
1880
+ predicate_property(TypeIn:G0, imported_from(M)),
1881
+ \+ predicate_property(G0, transparent),
1882
+ !,
1883
+ G0 = G.
1884
+ omit_qualifier(_:G0, _, G) :-
1885
+ predicate_property(G0, built_in),
1886
+ \+ predicate_property(G0, transparent),
1887
+ !,
1888
+ G0 = G.
1889
+ omit_qualifier(M:G0, _, M:G) :-
1890
+ atom(M),
1891
+ !,
1892
+ omit_meta_qualifiers(G0, M, G).
1893
+ omit_qualifier(G0, TypeIn, G) :-
1894
+ omit_meta_qualifiers(G0, TypeIn, G).
1895
+
1896
+ omit_meta_qualifiers(V, _, V) :-
1897
+ var(V),
1898
+ !.
1899
+ omit_meta_qualifiers((QA,QB), TypeIn, (A,B)) :-
1900
+ !,
1901
+ omit_qualifier(QA, TypeIn, A),
1902
+ omit_qualifier(QB, TypeIn, B).
1903
+ omit_meta_qualifiers(tnot(QA), TypeIn, tnot(A)) :-
1904
+ !,
1905
+ omit_qualifier(QA, TypeIn, A).
1906
+ omit_meta_qualifiers(freeze(V, QGoal), TypeIn, freeze(V, Goal)) :-
1907
+ callable(QGoal),
1908
+ !,
1909
+ omit_qualifier(QGoal, TypeIn, Goal).
1910
+ omit_meta_qualifiers(when(Cond, QGoal), TypeIn, when(Cond, Goal)) :-
1911
+ callable(QGoal),
1912
+ !,
1913
+ omit_qualifier(QGoal, TypeIn, Goal).
1914
+ omit_meta_qualifiers(G, _, G).
1915
+
1916
+
1917
+ %! bind_vars(+BindingsIn, -Bindings)
1918
+ %
1919
+ % Bind variables to '$VAR'(Name), so they are printed by the names
1920
+ % used in the query. Note that by binding in the reverse order,
1921
+ % variables bound to one another come out in the natural order.
1922
+
1923
+ bind_vars(Bindings0, Bindings) :-
1924
+ bind_query_vars(Bindings0, Bindings, SNames),
1925
+ bind_skel_vars(Bindings, Bindings, SNames, 1, _).
1926
+
1927
+ bind_query_vars([], [], []).
1928
+ bind_query_vars([binding(Names,Var,[Var2=Cycle])|T0],
1929
+ [binding(Names,Cycle,[])|T], [Name|SNames]) :-
1930
+ Var == Var2, % also implies var(Var)
1931
+ !,
1932
+ '$last'(Names, Name),
1933
+ Var = '$VAR'(Name),
1934
+ bind_query_vars(T0, T, SNames).
1935
+ bind_query_vars([B|T0], [B|T], AllNames) :-
1936
+ B = binding(Names,Var,Skel),
1937
+ bind_query_vars(T0, T, SNames),
1938
+ ( var(Var), \+ attvar(Var), Skel == []
1939
+ -> AllNames = [Name|SNames],
1940
+ '$last'(Names, Name),
1941
+ Var = '$VAR'(Name)
1942
+ ; AllNames = SNames
1943
+ ).
1944
+
1945
+
1946
+
1947
+ bind_skel_vars([], _, _, N, N).
1948
+ bind_skel_vars([binding(_,_,Skel)|T], Bindings, SNames, N0, N) :-
1949
+ bind_one_skel_vars(Skel, Bindings, SNames, N0, N1),
1950
+ bind_skel_vars(T, Bindings, SNames, N1, N).
1951
+
1952
+ %! bind_one_skel_vars(+Subst, +Bindings, +VarName, +N0, -N)
1953
+ %
1954
+ % Give names to the factorized variables that do not have a name
1955
+ % yet. This introduces names _S<N>, avoiding duplicates. If a
1956
+ % factorized variable shares with another binding, use the name of
1957
+ % that variable.
1958
+ %
1959
+ % @tbd Consider the call below. We could remove either of the
1960
+ % A = x(1). Which is best?
1961
+ %
1962
+ % ==
1963
+ % ?- A = x(1), B = a(A,A).
1964
+ % A = x(1),
1965
+ % B = a(A, A), % where
1966
+ % A = x(1).
1967
+ % ==
1968
+
1969
+ bind_one_skel_vars([], _, _, N, N).
1970
+ bind_one_skel_vars([Var=Value|T], Bindings, Names, N0, N) :-
1971
+ ( var(Var)
1972
+ -> ( '$member'(binding(Names, VVal, []), Bindings),
1973
+ same_term(Value, VVal)
1974
+ -> '$last'(Names, VName),
1975
+ Var = '$VAR'(VName),
1976
+ N2 = N0
1977
+ ; between(N0, infinite, N1),
1978
+ atom_concat('_S', N1, Name),
1979
+ \+ memberchk(Name, Names),
1980
+ !,
1981
+ Var = '$VAR'(Name),
1982
+ N2 is N1 + 1
1983
+ )
1984
+ ; N2 = N0
1985
+ ),
1986
+ bind_one_skel_vars(T, Bindings, Names, N2, N).
1987
+
1988
+
1989
+ %! factorize_bindings(+Bindings0, -Factorized)
1990
+ %
1991
+ % Factorize cycles and sharing in the bindings.
1992
+
1993
+ factorize_bindings([], []).
1994
+ factorize_bindings([Name=Value|T0], [binding(Name, Skel, Subst)|T]) :-
1995
+ '$factorize_term'(Value, Skel, Subst0),
1996
+ ( current_prolog_flag(toplevel_print_factorized, true)
1997
+ -> Subst = Subst0
1998
+ ; only_cycles(Subst0, Subst)
1999
+ ),
2000
+ factorize_bindings(T0, T).
2001
+
2002
+
2003
+ only_cycles([], []).
2004
+ only_cycles([B|T0], List) :-
2005
+ ( B = (Var=Value),
2006
+ Var = Value,
2007
+ acyclic_term(Var)
2008
+ -> only_cycles(T0, List)
2009
+ ; List = [B|T],
2010
+ only_cycles(T0, T)
2011
+ ).
2012
+
2013
+
2014
+ %! filter_bindings(+Bindings0, -Bindings)
2015
+ %
2016
+ % Remove bindings that must not be printed. There are two of them:
2017
+ % Variables whose name start with '_' and variables that are only
2018
+ % bound to themselves (or, unbound).
2019
+
2020
+ filter_bindings([], []).
2021
+ filter_bindings([H0|T0], T) :-
2022
+ hide_vars(H0, H),
2023
+ ( ( arg(1, H, [])
2024
+ ; self_bounded(H)
2025
+ )
2026
+ -> filter_bindings(T0, T)
2027
+ ; T = [H|T1],
2028
+ filter_bindings(T0, T1)
2029
+ ).
2030
+
2031
+ hide_vars(binding(Names0, Skel, Subst), binding(Names, Skel, Subst)) :-
2032
+ hide_names(Names0, Skel, Subst, Names).
2033
+
2034
+ hide_names([], _, _, []).
2035
+ hide_names([Name|T0], Skel, Subst, T) :-
2036
+ ( sub_atom(Name, 0, _, _, '_'),
2037
+ current_prolog_flag(toplevel_print_anon, false),
2038
+ sub_atom(Name, 1, 1, _, Next),
2039
+ char_type(Next, prolog_var_start)
2040
+ -> true
2041
+ ; Subst == [],
2042
+ Skel == '$VAR'(Name)
2043
+ ),
2044
+ !,
2045
+ hide_names(T0, Skel, Subst, T).
2046
+ hide_names([Name|T0], Skel, Subst, [Name|T]) :-
2047
+ hide_names(T0, Skel, Subst, T).
2048
+
2049
+ self_bounded(binding([Name], Value, [])) :-
2050
+ Value == '$VAR'(Name).
2051
+
2052
+ %! get_respons(-Action, +Chp)
2053
+ %
2054
+ % Read the continuation entered by the user.
2055
+
2056
+ :- if(current_prolog_flag(emscripten, true)).
2057
+ get_respons(Action, Chp) :-
2058
+ '$can_yield',
2059
+ !,
2060
+ repeat,
2061
+ await(more, CommandS),
2062
+ atom_string(Command, CommandS),
2063
+ more_action(Command, Chp, Action),
2064
+ ( Action == again
2065
+ -> print_message(query, query(action)),
2066
+ fail
2067
+ ; !
2068
+ ).
2069
+ :- endif.
2070
+ get_respons(Action, Chp) :-
2071
+ repeat,
2072
+ flush_output(user_output),
2073
+ get_single_char(Code),
2074
+ find_more_command(Code, Command, Feedback, Style),
2075
+ ( Style \== '-'
2076
+ -> print_message(query, if_tty([ansi(Style, '~w', [Feedback])]))
2077
+ ; true
2078
+ ),
2079
+ more_action(Command, Chp, Action),
2080
+ ( Action == again
2081
+ -> print_message(query, query(action)),
2082
+ fail
2083
+ ; !
2084
+ ).
2085
+
2086
+ find_more_command(-1, end_of_file, 'EOF', warning) :-
2087
+ !.
2088
+ find_more_command(Code, Command, Feedback, Style) :-
2089
+ more_command(Command, Atom, Feedback, Style),
2090
+ '$in_reply'(Code, Atom),
2091
+ !.
2092
+ find_more_command(Code, again, '', -) :-
2093
+ print_message(query, no_action(Code)).
2094
+
2095
+ more_command(help, '?h', '', -).
2096
+ more_command(redo, ';nrNR \t', ';', bold).
2097
+ more_command(trace, 'tT', '; [trace]', comment).
2098
+ more_command(continue, 'ca\n\ryY.', '.', bold).
2099
+ more_command(break, 'b', '', -).
2100
+ more_command(choicepoint, '*', '', -).
2101
+ more_command(write, 'w', '[write]', comment).
2102
+ more_command(print, 'p', '[print]', comment).
2103
+ more_command(depth_inc, '+', Change, comment) :-
2104
+ ( print_depth(Depth0)
2105
+ -> depth_step(Step),
2106
+ NewDepth is Depth0*Step,
2107
+ format(atom(Change), '[max_depth(~D)]', [NewDepth])
2108
+ ; Change = 'no max_depth'
2109
+ ).
2110
+ more_command(depth_dec, '-', Change, comment) :-
2111
+ ( print_depth(Depth0)
2112
+ -> depth_step(Step),
2113
+ NewDepth is max(1, Depth0//Step),
2114
+ format(atom(Change), '[max_depth(~D)]', [NewDepth])
2115
+ ; Change = '[max_depth(10)]'
2116
+ ).
2117
+
2118
+ more_action(help, _, Action) =>
2119
+ Action = again,
2120
+ print_message(help, query(help)).
2121
+ more_action(redo, _, Action) => % Next
2122
+ Action = redo.
2123
+ more_action(trace, _, Action) =>
2124
+ Action = redo,
2125
+ trace,
2126
+ save_debug.
2127
+ more_action(continue, _, Action) => % Stop
2128
+ Action = continue.
2129
+ more_action(break, _, Action) =>
2130
+ Action = show_again,
2131
+ break.
2132
+ more_action(choicepoint, Chp, Action) =>
2133
+ Action = show_again,
2134
+ print_last_chpoint(Chp).
2135
+ more_action(end_of_file, _, Action) =>
2136
+ Action = show_again,
2137
+ halt(0).
2138
+ more_action(again, _, Action) =>
2139
+ Action = again.
2140
+ more_action(Command, _, Action),
2141
+ current_prolog_flag(answer_write_options, Options0),
2142
+ print_predicate(Command, Options0, Options) =>
2143
+ Action = show_again,
2144
+ set_prolog_flag(answer_write_options, Options).
2145
+
2146
+ print_depth(Depth) :-
2147
+ current_prolog_flag(answer_write_options, Options),
2148
+ memberchk(max_depth(Depth), Options),
2149
+ !.
2150
+
2151
+ %! print_predicate(+Action, +Options0, -Options) is semidet.
2152
+ %
2153
+ % Modify the `answer_write_options` value according to the user
2154
+ % command.
2155
+
2156
+ print_predicate(write, Options0, Options) :-
2157
+ edit_options([-portrayed(true),-portray(true)],
2158
+ Options0, Options).
2159
+ print_predicate(print, Options0, Options) :-
2160
+ edit_options([+portrayed(true)],
2161
+ Options0, Options).
2162
+ print_predicate(depth_inc, Options0, Options) :-
2163
+ ( '$select'(max_depth(D0), Options0, Options1)
2164
+ -> depth_step(Step),
2165
+ D is D0*Step,
2166
+ Options = [max_depth(D)|Options1]
2167
+ ; Options = Options0
2168
+ ).
2169
+ print_predicate(depth_dec, Options0, Options) :-
2170
+ ( '$select'(max_depth(D0), Options0, Options1)
2171
+ -> depth_step(Step),
2172
+ D is max(1, D0//Step),
2173
+ Options = [max_depth(D)|Options1]
2174
+ ; D = 10,
2175
+ Options = [max_depth(D)|Options0]
2176
+ ).
2177
+
2178
+ depth_step(5).
2179
+
2180
+ edit_options([], Options, Options).
2181
+ edit_options([H|T], Options0, Options) :-
2182
+ edit_option(H, Options0, Options1),
2183
+ edit_options(T, Options1, Options).
2184
+
2185
+ edit_option(-Term, Options0, Options) =>
2186
+ ( '$select'(Term, Options0, Options)
2187
+ -> true
2188
+ ; Options = Options0
2189
+ ).
2190
+ edit_option(+Term, Options0, Options) =>
2191
+ functor(Term, Name, 1),
2192
+ functor(Var, Name, 1),
2193
+ ( '$select'(Var, Options0, Options1)
2194
+ -> Options = [Term|Options1]
2195
+ ; Options = [Term|Options0]
2196
+ ).
2197
+
2198
+ %! print_last_chpoint(+Chp) is det.
2199
+ %
2200
+ % Print the last choicepoint when an answer is nondeterministic.
2201
+
2202
+ print_last_chpoint(Chp) :-
2203
+ current_predicate(print_last_choice_point/0),
2204
+ !,
2205
+ print_last_chpoint_(Chp).
2206
+ print_last_chpoint(Chp) :-
2207
+ use_module(library(prolog_stack), [print_last_choicepoint/2]),
2208
+ print_last_chpoint_(Chp).
2209
+
2210
+ print_last_chpoint_(Chp) :-
2211
+ print_last_choicepoint(Chp, [message_level(information)]).
2212
+
2213
+
2214
+ /*******************************
2215
+ * EXPANSION *
2216
+ *******************************/
2217
+
2218
+ :- user:dynamic(expand_query/4).
2219
+ :- user:multifile(expand_query/4).
2220
+
2221
+ call_expand_query(Goal, Expanded, Bindings, ExpandedBindings) :-
2222
+ ( '$replace_toplevel_vars'(Goal, Expanded0, Bindings, ExpandedBindings0)
2223
+ -> true
2224
+ ; Expanded0 = Goal, ExpandedBindings0 = Bindings
2225
+ ),
2226
+ ( user:expand_query(Expanded0, Expanded, ExpandedBindings0, ExpandedBindings)
2227
+ -> true
2228
+ ; Expanded = Expanded0, ExpandedBindings = ExpandedBindings0
2229
+ ).
2230
+
2231
+
2232
+ :- dynamic
2233
+ user:expand_answer/2,
2234
+ prolog:expand_answer/3.
2235
+ :- multifile
2236
+ user:expand_answer/2,
2237
+ prolog:expand_answer/3.
2238
+
2239
+ call_expand_answer(Goal, BindingsIn, BindingsOut) :-
2240
+ ( prolog:expand_answer(Goal, BindingsIn, BindingsOut)
2241
+ -> true
2242
+ ; user:expand_answer(BindingsIn, BindingsOut)
2243
+ -> true
2244
+ ; BindingsOut = BindingsIn
2245
+ ),
2246
+ '$save_toplevel_vars'(BindingsOut),
2247
+ !.
2248
+ call_expand_answer(_, Bindings, Bindings).