PyCLP Module Reference

pyclp.init()

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

Returns:False if init succeed. True if init fails
pyclp.cleanup()

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

Returns:False if cleanup succeed. True if cleanup fails

Warning

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.

pyclp.cut()

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

ec_cut_to_chp
cut function in ECLiPSe in C interface library

For an example see Cut Example

pyclp.resume(in_term=None)

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.PYIELD, yield_returned_value) in case of predicate call yield/2.

Warning

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.

Note

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

ec_resume,ec_resume1,ec_resume2
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 :
 
__str__()

Convert to string for pretty printing

class pyclp.Compound(functor_string, *args)

Class to create compound terms.

Parameters:
  • 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:

Example:

init()
my_compound=Compound("test",1,"dummy")
for x in my_compound:
    print(x)
print(my_compound[0])  # Print first argument.

Warning

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

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

Class to create Prolog variable.

Inherited-members :
 
__str__()
Returns:Return pretty print string of object unified to this varible. If variable is uninstantiated it returns ‘_’
value()
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

Example:

init()
my_list=PList([1,2,3])
for x in my_list:
    print(x)

This class support retrieving values by indexing.

Example:

init()
my_list=PList([1,2,3])
print(my_list[3])

Warning

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

__str__()

Pretty printing of the list

iterheadtail()
Returns:Iterator that returns a tuple (head,tail) where head is a element of the list and tail is the remaining list
post_goal()

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

Note

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(n=-1)

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(buffer)

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

readall

Read all available bytes equivalent to pyclp.read()

exception pyclp.pyclpEx

Previous topic

Installation

Next topic

Examples

This Page