PyCLP Module Reference


This shall be called before calling any other function. This initialize Eclipse engine.

Raise :pyclpEx in case of failure or if eclipse engine is already initialized

This shutdown the Eclipse engine. After calling this function any operation on pyclp object or class could crash the program.

Raise :pyclpEx in case of failure or if eclipse engine is already shutdown


If after a cleanup it is called again pyclp.init() all terms created before the cleanup are not valid and they need to be rebuilt.


Cut all choice point of succeeded goal. Equivalent to void ec_cut_to_chp(ec_ref) It can be called only if previous resume call SUCCEED.

See also

cut function in ECLiPSe in C interface library

For an example see Cut Example


Implements unify as described in ec_unify This function shall be used only inside python function tha are called from ECLiPSe

Returns:pyclp.SUCCEED or pyclp.FAIL

Register a python function to be called from Eclipse using the predicate call_python. It shall be called after init()

E.g. call_python(<eclipse_name>,<list of terms.>).

The registered python function will be called as:

<func>(<list of terms>)

The registered function shall return pyclp.SUCCEED or any other value for reporting FAIL.

  • eclipse_name – str or byte string. Name to be used to with predicate call_python_function
  • func – It shall be the function to be called.

Resume Eclipse engine. Implements the functionality of ec_resume,ec_resume1,ec_resume2. It accepts optional argument in_term. Used to return a value to the prolog predicate yield/2

Parameters:in_term (PList, Atom, Compound) –

Optional argument in_term. Used to return a value to the prolog predicate yield/2

Return type:tuple
Returns:(pyclp.SUCCEED,None) if execution succeed (equivalent to True). In this case it is possible to call pyclp.cut()

(pyclp.FAIL,None) if the goal fails.

(pyclp.FLUSHIO,stream_number) if some data is present in stream identified by stream_number

(pyclp.WAITIO,stream_number) if eclipse engine try to read data from stream identified by stream_number

(pyclp.YIELD, yield_returned_value) in case of predicate call yield/2.

(pyclp.THROW, Term TagExit) an event have been thrown and no one have catched it exit_block/1.


After receiving FLUSHIO or WAITIO a new resume shall be issued before creating variable or calling post_goal to complete the goal execution and avoid unpredictable behavior.


PyCLP have a different behavior compared to C/C++/Java default libraries provided by ECLiPsE. Standard resume execution destroys all the terms built before the execution of resume function while PyCLP is preserving them creating a reference and storing the created term in this.

See also

Resume functions in ECLiPSe in C interface library.
class pyclp.Atom(atom_id)

Class to create Atom.

Parameters:atom_id (string) – atom name
Inherited-members :

Convert to string for pretty printing

class pyclp.Compound(functor_string, *args)

Class to create compound terms.

  • functor_string – A string with functor name.
  • args – Any number of arguments of type integer, float,string and PList, Atom, Compound

len(arg) function called with a Compound object return the arity of compound term.

This class support iterator protocol this means that you can iterate over term arguments or get the arguments by index protocol:


for x in my_compound:
print(my_compound[0])  # Print first argument.


As for all other terms it is not possible to change their values.

Inherited-members :
__str__() <==> str(x)
Returns:string storing name of functor
Returns:arity of Compound object.
class pyclp.Var

Class to create Prolog variable.

Inherited-members :
Returns:Return pretty print string of object unified to this variable. If variable is uninstantiated it returns ‘_’
Return type:integer, float, string, PList, Atom, Compound, None (if var is uninstantiated)
class pyclp.PList

Class to create and read Prolog lists.

When creating a new instance a list or tuple shall be provided. string,float and integer are automatically transformed in term as in Compound class. This class support iterator protocol this means that you can loop on the list as for python list


for x in my_list:

This class support retrieving values by indexing.




As for all other terms it is not possible to change their values.

Special cases

Empty prolog list can be created with PList([]) To check that a returned PList is the empty list it avaiable the method pyclp.PList.isNil()

Head Tail

In prolog it is possible to define a list using the operator |

Example of prolog list and head tail decomposition:

%Prolog list example
%Also regular list have a tail: []
%All list can be decomposed recursively as head tail couple

Pretty printing of the list


Convert a PList in a python list and the tail.


prolog              python
[1,2,3,f(1,2)]  --> ([1,2,3,Compound('f',1,2)],PList([]))
[1,2,3|A]       --> ([1,2,3],Var())
[1,2,3|dummy]   --> ([1,2,3],Atom('dummy'))
Returns:a tuple (list,tail). First element is a python list containing each element of prolog list converted to a pyclp object second element is a pyclp object representing the tail of prolog list.

Check if the PList is the nil list –> []

Returns:True if it is the empty list
Returns:Iterator that returns a tuple (head,tail) where head is a element of the list and tail is the remaining list

Deprecated since version 1.5.

Replaced by PList.iterHeadTail()


Post goal

class pyclp.Stream(name)

Class to support streams to and from ECLiPSe. This is class is derived from io.RawIOBase.

Parameters:name – string containing stream name of a previously opened stream by ECLiPSe program. See: Embedded C stream api and get_stream/2


The following stream are already opened: ‘input’, ‘output’, ‘error’, ‘warning_output’, ‘log_output’, ‘stdin’, ‘stdout’, ‘stderr’, ‘null’.

Raises IOError:if name is not matching a previously open stream by open/3 and open/4

Read all bytes from stream

Parameters:n – Number of bytes to be read if omitted or equal to -1 it will return all avaiable bytes.
Returns:bytes object

Write a bytes object to stream. :type buffer: bytes object. :return: number of bytes written


Read all available bytes equivalent to

exception pyclp.pyclpEx

Previous topic


Next topic


This Page