# Higher-order predicates

**Author(s):**Daniel Cabeza, Manuel Carro, Edison Mera.

This library implements a few basic higher-order predicates. These add functionality to the basic higher-order functionality of Ciao. Examples of the latter are:

Using pred(1):

list(L, functor(_,2)) list(L, >(0))

Using pred(2):

## Usage and interface

**Library usage:**`:- use_module(library(hiordlib)).`**Exports:****Imports:***System library modules:*`assertions/native_props`.*Packages:*`prelude`,`nonpure`,`assertions`,`basicmodes`,`nativeprops`,`dcg`,`fsyntax`,`hiord`,`unittestdecls`.

## Documentation on exports

**Usage:**`map(LList,Op,RList)`

Examples of use:

map([1,3,2], arg(f(a,b,c,d)), [a,c,b]) or map([1,3,2], nth([a,b,c,d]), [a,c,b]) map(["D","C"], append("."), ["D.","C."])

*Meta-predicate*with arguments:

`map(?,(pred 2),?)`.

**General properties:**

**Test:**`map(A,B,C)`

*If the following properties should hold at call time:*

(term_basic:= /2)term_basic:A=[1,3,2]

(term_basic:= /2)term_basic:B=arg(f(a,b,c,d))*then the following properties should hold upon exit:*

(term_basic:= /2)term_basic:C=[a,c,b]*then the following properties should hold globally:*

(native_props:not_fails/1)All the calls of the form map(A,B,C) do not fail.

(native_props:is_det/1)All calls of the form map(A,B,C) are deterministic.

**Test:**`map(A,B,C)`

*If the following properties should hold at call time:*

(term_basic:= /2)term_basic:A=[1,3,2]

(term_basic:= /2)term_basic:B=nth([a,b,c,d])*then the following properties should hold upon exit:*

(term_basic:= /2)term_basic:C=[a,c,b]*then the following properties should hold globally:*

(native_props:not_fails/1)All the calls of the form map(A,B,C) do not fail.

(native_props:is_det/1)All calls of the form map(A,B,C) are deterministic.

**Test:**`map(A,B,C)`

*If the following properties should hold at call time:*

(term_basic:= /2)term_basic:A=[[68],[67]]

(term_basic:= /2)term_basic:B=append([46])*then the following properties should hold upon exit:*

(term_basic:= /2)term_basic:C=[[68,46],[67,46]]*then the following properties should hold globally:*

(native_props:not_fails/1)All the calls of the form map(A,B,C) do not fail.

(native_props:is_det/1)All calls of the form map(A,B,C) are deterministic.

**Usage:**`map(LList,Op,RList,Tail)`

DCG version of map.

*Meta-predicate*with arguments:

`map(?,(pred 3),?,?)`.

**General properties:**

**Test:**`map(A,B,C,D)`

*If the following properties should hold at call time:*

(term_basic:= /2)term_basic:A=[1,3,2]

(term_basic:= /2)term_basic:B=((L,[E|T],T):-arg(L,f(a,b,c,d),E))

(term_basic:= /2)term_basic:D=[x,y]*then the following properties should hold upon exit:*

(term_basic:= /2)term_basic:C=[a,c,b,x,y]*then the following properties should hold globally:*

(native_props:not_fails/1)All the calls of the form map(A,B,C,D) do not fail.

(native_props:is_det/1)All calls of the form map(A,B,C,D) are deterministic.

*Meta-predicate*with arguments:

`map(?,?,(pred 4),?,?)`.

*Meta-predicate*with arguments:

`map(?,?,?,(pred 5),?,?)`.

**Usage:**`foldl(List,Seed,Op,Result)`

Example of use:

?- foldl(["daniel","cabeza","gras"], "", (”(X,Y,Z) :- append(X, " "||Y, Z)), R). R = "daniel cabeza gras " ?

*Meta-predicate*with arguments:

`foldl(?,?,(pred 3),?)`.

**Usage:**`minimum(List,SmallerThan,Minimum)`

Minimum is the smaller in the nonempty list List according to the relation SmallerThan: `SmallerThan(X, Y)` succeeds iff X is smaller than Y.

*The following properties should hold at call time:*

(term_typing:nonvar/1)SmallerThan is currently a term which is not a free variable.

(basic_props:list/1)List is a list.

(basic_props:callable/1)SmallerThan is a term which represents a goal, i.e., an atom or a structure.

(basic_props:term/1)Minimum is any term.

*Meta-predicate*with arguments:

`minimum(?,(pred 2),?)`.

**Usage:**`split(List,Condition,Left,Right)`

Divides List in two list, where Left contains the elements for which the call to Condition succeeds, and Right the remaining elements.

*The following properties should hold at call time:*

(term_typing:nonvar/1)List is currently a term which is not a free variable.

(term_typing:nonvar/1)Condition is currently a term which is not a free variable.

(basic_props:list/1)List is a list.

(basic_props:callable/1)Condition is a term which represents a goal, i.e., an atom or a structure.

(basic_props:term/1)Left is any term.

(basic_props:term/1)Right is any term.*The following properties should hold upon exit:*

(basic_props:list/1)List is a list.

(basic_props:callable/1)Condition is a term which represents a goal, i.e., an atom or a structure.

(basic_props:list/1)Left is a list.

(basic_props:list/1)Right is a list.

*Meta-predicate*with arguments:

`split(?,(pred 1),?,?)`.

**General properties:**

**Test:**`split(A,B,C,D)`

*If the following properties should hold at call time:*

(term_basic:= /2)term_basic:A=[1,2,3,4,5,6]

(term_basic:= /2)term_basic:B= >(4)*then the following properties should hold upon exit:*

(term_basic:= /2)term_basic:C=[5,6]

(term_basic:= /2)term_basic:D=[1,2,3,4]*then the following properties should hold globally:*

(native_props:not_fails/1)All the calls of the form split(A,B,C,D) do not fail.