clingo.symbol
Functions and classes for symbol manipulation.
Examples
>>> from clingo.core import Library
>>> from clingo.symbol import Function, Number, parse_term
>>>
>>> lib = Library()
>>>
>>> num = Number(lib, 42)
>>> num.number
42
>>> fun = Function(lib, "f", [num])
>>> fun.name
'f'
>>> [ str(arg) for arg in fun.arguments ]
['42']
>>> parse_term(lib, str(fun)) == fun
True
>>> parse_term(lib, 'p(1+2)')
p(3)
Construct a function symbol.
This includes constants and tuples. Constants have an empty argument list and
tuples have an empty name. Functions can represent classically negated atoms.
Argument is_positive
has to be set to False
to represent such atoms.
Arguments:
- lib: A library object to store the function in.
- name: The name of the function.
- arguments: The arguments in the form of a list of symbols.
- is_positive: Whether the function is positive.
Construct a numeric symbol given a number.
Arguments:
- lib: A library object to store the number in.
- number: The given number.
Construct a string symbol given a string.
Arguments:
- lib: A library object to store the string in.
- string: The given string.
Represents a clingo symbol.
This includes #inf
and #sup
, numbers, strings, tuples, functions (including
constants with len(arguments) == 0
.
Symbol objects implement Python's rich comparison operators and are ordered like in clingo. They can also be used as keys in dictionaries. Their string representation corresponds to their clingo representation.
Note that this class does not have a constructor. Instead there are the
preconstructed symbols Infimum
and Supremum
and the functions Number
,
String
, Tuple_
, and Function
to construct symbol objects.
Enumeration of symbols types.
Construct a tuple symbol.
This is a shortcut for Function(lib, "", arguments)
.
Arguments:
- lib: A library object to store the tuple in.
- arguments: The arguments in form of a list of symbols.
Parse the given string using clingo's term parser for ground terms.
The function also evaluates arithmetic functions.
Arguments:
- lib: A library object to store parsed symbols in.
- string: The string to be parsed.