### Run installed system tests interactively Source: https://github.com/swi-prolog/swipl-devel/blob/master/doc/Testing.md Start SWI-Prolog and run the 'test_installation' predicate interactively to test the installed system. ```prolog ?- test_installation. ``` -------------------------------- ### Install Boot and ABI Files Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Installs essential SWI-Prolog boot and ABI (Application Binary Interface) files to the installation prefix. ```cmake install(FILES ${SWIPL_BOOT_FILE} ${SWIPL_ABI_FILE} DESTINATION ${SWIPL_INSTALL_PREFIX} ) ``` -------------------------------- ### Install License and Readme Files Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMakeLists.txt Installs the LICENSE and README.md files to the specified installation prefix. ```cmake install(FILES LICENSE README.md DESTINATION ${SWIPL_INSTALL_PREFIX}) ``` -------------------------------- ### Create Windows Installer (64-bit) Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Generate a Windows installer for SWI-Prolog using cross-compilation from a Linux environment. Requires NSIS to be installed. ```bash cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../cmake/cross/linux_win64.cmake -G Ninja .. ninja cpack ``` -------------------------------- ### Install SWIPL Home Configuration Files Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Installs SWI-Prolog configuration files ('swipl.home' and 'swipl.home' in bin) to the installation prefix and bin directory, respectively. ```cmake install(FILES ${SWIPL_BIN_ROOT}/dot.txt DESTINATION ${SWIPL_INSTALL_PREFIX} RENAME "swipl.home") install(FILES ${SWIPL_BIN_ROOT}/dotdot.txt DESTINATION ${SWIPL_INSTALL_PREFIX}/bin RENAME "swipl.home") ``` -------------------------------- ### Create Windows Installer (32-bit) Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Generate a 32-bit Windows installer for SWI-Prolog using cross-compilation. Ensure NSIS is installed. ```bash cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../cmake/cross/linux_win32.cmake -G Ninja .. ninja cpack ``` -------------------------------- ### Set Custom Install Prefix Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Specify a custom installation directory using CMAKE_INSTALL_PREFIX. This example installs to the user's home directory. ```bash cmake -DCMAKE_INSTALL_PREFIX=$HOME -G Ninja .. ``` -------------------------------- ### Compile and Install Library .qlf Files Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Enable the compilation and installation of library .qlf files. ```cmake -DINSTALL_QLF=ON ``` -------------------------------- ### Install Docs in /share Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Controls the installation directory for documentation files. ```cmake -DSWIPL_INSTALL_IN_SHARE=ON ``` -------------------------------- ### Install libswipl.so in /lib Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Controls the installation directory for the `libswipl.so` library. ```cmake -DSWIPL_INSTALL_IN_LIB=ON ``` -------------------------------- ### Basic SWI-Prolog Source Installation Source: https://github.com/swi-prolog/swipl-devel/blob/master/INSTALL.md Clone the SWI-Prolog development repository, create a build directory, configure the build, and compile using Ninja. Ensure all dependencies are installed beforehand. ```bash git clone --recurse-submodules https://github.com/SWI-Prolog/swipl-devel.git cd swipl-devel mkdir build cd build ../scripts/configure ninja ``` -------------------------------- ### Install init.pl on Unix Source: https://github.com/swi-prolog/swipl-devel/blob/master/customize/README.md Copies the init.pl template to the SWI-Prolog configuration directory on Unix-like systems. ```bash mkdir -p ${XDG_DATA_HOME-$HOME/.config}/swi-prolog cp init.pl ${XDG_DATA_HOME-$HOME/.config}/swi-prolog ``` -------------------------------- ### Install Tests Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Add tests to the installed system. ```cmake -DINSTALL_TESTS=ON ``` -------------------------------- ### Install PkgConfig File Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Installs the pkgconfig file if SWIPL_INSTALL_PKGCONFIG is enabled, allowing other build systems to find SWI-Prolog. ```cmake if(SWIPL_INSTALL_PKGCONFIG) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/swipl.pc DESTINATION ${SWIPL_INSTALL_PKGCONFIG}) endif() ``` -------------------------------- ### Install Manpages Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Installs SWI-Prolog manpages if SWIPL_INSTALL_MANPAGES is enabled. This includes the main swipl manpage and swipl-ld. ```cmake if(SWIPL_INSTALL_MANPAGES) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/swipl.1 DESTINATION ${SWIPL_INSTALL_MANPAGES}) install(FILES swipl-ld.1 DESTINATION ${SWIPL_INSTALL_MANPAGES}) endif() ``` -------------------------------- ### Install Documentation Targets Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/CMakeLists.txt Configures installation targets for documentation when INSTALL_DOCUMENTATION is enabled. This includes core HTML documentation and optionally PDF documentation. ```cmake if(INSTALL_DOCUMENTATION) add_custom_target( core.doc.html DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/manual.html) add_dependencies(doc.html core.doc.html) if(BUILD_PDF_DOCUMENTATION) add_custom_target( core.doc.pdf DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${DOC}.pdf) add_dependencies(doc.pdf core.doc.pdf) endif() install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Manual destination ${SWIPL_INSTALL_DOC}) endif(INSTALL_DOCUMENTATION) ``` -------------------------------- ### Install Customize Scripts Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMakeLists.txt Installs customization scripts and their README to the 'customize' subdirectory of the installation prefix. ```cmake install(FILES customize/edit customize/init.pl customize/README.md DESTINATION ${SWIPL_INSTALL_PREFIX}/customize) ``` -------------------------------- ### Populate Example Questions Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/wasm/demos/chat80.html Fetches example questions from the CHAT80 knowledge base and populates a dropdown list. This function is called after SWI-Prolog WASM is initialized and the CHAT80 knowledge base is loaded. ```javascript function chat80() { fill_examples(); } function fill_examples() { Prolog.forEach("chat_example(_,Sentence,_)", (r) => { const q = r.Sentence.map((t) => t.nb !== undefined ? t.nb[0] : t).join(" "); const node = document.createElement("option"); node.textContent = q; examples.appendChild(node); }).then(() => {}); } ``` -------------------------------- ### Install SWI-Prolog Component on Linux Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Use this command to install a specific SWI-Prolog component on Linux. Ensure you replace `` with the desired component name. ```bash DESTDIR=$(pwd)/ \ cmake -DCMAKE_INSTALL_COMPONENT= \ -P cmake_install.cmake ``` -------------------------------- ### Install SWI-Prolog tests Source: https://github.com/swi-prolog/swipl-devel/blob/master/doc/Testing.md Configure cmake with the -DINSTALL_TESTS=ON option to include test scripts and data in the SWI-Prolog installation directory. ```bash cmake -DINSTALL_TESTS=ON ... ``` -------------------------------- ### Install SWIPL Targets and Libraries Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Installs the main SWIPL executable, libraries, and related runtime dependencies. Configures installation paths for executables, libraries, and archives. ```cmake install(TARGETS swipl ${SWIPL_INSTALLED_LIBRARIES} EXPORT SWIPL_EXPORT rustime DESTINATION ${SWIPL_INSTALL_ARCH_EXE} LIBRARY DESTINATION ${LIBSWIPL_DIR} ARCHIVE DESTINATION ${LIBSWIPL_DIR} ) target_runtime_dependencies(swipl) ``` -------------------------------- ### Get Help on a Predicate with help/1 Source: https://github.com/swi-prolog/swipl-devel/blob/master/README.md Use the `help/1` predicate to display detailed information about a specific predicate. Provide the predicate name and arity, for example, `append/3`. ```Prolog ?- help(append/3). ``` -------------------------------- ### Usage Example for Persistent Dynamic Predicates Source: https://context7.com/swi-prolog/swipl-devel/llms.txt Provides a complete usage example for managing a persistent user database, including attaching the database, adding users, querying users, and demonstrating persistence across sessions. ```prolog % Usage: % ?- attach_db('users.db'). % ?- add_user(john, 'john@example.com'). % ?- add_user(mary, 'mary@example.com'). % ?- get_user(Name, Email). % Name = john, Email = 'john@example.com' ; % Name = mary, Email = 'mary@example.com'. % % Database survives restart: % ?- attach_db('users.db'). % ?- get_user(Name, _). % Name = john ; % Name = mary. ``` -------------------------------- ### Activate SWI-Prolog Installation Source: https://github.com/swi-prolog/swipl-devel/blob/master/INSTALL.md Link the built SWI-Prolog system to your personal binary directory for easy access. This command should be run from the SWI-Prolog source directory. ```bash ../scripts/swipl-activate ``` -------------------------------- ### Install SWIPL Data Directories Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Installs SWI-Prolog data files from specified directories. It dynamically constructs variable names based on directory paths. ```cmake foreach(d ${SWIPL_DATA_DIRS}) string(REGEX REPLACE "/" "_" filevar ${d}) prepend(files ${SWIPL_ROOT}/${d} ${SWIPL_DATA_${filevar}}) install_src(core_${filevar} FILES ${files} DESTINATION ${SWIPL_INSTALL_PREFIX}/${d}) endforeach() ``` -------------------------------- ### Example: Custom Package List with Documentation Disabled Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Example of disabling documentation and specifying a custom package list for the build. ```cmake cmake -DINSTALL_DOCUMENTATION=OFF -DSWIPL_PACKAGE_LIST="clib;plunit" ``` -------------------------------- ### SWI-Prolog Trace Mode Commands: Find Examples Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/textdebugger.md Examples of using the 'Find' command ('/') in SWI-Prolog's tracer to search for specific ports and goals. ```prolog /f ``` ```prolog /fe solve ``` ```prolog /c solve(a, _) ``` ```prolog /a member(_, _) ``` -------------------------------- ### Load CLP(FD) Library Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/lib/clpfdlib.md Include this directive in your initialization file to make CLP(FD) constraints available in all your programs. All example programs assume this setup. ```Prolog :- use_module(library(clpfd)). ``` -------------------------------- ### Install SWIPL Core Headers Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Installs the main SWI-Prolog header files and stream-related headers to the include directory. ```cmake install_src(core_headers FILES ${CMAKE_CURRENT_SOURCE_DIR}/SWI-Prolog.h ${CMAKE_CURRENT_SOURCE_DIR}/os/SWI-Stream.h DESTINATION ${SWIPL_INSTALL_INCLUDE}) ``` -------------------------------- ### Solve Radiation Therapy LP and Get Variable Values Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/lib/simplexlib.md Example query to solve the radiation therapy linear programming problem and retrieve the optimal values for variables x1 and x2. ```prolog ?- radiation(S), variable_value(S, x1, Val1), variable_value(S, x2, Val2). Val1 = 15 rdiv 2, Val2 = 9 rdiv 2. ``` -------------------------------- ### Install Runtime Dependencies Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMakeLists.txt Installs all necessary DLL dependencies for the target. ```cmake install_target_runtime_dependencies() ``` -------------------------------- ### Install EPILOG Application Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Installs the EPILOG application, handling different installation methods based on whether it's being built as a MacOS bundle or a standalone executable. ```cmake if(EPILOG) if(BUILD_MACOS_BUNDLE) install(TARGETS ${EPILOG_APP} BUNDLE DESTINATION .) else() install( TARGETS ${EPILOG_APP} RUNTIME DESTINATION ${SWIPL_INSTALL_ARCH_EXE}) endif() target_runtime_dependencies(${EPILOG_APP}) endif() ``` -------------------------------- ### Install Test Runner Script Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMakeLists.txt Installs SWI-Prolog tests to the target device if INSTALL_TESTS is enabled. This includes the test directory and a database file. ```cmake if(INSTALL_TESTS) set(INSTALL_TESTS_DIR ${SWIPL_INSTALL_PREFIX}/test) set(PKGS_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/packages) set(INSTALL_TESTS_DB ${CMAKE_BINARY_DIR}/cmake_pkg_tests.db) # Use a function to scope CMAKE_INSTALL_DEFAULT_COMPONENT_NAME function(install_tests) set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME Tests) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests/ DESTINATION ${INSTALL_TESTS_DIR} PATTERN "*~" EXCLUDE) #Move test db to installation install(FILES ${INSTALL_TESTS_DB} DESTINATION ${INSTALL_TESTS_DIR}) file(REMOVE ${INSTALL_TESTS_DB}) endfunction() install_tests() endif(INSTALL_TESTS) ``` -------------------------------- ### Native Build SWI-Prolog Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Standard sequence to build and install SWI-Prolog to /usr/local using CMake and Ninja. ```bash cd swipl-devel mkdir build cd build cmake -G Ninja .. ninja ctest -j 8 ninja install ``` -------------------------------- ### Install SWIPL-LD Target Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Installs the swipl-ld executable and its runtime dependencies if BUILD_SWIPL_LD is enabled. ```cmake if(BUILD_SWIPL_LD) install(TARGETS swipl-ld RUNTIME DESTINATION ${SWIPL_INSTALL_ARCH_EXE} ) target_runtime_dependencies(swipl-ld) endif() ``` -------------------------------- ### Handle Example Selection Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/wasm/demos/chat80.html Updates the question input field when a user selects an example from the dropdown list. This provides a convenient way for users to try out pre-defined questions. ```javascript examples.addEventListener("change", (e) => { e.preventDefault(); let q = e.target.options[e.target.selectedIndex].textContent; input.elements.question.value = q; }); ``` -------------------------------- ### Install CMake Export and Config Files Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Installs CMake export set and configuration files, enabling SWI-Prolog to be used as a dependency in other CMake projects. ```cmake install(EXPORT SWIPL_EXPORT FILE SWIPLTargets.cmake NAMESPACE "${SWIPL_CMAKE_NAMESPACE}" DESTINATION "${SWIPL_INSTALL_CMAKE_CONFIG_DIR}") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/SWIPLConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/SWIPLConfigVersion.cmake" DESTINATION "${SWIPL_INSTALL_CMAKE_CONFIG_DIR}") ``` -------------------------------- ### Install MinGW Library Archive Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Installs the MinGW library archive file, renaming it to libswipl.lib for compatibility. ```cmake if(MINGW) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libswipl.dll.a DESTINATION ${LIBSWIPL_DIR} RENAME libswipl.lib) endif() ``` -------------------------------- ### Build SWI-Prolog with Profile Guided Optimization (PGO) Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Build SWI-Prolog using Profile Guided Optimization with Ninja and GCC for performance improvements. This involves a multi-step process of building with instrumentation, running benchmarks, and recompiling. ```bash cmake -DCMAKE_BUILD_TYPE=PGO -G Ninja .. ninja ``` -------------------------------- ### SWI-Prolog Build with Profile Guided Optimization (PGO) Source: https://github.com/swi-prolog/swipl-devel/blob/master/INSTALL.md Configure and build SWI-Prolog with Profile Guided Optimization enabled. This configuration is recommended for gcc and can be combined with other features. ```bash mkdir build.pgo cd build.pgo ../scripts/configure ninja ``` -------------------------------- ### Install Windows Helper DLLs Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Installs necessary helper DLLs for Windows builds, such as MinGW runtime and pthread-win32 libraries. ```cmake if(WIN32) # helper dlls (MinGW runtime, pthread-win32, etc.) prepend(WIN32_DLL_FILES ${CMAKE_CURRENT_BINARY_DIR}/ ${WIN32_DLLS}) install(FILES ${WIN32_DLL_FILES} DESTINATION ${SWIPL_INSTALL_ARCH_EXE}) install_src(core_swipl_ico FILES ${CMAKE_CURRENT_SOURCE_DIR}/swipl.ico DESTINATION ${SWIPL_INSTALL_PREFIX}) else(WIN32) ``` -------------------------------- ### Install SICStus Compatibility Headers Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Installs SICStus Prolog compatibility header files into a 'sicstus' subdirectory within the include path. ```cmake install_src(core_compat_sicstus FILES ${CMAKE_CURRENT_SOURCE_DIR}/compat/sicstus.h DESTINATION ${SWIPL_INSTALL_INCLUDE}/sicstus) ``` -------------------------------- ### Compile Benchmark to QLF Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/wasm/README.md Compile a benchmark to a self-contained .qlf file using this command in the `bench` directory. Requires SWI-Prolog to be installed. ```bash swipl -Dstatic -O qlf -c --include run.pl ``` -------------------------------- ### Start SWI-Prolog Debugger Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/macosx/SWIapp.html To use the source-level debugger, invoke `gtrace/0` before your goal. This replaces the traditional `trace/0` for GUI debugging. ```Prolog ?- gtrace, my_goal(...). ``` -------------------------------- ### Run WASM Server for Browser Benchmarking Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/wasm/README.md Start the WASM server from the build directory after creating a symlink for the compiled benchmark file. This allows browser-based benchmarking. ```bash swipl ../src/wasm/server.pl ``` -------------------------------- ### Create Debian/RPM Package Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Build a monolithic SWI-Prolog installer package for Debian (.deb) or RPM (.rpm) based Linux systems. This is intended for custom in-house deployment. ```bash cmake -DCMAKE_BUILD_TYPE=PGO -DCMAKE_INSTALL_PREFIX=/usr -G Ninja .. ninja cpack ``` -------------------------------- ### Load and Run Benchmark in WASM Shell Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/wasm/README.md After starting the WASM server and opening the indicated URL, run these commands in the WASM shell to load and execute the benchmark. ```prolog ?- ['http://localhost:8080/wasm/bench.qlf']. ?- set_prolog_flag(heartbeat, 1000000). ?- run(0.1). ``` -------------------------------- ### Configure PGO Build Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Set the build type to PGO (Profile Guided Optimization) for maximum performance. ```bash cmake -DCMAKE_BUILD_TYPE=PGO -G Ninja .. ``` -------------------------------- ### Trace Point Example without Trace Mode Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/textdebugger.md Demonstrates using a trace point on `is_a/2` without explicitly enabling trace mode. Only ports related to `is_a/2` are shown. ```Prolog ?- trace(is_a/2). % is_a/2: [all] true. ?- noun(X, rock), adjective(X, color, red). T Call: is_a(_25702, rock) T Exit: is_a(rock1, rock) X = rock1 ; T Redo: is_a(rock1, rock) T Exit: is_a(rock2, rock) false. ``` -------------------------------- ### Engines as Coroutines Example Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/wasm/demos/engines.html Illustrates using engines as coroutines by initiating two queries that generate numbers. The loop then fetches results from both, interleaving their output. ```javascript tests.push({ name: "Using engines as coroutines", func: two_coroutines }); function two_coroutines(out) { const q1 = Prolog.query("between( 1,10,X)", {}, {engine:true}); const q2 = Prolog.query("between(11,20,X)", {}, {engine:true}); for(::) { const ``` -------------------------------- ### Run installed system tests non-interactively Source: https://github.com/swi-prolog/swipl-devel/blob/master/doc/Testing.md Execute the 'test_installation' predicate non-interactively using the 'swipl' command. The command exits with status 0 on success and non-zero if tests fail. ```bash swipl -g test_installation -t halt ``` -------------------------------- ### Default CLP(FD) behavior example Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/lib/clpfdlib.md Demonstrates the default, non-monotonic behavior of CLP(FD) where adding constraints can yield new solutions. ```prolog ?- X #= 2, X = 1+1. false. ``` ```prolog ?- X = 1+1, X #= 2, X = 1+1. X = 1+1. ``` -------------------------------- ### Factorial Query with CLP(FD) Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/lib/clpfdlib.md Example query demonstrating the evaluation of the n_factorial/2 predicate with CLP(FD) constraints. ```Prolog ?- n_factorial(47, F). ``` -------------------------------- ### Initialize SWI-Prolog WASM and Load CHAT80 Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/wasm/demos/chat80.html Initializes SWI-Prolog WASM with specified options and loads the compiled CHAT80 knowledge base. This setup is required before interacting with Prolog from JavaScript. ```javascript const input = document.getElementById("input"); const answer = document.getElementById("answer"); const examples = document.getElementById("examples"); let Prolog; let Module; var options = { arguments: ["-q"], locateFile: (file) => '/wasm/' + file }; SWIPL(options).then((module) => { Module = module; Prolog = Module.prolog; Prolog.consult("chat80.qlf") .then(() => chat80()); }); ``` -------------------------------- ### Example usage of the 'oneground' custom constraint Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/lib/clpfdlib.md Demonstrates how to use the custom 'oneground(X, Y, Z)' constraint. When Y is unified with 5, Z is correctly set to 1. ```prolog ?- oneground(X, Y, Z), Y = 5. Y = 5, Z = 1, X in inf..sup. ``` -------------------------------- ### Build SWI-Prolog Core Components Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Use the 'core' ninja target to build only the essential components: the swipl executable, libswipl, and boot.prc. This is useful when developing the core system and you want to avoid regenerating documentation or package dependencies. ```bash ninja core ``` -------------------------------- ### Prolog Initialization for CLI Apps Source: https://github.com/swi-prolog/swipl-devel/blob/master/app/README.md Define the entry point for a SWI-Prolog CLI application using `initialization/2` with the `main` class. This typically involves using `library(main)` for argument handling. ```prolog :- initialization(mystart, main). ``` ```prolog :- use_module(library(main)). :- initialization(main, main). ``` ```prolog main(Argv) :- argv_options(Argv, Positional, Options), ... ``` -------------------------------- ### Do Not Install Library .pl Files Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Use this option to prevent the installation of library .pl files. ```cmake -DINSTALL_PROLOG_SRC=OFF ``` -------------------------------- ### Set Default Installation Component Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMakeLists.txt Sets the default component name for installed files to 'Core_system'. ```cmake set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "Core_system") ``` -------------------------------- ### Set CMAKE_INSTALL_MESSAGE Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMakeLists.txt Configures the installation message verbosity for CMake. Set to NEVER to suppress messages during installation. ```cmake set(CMAKE_INSTALL_MESSAGE NEVER) ``` -------------------------------- ### Cross-build SWI-Prolog for Windows using Docker Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Instructions for cross-building SWI-Prolog for Windows using a provided Docker specification. This is the recommended approach for cross-compilation. ```bash https://github.com/SWI-Prolog/docker-swipl-build-mingw ``` -------------------------------- ### Activate Trace Mode and Initial Query Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/textdebugger.md This snippet shows how to enter trace mode using `trace.` and then execute a query. The prompt changes to `[trace] ?-` indicating trace mode is active. ```prolog ?- trace. true. [trace] ?- noun(X, rock), adjective(X, color, red). ``` -------------------------------- ### Define predicates for debugging example Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/textdebugger.md These predicates are used in the example to demonstrate breakpoint functionality. They define relationships between objects and their properties. ```Prolog is_a(rock1, rock). is_a(rock2, rock). color(rock1, red). noun(X, Type) :- is_a(X, Type). adjective(X, color, Value) :- color(X, Value). test_noun1(X, Type) :- noun(X, Type). test_noun2(X, Type) :- noun(X, Type). ``` -------------------------------- ### Configure XSB Dialect Support in init.pl Source: https://github.com/swi-prolog/swipl-devel/blob/master/library/dialect/xsb/README.md Include this in your SWI-Prolog configuration file (/init.pl) to enable XSB dialect support automatically when loading files with the .P extension. ```prolog :- use_module(library(dialect/xsb/source)). ``` -------------------------------- ### Install YAP Compatibility Headers Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Installs YAP Prolog compatibility header files into a 'Yap' subdirectory within the include path. ```cmake install_src(core_compat_yap FILES ${CMAKE_CURRENT_SOURCE_DIR}/compat/YapInterface.h DESTINATION ${SWIPL_INSTALL_INCLUDE}/Yap) ``` -------------------------------- ### Configure Desktop Integration Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMakeLists.txt Includes the 'Desktop' module to set up files for desktop integration. ```cmake include(Desktop) ``` -------------------------------- ### Create and populate an association list Source: https://context7.com/swi-prolog/swipl-devel/llms.txt Demonstrates creating an empty association list and adding key-value pairs using `empty_assoc/1` and `put_assoc/4`. ```Prolog :- use_module(library(assoc)). % Create and populate an association list ?- empty_assoc(A0), put_assoc(name, A0, john, A1), put_assoc(age, A1, 30, A2), put_assoc(city, A2, boston, A3), get_assoc(name, A3, Name), get_assoc(age, A3, Age). ``` -------------------------------- ### Sample Sudoku Query and Solution Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/lib/clpfdlib.md A sample query to solve a specific Sudoku problem and its resulting output, demonstrating constraint propagation. ```Prolog ?- problem(1, Rows), sudoku(Rows), maplist(portray_clause, Rows). ``` -------------------------------- ### Create MacOSX Bundle for SWI-Prolog Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Build a MacOSX bundle for SWI-Prolog using CMake and Ninja. This process creates a self-contained application bundle. ```bash cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_MACOS_BUNDLE=ON -G Ninja .. ninja cpack ``` -------------------------------- ### Build SWI-Prolog Distribution Source: https://github.com/swi-prolog/swipl-devel/blob/master/doc/Release.md Build the SWI-Prolog release distribution. This command sources the make-distribution script and then executes the build function. It's recommended to run steps individually the first time. ```bash . scripts/make-distribution build ``` -------------------------------- ### Terminating Factorial Queries Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/lib/clpfdlib.md Examples of queries that now terminate due to the reordered goals in the n_factorial/2 predicate. ```Prolog ?- n_factorial(N, 1). ``` ```Prolog ?- n_factorial(N, 3). ``` -------------------------------- ### Synchronize and Build SWI-Prolog on Mac Source: https://github.com/swi-prolog/swipl-devel/blob/master/doc/Release.md Pull the latest repository changes from the Linux machine, including tags, and verify the directory is clean and in sync before building the Mac release. ```bash git pull linux master git pull --tags linux master git describe ``` ```bash . scripts/make-distribution build ``` -------------------------------- ### Basic CLP(B) Queries Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/lib/clpblib.md Demonstrates fundamental queries using `sat/1` and `taut/2` to solve Boolean satisfiability problems and check tautologies. Requires loading the `library(clpb)`. ```Prolog ?- use_module(library(clpb)). true. ?- sat(X*Y). X = Y, Y = 1. ?- sat(X * ~X). false. ?- taut(X * ~X, T). T = 0, sat(X=:=X). ?- sat(X^Y^(X+Y)). sat(X=:=X), sat(Y=:=Y). ?- sat(X*Y + X*Z), labeling([X,Y,Z]). X = Z, Z = 1, Y = 0 ; X = Y, Y = 1, Z = 0 ; X = Y, Y = Z, Z = 1. ?- sat(X =< Y), sat(Y =< Z), taut(X =< Z, T). T = 1, sat(X=:=X*Y), sat(Y=:=Y*Z). ?- sat(1#X#a#b). sat(X=:=a#b). ``` -------------------------------- ### Upgrade SWI-Prolog Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Update an installed SWI-Prolog system to the latest version by pulling changes, updating submodules, and rebuilding. ```bash git pull git submodule update --init --recursive cd build cmake .. ninja ctest -j 8 ninja install ``` -------------------------------- ### Configure and Build with Custom Features Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Create a build directory and use the 'scripts/configure' script to set up a custom build configuration. This script assembles CMake options and environment variables based on the build directory name, allowing for features like AddressSanitizer. ```bash mkdir build.clang-asan cd build.clang-asan ../scripts/configure (direnv allow) ninja ``` -------------------------------- ### Set SWIPL_PKG_NAME Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMakeLists.txt Determines the package name for SWI-Prolog based on the installation directory. Used for internal package management. ```cmake if(NOT SWIPL_PKG_NAME) if(SWIPL_INSTALL_DIR STREQUAL "swi-prolog") set(SWIPL_PKG_NAME ${SWIPL_INSTALL_DIR}) else() set(SWIPL_PKG_NAME "swipl") endif() endif() ``` -------------------------------- ### Benchmark SWI-Prolog WASM with Node.js Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/wasm/README.md Use this command to benchmark the WASM version of SWI-Prolog from the build directory using Node.js. ```bash node src/swipl.js -O ../bench/run.pl -s 10 ``` -------------------------------- ### Callback Function Example Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/wasm/demos/test.html A simple callback function that increments its input by one. Useful for demonstrating callback patterns. ```javascript function add_one(i) { return i+1; } ``` -------------------------------- ### Run a Specific SWI-Prolog Test Interactively Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Execute a single test file interactively by loading it with 'src/swipl' and then calling the test's entry point predicate. The entry point is typically the base name of the test file. ```prolog % src/swipl ../tests/core/test_arith.pl ?- test_arith. ``` -------------------------------- ### Initialize SWI-Prolog WASM Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/wasm/demos/bench.html Initializes SWI-Prolog with specified options and loads a Prolog file. Requires the SWIPL function to be available globally. ```javascript output = document.getElementById('output'); test_div = document.getElementById('tests'); table = document.getElementById('bench'); let Prolog; let Module; var options = { arguments: ["-q", "-O"], locateFile: (file) => '/wasm/' + file, on_output: print }; SWIPL(options).then((module) => { Module = module; Prolog = Module.prolog; Prolog.consult("test.pl").then(()=>{}); test_menu(); }); ``` -------------------------------- ### Determine SWIPL Library Directory Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/CMakeLists.txt Sets the LIBSWIPL_DIR based on installation preferences and CMake variables. Handles cases where SWIPL_INSTALL_IN_LIB is set or not. ```cmake if(SWIPL_INSTALL_IN_LIB) if(CMAKE_INSTALL_LIBDIR) set(LIBSWIPL_DIR ${CMAKE_INSTALL_LIBDIR}) else() set(LIBSWIPL_DIR lib) endif() else() set(LIBSWIPL_DIR ${SWIPL_INSTALL_ARCH_LIB}) endif() ``` -------------------------------- ### Inspecting Residual Goals with copy_term/3 Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/lib/clpfdlib.md Example showing how to use copy_term/3 to capture residual goals, making them available for further programmatic inspection. ```Prolog ?- X #= Y + Z, X in 0..5, copy_term([X,Y,Z], [X,Y,Z], Gs). Gs = [clpfd: (X in 0..5), clpfd: (Y+Z#=X)], X in 0..5, Y+Z#=X. ``` -------------------------------- ### Search Documentation with apropos/1 Source: https://github.com/swi-prolog/swipl-devel/blob/master/README.md Use the `apropos/1` predicate to search the documentation for a given query. This is useful for finding relevant predicates or topics. ```Prolog ?- apropos("query"). ``` -------------------------------- ### Define Facts and Rules for Debugging Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/textdebugger.md These are the initial facts and rules used in the debugging session. Ensure these are loaded into your Prolog environment before running the trace example. ```prolog is_a(rock1, rock). is_a(rock2, rock). color(rock1, red). noun(X, Type) :- is_a(X, Type). adjective(X, color, Value) :- color(X, Value). ``` -------------------------------- ### Get Keys from a Prolog Dict Source: https://context7.com/swi-prolog/swipl-devel/llms.txt Uses the `library(dicts)` to extract all keys from a given dictionary. This is helpful for iterating over dictionary elements or validating structure. ```prolog % Using library(dicts) for operations on dict lists :- use_module(library(dicts)). ?- dict_keys(person{name:john, age:30}, Keys). Keys = [age, name]. ``` -------------------------------- ### Synchronous Benchmark Execution Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/wasm/demos/bench.html Executes a single synchronous benchmark. It handles setup, timing, function calls, and cleanup. Iterations default to 1000 if not specified. ```javascript function run_benchmark(out, bm) { if ( !bm.iterations ) bm.iterations = 1000; const iter = bm.iterations; const data = bm.setup ? bm.setup.call(bm) : {}; time(out, bm, async () => { for(let i=0; i ReleaseNotes/RELNOTES-8.3.1 ``` -------------------------------- ### Query Prolog with Iterator Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/wasm/demos/test.html Demonstrates querying Prolog using a JavaScript iterator (`for..of`) to enumerate answers. This is an alternative to the `while(q.next().value)` loop shown in other examples. ```javascript /* Same as above, but using the JavaScript iterator (for..of) to enume ``` -------------------------------- ### Build Prolog Kernel as Static Library Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Use this option to build the Prolog kernel as a static library. ```cmake -DSWIPL_SHARED_LIB=OFF ``` -------------------------------- ### Build Static Library libswipl_static.a Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMAKE.md Enable building the static library `libswipl_static.a` in addition to the shared library. ```cmake -DSWIPL_STATIC_LIB=ON ``` -------------------------------- ### Conditional Documentation Build Source: https://github.com/swi-prolog/swipl-devel/blob/master/CMakeLists.txt Configures the build process for documentation if INSTALL_DOCUMENTATION is enabled. Includes HTML and man page generation. ```cmake if(INSTALL_DOCUMENTATION) include(Documentation) set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME Documentation) add_custom_target( doc ALL COMMENT "Build the documentation") add_custom_target( doc.html COMMENT "Build HTML documentation") add_dependencies(doc doc.html) add_custom_command( OUTPUT ${MAN_INDEX} COMMAND ${PROG_SWIPL} -f none --no-packs --home=${SWIPL_BUILD_HOME} -g "use_module(library(pldoc/man_index))" -g save_man_index -t halt DEPENDS swipl core doc.html VERBATIM) add_custom_target( man_index DEPENDS ${MAN_INDEX}) add_dependencies(doc man_index) install(FILES ${MAN_INDEX} DESTINATION ${SWIPL_INSTALL_DOC}) if(BUILD_PDF_DOCUMENTATION) add_custom_target( doc.pdf COMMENT "Build PDF documentation") add_dependencies(doc doc.pdf) endif() add_subdirectory(man) install(FILES packages/index.html DESTINATION ${SWIPL_INSTALL_DOC}/packages) endif(INSTALL_DOCUMENTATION) ``` -------------------------------- ### Get Calls and Returns for Tables Source: https://github.com/swi-prolog/swipl-devel/blob/master/tests/xsb/ptq/README.md Prolog code snippets for retrieving calls and returns from tables. These routines were used for outputting table data in the ptq testsuite. ```prolog get_calls/3 ``` ```prolog get_returns/2 ``` -------------------------------- ### JavaScript SWI-Prolog Integration Source: https://github.com/swi-prolog/swipl-devel/blob/master/src/wasm/demos/cbg.html Initializes SWI-Prolog in the browser using WebAssembly and sets up event handlers for user interactions. It loads scripts and calls the Prolog 'init' predicate. ```JavaScript let Prolog; let Module; var options = { arguments: ["-q"], locateFile: (file) => '/wasm/' + file, on_output: print }; SWIPL(options).then((module) => { Module = module; Prolog = Module.prolog; Prolog.load_scripts().then(() => Prolog.call("init")); }); function print(line, cls) { const node = document.createElement('span'); node.className = cls; node.textContent = line; output.appendChild(node); }; ``` -------------------------------- ### Automatic Rewriting of CLP(FD) Constraints Source: https://github.com/swi-prolog/swipl-devel/blob/master/man/lib/clpfdlib.md This example shows how CLP(FD) constraints are automatically rewritten to low-level arithmetic predicates when possible, ensuring good performance. ```prolog positive_integer(N) :- ( integer(N) -> N >= 1 ; N #>= 1 ). ```