Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "accessors"

Title:Relational predicate accessors generators that allow easy and efficient access to term arguments by name.
Rating:Not rated. Create the first rating!
Latest version:1.1.2
SHA1 sum:bb45d6bdc0ca9ffb449bcb315a993a0c7de9a00f
Author:Luiz Fernando https://github.com/LuizFBR
Maintainer:Luiz Fernando https://github.com/LuizFBR
Packager:Luiz Fernando https://github.com/LuizFBR
Home page:https://github.com/LuizFBR/accessors
Download URL:https://github.com/LuizFBR/accessors.git

Reviews

No reviews. Create the first review!.

Details by download location

VersionSHA1#DownloadsURL
1.1.2bb45d6bdc0ca9ffb449bcb315a993a0c7de9a00f2https://github.com/LuizFBR/accessors.git
1.0.100bb08757620ad9ba8d39c2494d4138dfd72edd82https://github.com/LuizFBR/accessors.git
1.0.03f103c09002fb2d7770e1a12f36f059b172d9a7f1https://github.com/LuizFBR/accessors.git

Prolog Automatic Accessors

Relational predicate accessors generators that allows easy and efficient access to term and pairs-lists arguments by name.

This library provides the user with the :- derive_accessors/1 and :- derive_accessors/2 prolog directives that automatically generate relational predicates that associate a predicate/pairs-list with each of its arguments.

The choice of imperative naming for :- derive_accessors was to keep this library user-friendly for users who are used to imperative programming.

To-do:

  • Test for purity;

Installation

To install the fld library, type the following in the SWI-Prolog shell:

? - pack_install('accessors').
  true.

or, alternatively, you can install directly from this github repo:

?- pack_install('https://github.com/LuizFBR/accessors.git').
  true.

Example

Predicate accessors

The directive call:

:- derive_accessors(pred(a,b,c)).

will generate the following static predicate accessors globally:

pred_a(pred(A,_,_),A).
pred_b(pred(_,B,_),B).
pred_c(pred(_,_,C),C).

Pairs-List Accessors

The directive call:

:- derive_accessors(pred, [a,b,c]).

will generate the following static pairs-list accessors at compile-time:

fact_a(_ListPair,_a) :-
    member(a-_a,_ListPair).
fact_b(_ListPair,_b) :-
    member(b-_b,_ListPair).
fact_c(_ListPair,_c) :-
    member(c-_c,_ListPair).

Importing

Import this module with

:- use_module(library(accessors)).

Dependencies

This library depends on Markus Triskas' clpfd library:

https://www.swi-prolog.org/man/clpfd.html

Contents of pack "accessors"

Pack contains 4 files holding a total of 5.2K bytes.