Skip to content

Indexed predicates in Prolog

License

Notifications You must be signed in to change notification settings

CodiePP/predidx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

building the module for SWI Prolog

Indexed Predicates

Installation

aclocal --force && autoheader --force && autoconf --force
./configure
make swi

then, I copy the results to a module directory that SWI Prolog finds:

mkdir -v -p ~/lib/sbcl
cp -v predidx-* ~/lib/sbcl/predidx
cp -v src/predidx.qlf ~/lib/sbcl/

Update the swipl config file:

  • SWI-Prolog version < 8.1.15
    (add the following to ~/.swiplrc)
echo ":- assertz(file_search_path(sbcl,'${HOME}/lib/sbcl'))." >> ${HOME}/.swiplrc
  • SWI-Prolog version >= 8.1.15
    run the following from the terminal
echo ":- assertz(file_search_path(sbcl,'${HOME}/lib/sbcl'))." >> ${HOME}/.config/swi-prolog/init.pl

Description

Prolog predicates in tables indexed by their row number. Behind the scenes this is the same as an array of a structure type in C.

tbl_create('table_name', [max_rows(1_000_000), realloc_rows(10_000)], Tid).

so, indexing from 0 to 999_999 is OK

tbl_has(Tid, 42).
tbl_has(Tid, X). % enumerate
tbl_get(Tid, 42, X).
tbl_set(Tid, 42, 'something').
tbl_unset(Tid, 42).
tbl_has(Tid, 42).  % => false

example usage

:- use_module(sbcl(predidx)).

t1 :-
  Tname = 'likes',
  tbl_create(Tname, [max_rows(10000),realloc_rows(100),structure(['int32'])], Tid),
  format("created table '~a' with id = ~p~n", [Tname, Tid]).

About

Indexed predicates in Prolog

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Contributors 2

  •  
  •