Documentation ¶
Overview ¶
Package predicate provides a set of predicates for use with the logic module.
Index ¶
- Constants
- Variables
- func Abolish(vm *engine.VM, indicator engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
- func Accounts(ctx context.Context, authQueryService types.AuthQueryService, ...) func() (lo.Tuple2[sdk.AccountI, error], bool)
- func AllBalancesSorted(ctx context.Context, bankKeeper types.BankKeeper, bech32Addr sdk.AccAddress) sdk.Coins
- func Asserta(vm *engine.VM, clause engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
- func Assertz(vm *engine.VM, clause engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
- func AtomicListConcat2(vm *engine.VM, list, atom engine.Term, k engine.Cont, env *engine.Env) *engine.Promise
- func AtomicListConcat3(vm *engine.VM, list, sep, atom engine.Term, k engine.Cont, env *engine.Env) *engine.Promise
- func BankBalances(vm *engine.VM, address, balances engine.Term, cont engine.Cont, ...) *engine.Promise
- func BankLockedBalances(vm *engine.VM, address, balances engine.Term, cont engine.Cont, ...) *engine.Promise
- func BankSpendableBalances(vm *engine.VM, address, balances engine.Term, cont engine.Cont, ...) *engine.Promise
- func Bech32Address(_ *engine.VM, address, bech32 engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
- func BlockHeader(vm *engine.VM, header engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
- func BlockHeight(vm *engine.VM, height engine.Term, cont engine.Cont, env *engine.Env) *engine.Promisedeprecated
- func BlockTime(vm *engine.VM, time engine.Term, cont engine.Cont, env *engine.Env) *engine.Promisedeprecated
- func ChainID(vm *engine.VM, chainID engine.Term, cont engine.Cont, env *engine.Env) *engine.Promisedeprecated
- func CoinsToTerm(coins sdk.Coins) engine.Term
- func Consult(vm *engine.VM, file engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
- func CryptoDataHash(vm *engine.VM, data, hash, options engine.Term, cont engine.Cont, ...) *engine.Promise
- func CurrentOutput(vm *engine.VM, output engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
- func DIDComponents(vm *engine.VM, did, components engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
- func ECDSAVerify(_ *engine.VM, key, data, sig, options engine.Term, cont engine.Cont, ...) *engine.Promise
- func EDDSAVerify(_ *engine.VM, key, data, sig, options engine.Term, cont engine.Cont, ...) *engine.Promise
- func HexBytes(vm *engine.VM, hexa, bts engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
- func IterMap[U any, V any](next func() (U, bool), f func(U) V) func() (V, bool)
- func JSONProlog(vm *engine.VM, j, p engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
- func JSONRead(vm *engine.VM, stream, term engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
- func JSONWrite(_ *engine.VM, stream, term engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
- func LockedCoinsSorted(ctx context.Context, bankKeeper types.BankKeeper, bech32Addr sdk.AccAddress) sdk.Coins
- func Open(vm *engine.VM, sourceSink, mode, stream, options engine.Term, k engine.Cont, ...) *engine.Promise
- func Open3(vm *engine.VM, sourceSink, mode, stream engine.Term, k engine.Cont, ...) *engine.Promise
- func ReadString(vm *engine.VM, stream, length, result engine.Term, cont engine.Cont, ...) *engine.Promise
- func ReadTerm3(vm *engine.VM, streamOrAlias, t, options engine.Term, k engine.Cont, ...) *engine.Promise
- func Retract(vm *engine.VM, clause engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
- func SortBalances(balances sdk.Coins)
- func SourceFile(vm *engine.VM, file engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
- func SpendableCoinsSorted(ctx context.Context, bankKeeper types.BankKeeper, bech32Addr sdk.AccAddress) sdk.Coins
- func StringBytes(_ *engine.VM, str, bts, encodingTerm engine.Term, cont engine.Cont, ...) *engine.Promise
- func TermToAtom(vm *engine.VM, term, atom engine.Term, k engine.Cont, env *engine.Env) *engine.Promise
- func URIEncoded(_ *engine.VM, component, decoded, encoded engine.Term, cont engine.Cont, ...) *engine.Promise
- func WriteTerm3(vm *engine.VM, streamOrAlias, t, options engine.Term, k engine.Cont, ...) *engine.Promise
Constants ¶
const DIDPrefix = "did"
DIDPrefix is the prefix for a DID.
Variables ¶
var ( // AtomSyntaxErrorJSON represents a syntax error related to JSON. AtomSyntaxErrorJSON = engine.NewAtom("json") // AtomMalformedJSON represents a specific type of JSON syntax error where the JSON is malformed. AtomMalformedJSON = engine.NewAtom("malformed_json") // AtomEOF represents a specific type of JSON syntax error where an unexpected end-of-file occurs. AtomEOF = engine.NewAtom("eof") // AtomUnknown represents an unknown or unspecified syntax error. AtomUnknown = engine.NewAtom("unknown") // AtomValidJSONNumber is the atom denoting a valid JSON number. AtomValidJSONNumber = engine.NewAtom("json_number") )
Functions ¶
func Abolish ¶
func Abolish(vm *engine.VM, indicator engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
Abolish is a predicate that abolishes a predicate from the database. Removes all clauses of the predicate designated by given predicate indicator Name/Arity.
Signature ¶
abolish(+PredicateIndicator)
Where:
- PredicateIndicator is the indicator of the predicate to abolish.
func Accounts ¶
func Accounts(ctx context.Context, authQueryService types.AuthQueryService, unpacker cdctypes.AnyUnpacker) func() (lo.Tuple2[sdk.AccountI, error], bool)
Accounts returns an iterator that iterates over all accounts.
func AllBalancesSorted ¶
func AllBalancesSorted(ctx context.Context, bankKeeper types.BankKeeper, bech32Addr sdk.AccAddress) sdk.Coins
AllBalancesSorted returns the list of balances for the given address, sorted by coin denomination.
func Asserta ¶
Asserta is a predicate that asserts a clause into the database as the first clause of the predicate.
Signature ¶
asserta(+Clause)
Where:
- Clause is the clause to assert into the database.
func Assertz ¶
Assertz is a predicate that asserts a clause into the database as the last clause of the predicate.
Signature ¶
assertz(+Clause)
Where:
- Clause is the clause to assert into the database.
func AtomicListConcat2 ¶
func AtomicListConcat2(vm *engine.VM, list, atom engine.Term, k engine.Cont, env *engine.Env) *engine.Promise
AtomicListConcat2 is a predicate that unifies an Atom with the concatenated elements of a List.
Signature ¶
atomic_list_concat(+List, ?Atom)
where:
- List is a list of strings, atoms, integers, floating point numbers or non-integer rationals
- Atom is an Atom representing the concatenation of the elements of List
func AtomicListConcat3 ¶
func AtomicListConcat3(vm *engine.VM, list, sep, atom engine.Term, k engine.Cont, env *engine.Env) *engine.Promise
AtomicListConcat3 is a predicate that unifies an Atom with the concatenated elements of a List using a given separator.
The atomic_list_concat/3 predicate creates an atom just like atomic_list_concat/2, but inserts Separator between each pair of inputs.
Signature ¶
atomic_list_concat(+List, +Separator, ?Atom)
where:
- List is a list of strings, atoms, integers, floating point numbers or non-integer rationals
- Separator is an atom (possibly empty)
- Atom is an Atom representing the concatenation of the elements of List
func BankBalances ¶
func BankBalances(vm *engine.VM, address, balances engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
BankBalances is a predicate which unifies the given terms with the list of balances (coins) of the given account.
The signature is as follows:
bank_balances(?Address, ?Balances)
where:
- Address represents the account address (in Bech32 format).
- Balances represents the balances of the account as a list of pairs of coin denomination and amount.
Examples: ¶
# Query the balances of the account. - bank_balances('axone1ffd5wx65l407yvm478cxzlgygw07h79sw4jwpa', X). # Query the balances of all accounts. The result is a list of pairs of account address and balances. - bank_balances(X, Y). # Query the first balance of the given account by unifying the denomination and amount with the given terms. - bank_balances('axone1ffd5wx65l407yvm478cxzlgygw07h79sw4jwpa', [-(D, A), _]).
func BankLockedBalances ¶
func BankLockedBalances(vm *engine.VM, address, balances engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
BankLockedBalances is a predicate which unifies the given terms with the list of locked coins of the given account.
The signature is as follows:
bank_locked_balances(?Address, ?Balances)
where:
- Address represents the account address (in Bech32 format).
- Balances represents the locked balances of the account as a list of pairs of coin denomination and amount.
Examples: ¶
# Query the locked coins of the account. - bank_locked_balances('axone1ffd5wx65l407yvm478cxzlgygw07h79sw4jwpa', X). # Query the locked balances of all accounts. The result is a list of pairs of account address and balances. - bank_locked_balances(X, Y). # Query the first locked balances of the given account by unifying the denomination and amount with the given terms. - bank_locked_balances('axone1ffd5wx65l407yvm478cxzlgygw07h79sw4jwpa', [-(D, A), _]).
func BankSpendableBalances ¶
func BankSpendableBalances(vm *engine.VM, address, balances engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
BankSpendableBalances is a predicate which unifies the given terms with the list of spendable coins of the given account.
The signature is as follows:
bank_spendable_balances(?Address, ?Balances)
where:
- Address represents the account address (in Bech32 format).
- Balances represents the spendable balances of the account as a list of pairs of coin denomination and amount.
Examples: ¶
# Query the spendable balances of the account. - bank_spendable_balances('axone1ffd5wx65l407yvm478cxzlgygw07h79sw4jwpa', X). # Query the spendable balances of all accounts. The result is a list of pairs of account address and balances. - bank_spendable_balances(X, Y). # Query the first spendable balances of the given account by unifying the denomination and amount with the given terms. - bank_spendable_balances('axone1ffd5wx65l407yvm478cxzlgygw07h79sw4jwpa', [-(D, A), _]).
func Bech32Address ¶
func Bech32Address(_ *engine.VM, address, bech32 engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
Bech32Address is a predicate that convert a bech32 encoded string into base64 bytes and give the address prefix, or convert a prefix (HRP) and base64 encoded bytes to bech32 encoded string.
Signature ¶
bech32_address(-Address, +Bech32) is det bech32_address(+Address, -Bech32) is det
where:
- Address is a pair of the HRP (Human-Readable Part) which holds the address prefix and a list of numbers ranging from 0 to 255 that represent the base64 encoded bech32 address string.
- Bech32 is an Atom or string representing the bech32 encoded string address
func BlockHeader ¶
func BlockHeader(vm *engine.VM, header engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
BlockHeader is a predicate which unifies the given term with the current block header.
Signature ¶
block_header(?Header) is det
where:
- Header is a Dict representing the current chain header at the time of the query.
func BlockHeight
deprecated
func BlockHeight(vm *engine.VM, height engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
BlockHeight is a predicate which unifies the given term with the current block height.
Signature ¶
block_height(?Height) is det
where:
- Height represents the current chain height at the time of the query.
Deprecated: Use the `block_header/1` predicate instead.
func ChainID
deprecated
ChainID is a predicate which unifies the given term with the current chain ID. The signature is:
The signature is as follows:
chain_id(?ID)
where:
- ID represents the current chain ID at the time of the query.
Deprecated: Use the `block_header/1` predicate instead.
func CoinsToTerm ¶
CoinsToTerm converts the given coins to a term of the form:
[-(Denom, Amount), -(Denom, Amount), ...]
func Consult ¶
Consult is a predicate which read files as Prolog source code.
Signature ¶
consult(+Files) is det
where:
- Files represents the source files to be loaded. It can be an atom or a list of atoms representing the source files.
The Files argument are typically URIs that point to the sources file to be loaded through the Virtual File System (VFS). Please refer to the open/4 predicate for more information about the VFS.
func CryptoDataHash ¶
func CryptoDataHash( vm *engine.VM, data, hash, options engine.Term, cont engine.Cont, env *engine.Env, ) *engine.Promise
CryptoDataHash is a predicate that computes the Hash of the given Data using different algorithms.
The signature is as follows:
crypto_data_hash(+Data, -Hash, +Options) is det crypto_data_hash(+Data, +Hash, +Options) is det
Where:
- Data represents the data to be hashed, given as an atom, or code-list.
- Hash represents the Hashed value of Data, which can be given as an atom or a variable.
- Options are additional configurations for the hashing process. Supported options include: encoding(+Format) which specifies the encoding used for the Data, and algorithm(+Alg) which chooses the hashing algorithm among the supported ones (see below for details).
For Format, the supported encodings are:
- utf8 (default), the UTF-8 encoding represented as an atom.
- text, the plain text encoding represented as an atom.
- hex, the hexadecimal encoding represented as an atom.
- octet, the raw byte encoding depicted as a list of integers ranging from 0 to 255.
For Alg, the supported algorithms are:
- sha256 (default): The SHA-256 algorithm.
- sha512: The SHA-512 algorithm.
- md5: (insecure) The MD5 algorithm.
Note: Due to the principles of the hash algorithm (pre-image resistance), this predicate can only compute the hash value from input data, and cannot compute the original input data from the hash value.
Examples: ¶
# Compute the SHA-256 hash of the given data and unify it with the given Hash. - crypto_data_hash('Hello AXONE', Hash). # Compute the SHA-256 hash of the given hexadecimal data and unify it with the given Hash. - crypto_data_hash('9b038f8ef6918cbb56040dfda401b56b...', Hash, encoding(hex)). # Compute the SHA-256 hash of the given hexadecimal data and unify it with the given Hash. - crypto_data_hash([127, ...], Hash, encoding(octet)).
func CurrentOutput ¶
func CurrentOutput(vm *engine.VM, output engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
CurrentOutput is a predicate that unifies the given term with the current output stream.
Signature ¶
current_output(-Stream) is det
where:
- Stream represents the current output stream.
This predicate connects to the default output stream available for user interactions, allowing the user to perform write operations.
The outcome of the stream's content throughout the execution of a query is provided as a string within the user_output field in the query's response. However, it's important to note that the maximum length of the output is constrained by the max_query_output_size setting, meaning only the final max_query_output_size bytes (not characters) of the output are included in the response.
func DIDComponents ¶
func DIDComponents(vm *engine.VM, did, components engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
DIDComponents is a predicate which breaks down a DID into its components according to the W3C DID specification.
The signature is as follows:
did_components(+DID, -Components) is det did_components(-DID, +Components) is det
where:
- DID represent DID URI, given as an Atom, compliant with W3C DID specification.
- Components is a compound Term in the format did(Method, ID, Path, Query, Fragment), aligned with the DID syntax, where: Method is the method name, ID is the method-specific identifier, Path is the path component, Query is the query component and Fragment is the fragment component. Values are given as an Atom and are url encoded. For any component not present, its value will be null and thus will be left as an uninstantiated variable.
Examples: ¶
# Decompose a DID into its components. - did_components('did:example:123456?versionId=1', did_components(Method, ID, Path, Query, Fragment)). # Reconstruct a DID from its components. - did_components(DID, did_components('example', '123456', _, 'versionId=1', _42)).
func ECDSAVerify ¶
func ECDSAVerify(_ *engine.VM, key, data, sig, options engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
ECDSAVerify determines if a given signature is valid as per the ECDSA algorithm for the provided data, using the specified public key.
The signature is as follows:
ecdsa_verify(+PubKey, +Data, +Signature, +Options), which is semi-deterministic.
Where:
PubKey is the 33-byte compressed public key, as specified in section 4.3.6 of ANSI X9.62.
Data is the hash of the signed message, which can be either an atom or a list of bytes.
Signature represents the ASN.1 encoded signature corresponding to the Data.
Options are additional configurations for the verification process. Supported options include: encoding(+Format) which specifies the encoding used for the data, and type(+Alg) which chooses the algorithm within the ECDSA family (see below for details).
For Format, the supported encodings are:
- hex (default), the hexadecimal encoding represented as an atom.
- octet, the plain byte encoding depicted as a list of integers ranging from 0 to 255.
- text, the plain text encoding represented as an atom.
- utf8 (default), the UTF-8 encoding represented as an atom.
For Alg, the supported algorithms are:
- secp256r1 (default): Also known as P-256 and prime256v1.
- secp256k1: The Koblitz elliptic curve used in Bitcoin's public-key cryptography.
Examples: ¶
# Verify a signature for hexadecimal data using the ECDSA secp256r1 algorithm. - ecdsa_verify([127, ...], '9b038f8ef6918cbb56040dfda401b56b...', [23, 56, ...], encoding(hex)) # Verify a signature for binary data using the ECDSA secp256k1 algorithm. - ecdsa_verify([127, ...], [56, 90, ..], [23, 56, ...], [encoding(octet), type(secp256k1)])
func EDDSAVerify ¶
func EDDSAVerify(_ *engine.VM, key, data, sig, options engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
EDDSAVerify determines if a given signature is valid as per the EdDSA algorithm for the provided data, using the specified public key.
The signature is as follows:
eddsa_verify(+PubKey, +Data, +Signature, +Options) is semi-det
Where:
- PubKey is the encoded public key as a list of bytes.
- Data is the message to verify, represented as either a hexadecimal atom or a list of bytes. It's important that the message isn't pre-hashed since the Ed25519 algorithm processes messages in two passes when signing.
- Signature represents the signature corresponding to the data, provided as a list of bytes.
- Options are additional configurations for the verification process. Supported options include: encoding(+Format) which specifies the encoding used for the Data, and type(+Alg) which chooses the algorithm within the EdDSA family (see below for details).
For Format, the supported encodings are:
- hex (default), the hexadecimal encoding represented as an atom.
- octet, the plain byte encoding depicted as a list of integers ranging from 0 to 255.
- text, the plain text encoding represented as an atom.
- utf8 (default), the UTF-8 encoding represented as an atom.
For Alg, the supported algorithms are:
- ed25519 (default): The EdDSA signature scheme using SHA-512 (SHA-2) and Curve25519.
Examples: ¶
# Verify a signature for a given hexadecimal data. - eddsa_verify([127, ...], '9b038f8ef6918cbb56040dfda401b56b...', [23, 56, ...], [encoding(hex), type(ed25519)]) # Verify a signature for binary data. - eddsa_verify([127, ...], [56, 90, ..], [23, 56, ...], [encoding(octet), type(ed25519)])
func HexBytes ¶
func HexBytes(vm *engine.VM, hexa, bts engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
HexBytes is a predicate that unifies hexadecimal encoded bytes to a list of bytes.
The signature is as follows:
hex_bytes(?Hex, ?Bytes) is det
Where:
- Hex is an Atom, string or list of characters in hexadecimal encoding.
- Bytes is the list of numbers between 0 and 255 that represent the sequence of bytes.
Examples: ¶
# Convert hexadecimal atom to list of bytes. - hex_bytes('2c26b46b68ffc68ff99b453c1d3041341342d706483bfa0f98a5e886266e7ae', Bytes).
func IterMap ¶
IterMap transforms the output of an iterator by applying a given mapping function to each element.
func JSONProlog ¶
JSONProlog is a predicate that unifies a JSON into a prolog term and vice versa.
The signature is as follows:
json_prolog(?Json, ?Term) is det
Where:
- Json is the textual representation of the JSON, as either an atom, a list of character codes, or a list of characters.
- Term is the Prolog term that represents the JSON structure.
JSON canonical representation ¶
The canonical representation for Term is:
- A JSON object is mapped to a Prolog term json(NameValueList), where NameValueList is a list of Name=Value key values. Name is an atom created from the JSON string.
- A JSON array is mapped to a Prolog list of JSON values.
- A JSON string is mapped to a Prolog atom.
- A JSON number is mapped to a Prolog number.
- The JSON constants true and false are mapped to @(true) and @(false).
- The JSON constant null is mapped to the Prolog term @(null).
Examples: ¶
# JSON conversion to Prolog. - json_prolog('{"foo": "bar"}', json([foo=bar])).
func JSONRead ¶
func JSONRead(vm *engine.VM, stream, term engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
JSONRead is a predicate that reads a JSON from a stream and unifies it with a Prolog term.
See json_prolog/2 for the canonical representation of the JSON term.
The signature is as follows:
json_read(+Stream, ?Term) is det
Where:
- Stream is the input stream from which the JSON is read.
- Term is the Prolog term that represents the JSON structure.
func JSONWrite ¶
func JSONWrite(_ *engine.VM, stream, term engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
JSONWrite is a predicate that writes a Prolog term as a JSON to a stream.
The JSON object is of the same format as produced by json_read/2.
The signature is as follows:
json_write(+Stream, +Term) is det
Where:
- Stream is the output stream to which the JSON is written.
- Term is the Prolog term that represents the JSON structure.
func LockedCoinsSorted ¶
func LockedCoinsSorted(ctx context.Context, bankKeeper types.BankKeeper, bech32Addr sdk.AccAddress) sdk.Coins
LockedCoinsSorted returns the list of spendable coins for the given address, sorted by coin denomination.
func Open ¶
func Open(vm *engine.VM, sourceSink, mode, stream, options engine.Term, k engine.Cont, env *engine.Env) *engine.Promise
Open is a predicate which opens a stream to a source or sink.
Signature ¶
open(+SourceSink, +Mode, -Stream, +Options)
where:
- SourceSink is an atom representing the source or sink of the stream, which is typically a URI.
- Mode is an atom representing the mode of the stream to be opened. It can be one of "read", "write", or "append".
- Stream is the stream to be opened.
- Options is a list of options. No options are currently defined, so the list should be empty.
open/4 gives True when SourceSink can be opened in Mode with the given Options.
Virtual File System (VFS) ¶
The logical module interprets on-chain Prolog programs, relying on a Virtual Machine that isolates execution from the external environment. Consequently, the open/4 predicate doesn't access the physical file system as one might expect. Instead, it operates with a Virtual File System (VFS), a conceptual layer that abstracts the file system. This abstraction offers a unified view across various storage systems, adhering to the constraints imposed by blockchain technology.
This VFS extends the file concept to resources, which are identified by a Uniform Resource Identifier (URI). A URI specifies the access protocol for the resource, its path, and any necessary parameters.
CosmWasm URI ¶
The cosmwasm URI enables interaction with instantiated CosmWasm smart contract on the blockchain. The URI is used to query the smart contract and retrieve the response. The query is executed on the smart contract, and the response is returned as a stream. Query parameters are passed as part of the URI to customize the interaction with the smart contract.
Its format is as follows:
cosmwasm:{contract_name}:{contract_address}?query={contract_query}[&base64Decode={true|false}]
where:
- {contract_name}: For informational purposes, indicates the name or type of the smart contract (e.g., "axone-objectarium").
- {contract_address}: Specifies the smart contract instance to query.
- {contract_query}: The query to be executed on the smart contract. It is a JSON object that specifies the query payload.
- base64Decode: (Optional) If true, the response is base64-decoded. Otherwise, the response is returned as is.
func Open3 ¶
func Open3(vm *engine.VM, sourceSink, mode, stream engine.Term, k engine.Cont, env *engine.Env) *engine.Promise
Open3 is a predicate which opens a stream to a source or sink. This predicate is a shorthand for open/4 with an empty list of options.
Signature ¶
open(+SourceSink, +Mode, -Stream)
where:
- SourceSink is an atom representing the source or sink of the stream, which is typically a URI.
- Mode is an atom representing the mode of the stream to be opened. It can be one of "read", "write", or "append".
- Stream is the stream to be opened.
open/3 gives True when SourceSink can be opened in Mode.
func ReadString ¶
func ReadString(vm *engine.VM, stream, length, result engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
ReadString is a predicate that reads characters from the provided Stream and unifies them with String. Users can optionally specify a maximum length for reading; if the stream reaches this length, the reading stops. If Length remains unbound, the entire Stream is read, and upon completion, Length is unified with the count of characters read.
The signature is as follows:
read_string(+Stream, ?Length, -String) is det
Where:
- Stream is the input stream to read from.
- Length is the optional maximum number of characters to read from the Stream. If unbound, denotes the full length of Stream.
- String is the resultant string after reading from the Stream.
Examples: ¶
# Given a file `foo.txt` that contains `Hello World`: file_to_string(File, String, Length) :- open(File, read, In), read_string(In, Length, String), close(Stream). # It gives: ?- file_to_string('path/file/foo.txt', String, Length). String = 'Hello World' Length = 11
func ReadTerm3 ¶
func ReadTerm3(vm *engine.VM, streamOrAlias, t, options engine.Term, k engine.Cont, env *engine.Env) *engine.Promise
ReadTerm3 is a predicate that reads a term from a stream or alias.
The signature is as follows:
read_term(+Stream, -Term, +Options)
where:
- Stream represents the stream or alias to read the term from.
- Term represents the term to read.
- Options represents the options to control the reading process.
Valid options are:
- singletons(Vars): Vars is unified with a list of variables that occur only once in the term.
- variables(Vars): Vars is unified with a list of variables that occur in the term.
- variable_names(Vars): Vars is unified with a list of Name = Var terms, where Name is an atom and Var is a variable.
func Retract ¶
Retract is a predicate that retracts a clause from the database.
Signature ¶
retract(+Clause)
Where:
- Clause is the clause to retract from the database.
func SourceFile ¶
SourceFile is a predicate which unifies the given term with the source file that is currently loaded.
Signature ¶
source_file(?File) is det
where:
- File represents the loaded source file.
func SpendableCoinsSorted ¶
func SpendableCoinsSorted(ctx context.Context, bankKeeper types.BankKeeper, bech32Addr sdk.AccAddress) sdk.Coins
SpendableCoinsSorted returns the list of spendable coins for the given address, sorted by coin denomination.
func StringBytes ¶
func StringBytes( _ *engine.VM, str, bts, encodingTerm engine.Term, cont engine.Cont, env *engine.Env, ) *engine.Promise
StringBytes is a predicate that unifies a string with a list of bytes, returning true when the (Unicode) String is represented by Bytes in Encoding.
The signature is as follows:
string_bytes(?String, ?Bytes, +Encoding)
Where:
- String is the string to convert to bytes. It can be an Atom, string or list of characters codes.
- Bytes is the list of numbers between 0 and 255 that represent the sequence of bytes.
- Encoding is the encoding to use for the conversion.
Encoding can be one of the following: - 'text' considers the string as a sequence of Unicode characters. - 'octet' considers the string as a sequence of bytes. - '<encoding>' considers the string as a sequence of characters in the given encoding.
At least one of String or Bytes must be instantiated.
Examples: ¶
# Convert a string to a list of bytes. - string_bytes('Hello World', Bytes, octet). # Convert a list of bytes to a string. - string_bytes(String, [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100], octet).
func TermToAtom ¶
func TermToAtom(vm *engine.VM, term, atom engine.Term, k engine.Cont, env *engine.Env) *engine.Promise
TermToAtom is a predicate that describes Atom as a term that unifies with Term.
Signature ¶
term_to_atom(?Term, ?Atom)
where:
- Term is a term that unifies with Atom.
- Atom is an atom.
When Atom is instantiated, Atom is parsed and the result unified with Term. If Atom has no valid syntax, a syntax_error exception is raised. Otherwise, Term is “written” on Atom using write_term/2 with the option quoted(true).
Example ¶
# Convert the atom to a term. - term_to_atom(foo, foo).
func URIEncoded ¶
func URIEncoded(_ *engine.VM, component, decoded, encoded engine.Term, cont engine.Cont, env *engine.Env) *engine.Promise
URIEncoded is a predicate that unifies the given URI component with the given encoded or decoded string.
The signature is as follows:
uri_encoded(+Component, +Value, -Encoded) is det uri_encoded(+Component, -Value, +Encoded) is det
Where:
- Component represents the component of the URI to be escaped. It can be the atom 'query_path', 'fragment', 'path' or 'segment'.
- Decoded represents the decoded string to be escaped.
- Encoded represents the encoded string.
For more information on URI encoding, refer to RFC 3986.
Examples: ¶
# Escape the given string to be used in the path component. - uri_encoded(path, "foo/bar", Encoded). # Unescape the given string to be used in the path component. - uri_encoded(path, Decoded, foo%2Fbar).
func WriteTerm3 ¶
func WriteTerm3(vm *engine.VM, streamOrAlias, t, options engine.Term, k engine.Cont, env *engine.Env) *engine.Promise
WriteTerm3 is a predicate that writes a term to a stream or alias.
The signature is as follows:
write_term(+Stream, +Term, +Options)
where:
- Stream represents the stream or alias to write the term to.
- Term represents the term to write.
- Options represents the options to control the writing process.
Valid options are:
- quoted(Bool): If true, atoms and strings that need quotes will be quoted. The default is false.
- ignore_ops(Bool): If true, the generic term representation (<functor>(<args> ... )) will be used for all terms. Otherwise (default), operators will be used where appropriate.
- numbervars(Bool): If true, variables will be numbered. The default is false.
- variable_names(+List): Assign names to variables in Term. List is a list of Name = Var terms, where Name is an atom and Var is a variable.
- max_depth(+Int): The maximum depth to which the term is written. The default is infinite.
Types ¶
This section is empty.