Clingo
Loading...
Searching...
No Matches
Symbol Handling

Working with (evaluated) ground terms and related functions. More...

Typedefs

typedef int clingo_symbol_type_t
 Corresponding type to clingo_symbol_type.
 
typedef uint64_t clingo_symbol_t
 Type to represent a symbol.
 
typedef bool(* clingo_symbol_callback_t) (clingo_symbol_t const *symbols, size_t symbols_size, void *data)
 Callback function to inject symbols.
 

Enumerations

enum  clingo_symbol_type_e {
  clingo_symbol_type_number = 0 , clingo_symbol_type_supremum = 1 , clingo_symbol_type_infimum = 2 , clingo_symbol_type_string = 3 ,
  clingo_symbol_type_tuple = 4 , clingo_symbol_type_function = 5
}
 Enumeration of available symbol types. More...
 

Symbol Construction Functions

CLINGO_VISIBILITY_DEFAULT clingo_symbol_t clingo_symbol_create_infimum (void)
 Construct a symbol representing #inf.
 
CLINGO_VISIBILITY_DEFAULT clingo_symbol_t clingo_symbol_create_supremum (void)
 Construct a symbol representing #sup.
 
CLINGO_VISIBILITY_DEFAULT clingo_symbol_t clingo_symbol_create_number (int32_t number)
 Construct a symbol representing a number.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_create_number_str (clingo_lib_t *lib, char const *number, size_t size, clingo_symbol_t *symbol)
 Construct a symbol representing a number.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_create_string (clingo_lib_t *lib, char const *string, size_t size, clingo_symbol_t *symbol)
 Construct a symbol representing a string.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_create_id (clingo_lib_t *lib, char const *name, size_t size, bool is_positive, clingo_symbol_t *symbol)
 Construct a symbol representing an id.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_create_tuple (clingo_lib_t *lib, clingo_symbol_t const *arguments, size_t arguments_size, clingo_symbol_t *symbol)
 Construct a symbol representing a tuple.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_create_function (clingo_lib_t *lib, char const *name, size_t name_size, clingo_symbol_t const *arguments, size_t arguments_size, bool is_positive, clingo_symbol_t *symbol)
 Construct a symbol representing a function.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_parse_term (clingo_lib_t *lib, char const *string, size_t size, clingo_symbol_t *symbol)
 Parse a term in string form.
 
CLINGO_VISIBILITY_DEFAULT void clingo_symbol_acquire (clingo_symbol_t symbol)
 Acquire ownership of the given symbol.
 
CLINGO_VISIBILITY_DEFAULT void clingo_symbol_release (clingo_symbol_t symbol)
 Release ownership of the given symbol.
 

Symbol Inspection Functions

CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_number (clingo_symbol_t symbol, int32_t *number)
 Get the number of a symbol.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_name (clingo_symbol_t symbol, clingo_string_t *name)
 Get the name of a symbol.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_string (clingo_symbol_t symbol, clingo_string_t *string)
 Get the string of a symbol.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_is_positive (clingo_symbol_t symbol, bool *is_positive)
 Check whether a function or number is positive.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_arguments (clingo_symbol_t symbol, clingo_symbol_t const **arguments, size_t *arguments_size)
 Get the arguments of a symbol.
 
CLINGO_VISIBILITY_DEFAULT clingo_symbol_type_t clingo_symbol_type (clingo_symbol_t symbol)
 Get the type of a symbol.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_to_string (clingo_symbol_t symbol, clingo_string_builder_t *builder)
 Get the string representation of a symbol.
 

Symbol Comparison Functions

CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_equal (clingo_symbol_t a, clingo_symbol_t b)
 Check if two symbols are equal.
 
CLINGO_VISIBILITY_DEFAULT int clingo_symbol_compare (clingo_symbol_t a, clingo_symbol_t b)
 Check if a symbol is less than another symbol.
 
CLINGO_VISIBILITY_DEFAULT size_t clingo_symbol_hash (clingo_symbol_t symbol)
 Calculate a hash code of a symbol.
 

Detailed Description

Working with (evaluated) ground terms and related functions.

Note
Functions to create symbols are only thread-safe if library flags have been requested accordingly.

For an example, see symbol.c.

Typedef Documentation

◆ clingo_symbol_callback_t

typedef bool(* clingo_symbol_callback_t) (clingo_symbol_t const *symbols, size_t symbols_size, void *data)

Callback function to inject symbols.

Parameters
symbolsarray of symbols
symbols_sizesize of the symbol array
datauser data of the callback
Returns
whether the call was successful
See also
clingo_ground_callback_t

◆ clingo_symbol_t

typedef uint64_t clingo_symbol_t

Type to represent a symbol.

This includes numbers, strings, tuples, functions (including constants when arguments are empty), #inf and #sup.

Enumeration Type Documentation

◆ clingo_symbol_type_e

Enumeration of available symbol types.

Enumerator
clingo_symbol_type_number 

a numeric symbol, e.g., 1

clingo_symbol_type_supremum 

the #sup symbol

clingo_symbol_type_infimum 

the #inf symbol

clingo_symbol_type_string 

a string symbol, e.g., "a"

clingo_symbol_type_tuple 

a tuple symbol, e.g., (1, "a")`

clingo_symbol_type_function 

a function symbol, e.g., c, -c, or f(1,"a")

Function Documentation

◆ clingo_parse_term()

CLINGO_VISIBILITY_DEFAULT bool clingo_parse_term ( clingo_lib_t lib,
char const *  string,
size_t  size,
clingo_symbol_t symbol 
)

Parse a term in string form.

The result of this function is a symbol. The input term can contain unevaluated functions, which are evaluated during parsing.

Parameters
[in]liblibrary object storing the symbol
[in]stringthe string to parse
[in]sizethe size of the string
[out]symbolthe resulting symbol
Returns
the result code; might return one of the following codes:

◆ clingo_symbol_acquire()

CLINGO_VISIBILITY_DEFAULT void clingo_symbol_acquire ( clingo_symbol_t  symbol)

Acquire ownership of the given symbol.

Symbols not having any owners, are freed during garbage collection.

Parameters
[in]symbolthe resulting symbol

◆ clingo_symbol_arguments()

CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_arguments ( clingo_symbol_t  symbol,
clingo_symbol_t const **  arguments,
size_t *  arguments_size 
)

Get the arguments of a symbol.

Parameters
[in]symbolthe target symbol
[out]argumentsthe resulting arguments
[out]arguments_sizethe number of arguments
Returns
whether the arguments have been set
Examples
symbol.c.

◆ clingo_symbol_compare()

CLINGO_VISIBILITY_DEFAULT int clingo_symbol_compare ( clingo_symbol_t  a,
clingo_symbol_t  b 
)

Check if a symbol is less than another symbol.

Symbols are first compared by type. If the types are equal, the values are compared (where strings are compared using strcmp). Functions are first compared by signature and then lexicographically by arguments.

Parameters
[in]afirst symbol
[in]bsecond symbol
Returns
whether a < b
Examples
symbol.c.

◆ clingo_symbol_create_function()

CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_create_function ( clingo_lib_t lib,
char const *  name,
size_t  name_size,
clingo_symbol_t const *  arguments,
size_t  arguments_size,
bool  is_positive,
clingo_symbol_t symbol 
)

Construct a symbol representing a function.

Parameters
[in]liblibrary object storing the symbol
[in]namethe name of the function
[in]name_sizethe size of the name
[in]argumentsthe arguments of the function
[in]arguments_sizethe number of arguments
[in]is_positivewhether the symbol is_positive
[out]symbolthe resulting symbol
Returns
the result code; might return one of the following codes:
Examples
symbol.c.

◆ clingo_symbol_create_id()

CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_create_id ( clingo_lib_t lib,
char const *  name,
size_t  size,
bool  is_positive,
clingo_symbol_t symbol 
)

Construct a symbol representing an id.

Note
This is just a shortcut for clingo_symbol_create_function() with empty arguments.
Parameters
[in]liblibrary object storing the symbol
[in]namethe name
[in]sizethe size of the string
[in]is_positivewhether the symbol is positive
[out]symbolthe resulting symbol
Returns
the result code; might return one of the following codes:
Examples
symbol.c.

◆ clingo_symbol_create_infimum()

CLINGO_VISIBILITY_DEFAULT clingo_symbol_t clingo_symbol_create_infimum ( void  )

Construct a symbol representing #inf.

Returns
the resulting symbol

◆ clingo_symbol_create_number()

CLINGO_VISIBILITY_DEFAULT clingo_symbol_t clingo_symbol_create_number ( int32_t  number)

Construct a symbol representing a number.

Parameters
[in]numberthe number
Returns
the resulting symbol
Examples
symbol.c.

◆ clingo_symbol_create_number_str()

CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_create_number_str ( clingo_lib_t lib,
char const *  number,
size_t  size,
clingo_symbol_t symbol 
)

Construct a symbol representing a number.

Parameters
[in]liblibrary object storing the symbol
[in]numberthe number in form of a string
[in]sizethe size of the string
[out]symbolthe resulting symbol
Returns
whether the call was successful

◆ clingo_symbol_create_string()

CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_create_string ( clingo_lib_t lib,
char const *  string,
size_t  size,
clingo_symbol_t symbol 
)

Construct a symbol representing a string.

Parameters
[in]liblibrary object storing the symbol
[in]stringthe string
[in]sizethe size of the string
[out]symbolthe resulting symbol
Returns
the result code; might return one of the following codes:

◆ clingo_symbol_create_supremum()

CLINGO_VISIBILITY_DEFAULT clingo_symbol_t clingo_symbol_create_supremum ( void  )

Construct a symbol representing #sup.

Returns
the resulting symbol

◆ clingo_symbol_create_tuple()

CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_create_tuple ( clingo_lib_t lib,
clingo_symbol_t const *  arguments,
size_t  arguments_size,
clingo_symbol_t symbol 
)

Construct a symbol representing a tuple.

Parameters
[in]liblibrary object storing the symbol
[in]argumentsthe arguments of the function
[in]arguments_sizethe number of arguments
[out]symbolthe resulting symbol
Returns
the result code; might return one of the following codes:

◆ clingo_symbol_equal()

CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_equal ( clingo_symbol_t  a,
clingo_symbol_t  b 
)

Check if two symbols are equal.

Parameters
[in]afirst symbol
[in]bsecond symbol
Returns
whether a == b
Examples
symbol.c.

◆ clingo_symbol_hash()

CLINGO_VISIBILITY_DEFAULT size_t clingo_symbol_hash ( clingo_symbol_t  symbol)

Calculate a hash code of a symbol.

Parameters
[in]symbolthe target symbol
Returns
the hash code of the symbol
Examples
symbol.c.

◆ clingo_symbol_is_positive()

CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_is_positive ( clingo_symbol_t  symbol,
bool *  is_positive 
)

Check whether a function or number is positive.

Parameters
[in]symbolthe target symbol
[out]is_positivethe result
Returns
the result code

◆ clingo_symbol_name()

CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_name ( clingo_symbol_t  symbol,
clingo_string_t name 
)

Get the name of a symbol.

Note
The string is internalized and valid for the duration of the process.
Parameters
[in]symbolthe target symbol
[out]namethe resulting name
Returns
whether the name has been set

◆ clingo_symbol_number()

CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_number ( clingo_symbol_t  symbol,
int32_t *  number 
)

Get the number of a symbol.

Note
There is currently no explicit function to get representation of a number that does not fit an integer. For now, the clingo_symbol_to_string function should be used.
Parameters
[in]symbolthe target symbol
[out]numberthe resulting number
Returns
whether the number has been set

◆ clingo_symbol_release()

CLINGO_VISIBILITY_DEFAULT void clingo_symbol_release ( clingo_symbol_t  symbol)

Release ownership of the given symbol.

Symbols not having any owners, are freed during garbage collection.

Parameters
[in]symbolthe resulting symbol

◆ clingo_symbol_string()

CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_string ( clingo_symbol_t  symbol,
clingo_string_t string 
)

Get the string of a symbol.

Note
The string is internalized and valid for the duration of the process.
Parameters
[in]symbolthe target symbol
[out]stringthe resulting string
Returns
the result code

◆ clingo_symbol_to_string()

CLINGO_VISIBILITY_DEFAULT bool clingo_symbol_to_string ( clingo_symbol_t  symbol,
clingo_string_builder_t builder 
)

Get the string representation of a symbol.

Parameters
[in]symbolthe target symbol
[in]builderthe string builder
Returns
the result code
Examples
control.c, and symbol.c.

◆ clingo_symbol_type()

CLINGO_VISIBILITY_DEFAULT clingo_symbol_type_t clingo_symbol_type ( clingo_symbol_t  symbol)

Get the type of a symbol.

Parameters
[in]symbolthe target symbol
Returns
the type of the symbol