Documentation ¶
Index ¶
- Variables
- func AreGround(terms []engine.Term, env *engine.Env) bool
- func AssertAtom(term engine.Term, env *engine.Env) (engine.Atom, error)
- func AssertByte(term engine.Term, env *engine.Env) (byte, error)
- func AssertCharacter(term engine.Term, env *engine.Env) (rune, error)
- func AssertCharacterCode(term engine.Term, env *engine.Env) (rune, error)
- func AssertIsGround(term engine.Term, env *engine.Env) (engine.Term, error)
- func AssertList(term engine.Term, env *engine.Env) (engine.Term, error)
- func AssertPair(term engine.Term, env *engine.Env) (engine.Term, engine.Term, error)
- func AssertURIComponent(term engine.Term, env *engine.Env) (util.URIComponent, error)
- func AtomToString(term engine.Term, env *engine.Env) (string, error)
- func ByteListTermToBytes(term engine.Term, env *engine.Env) ([]byte, error)
- func BytesToByteListTerm(in []byte) engine.Term
- func CharacterCodeListTermToString(term engine.Term, env *engine.Env) (string, error)
- func CharacterListTermToString(term engine.Term, env *engine.Env) (string, error)
- func Decode(value engine.Term, bs []byte, encoding engine.Atom, env *engine.Env) (string, error)
- func Encode(value engine.Term, str string, encoding engine.Atom, env *engine.Env) ([]byte, error)
- func ErrorTerm(err error) engine.Term
- func ExtractJSONTerm(term engine.Compound, env *engine.Env) (map[string]engine.Term, error)
- func GetOption(name engine.Atom, options engine.Term, env *engine.Env) (engine.Term, error)
- func GetOptionAsAtomWithDefault(name engine.Atom, options engine.Term, defaultValue engine.Term, ...) (engine.Atom, error)
- func GetOptionWithDefault(name engine.Atom, options engine.Term, defaultValue engine.Term, ...) (engine.Term, error)
- func IsEmptyList(term engine.Term, env *engine.Env) bool
- func IsGround(term engine.Term, env *engine.Env) bool
- func IsList(term engine.Term, env *engine.Env) bool
- func JSONBool(b bool) engine.Term
- func JSONEmptyArray() engine.Term
- func JSONNull() engine.Term
- func ListHead(list engine.Term, env *engine.Env) engine.Term
- func ListIterator(list engine.Term, env *engine.Env) (engine.ListIterator, error)
- func OctetListTermToString(term engine.Term, env *engine.Env) (string, error)
- func PredicateMatches(this string) func(string) bool
- func ResourceContext() engine.Term
- func ResourceGas(descriptor string, consumed types.Gas, limit types.Gas) engine.Term
- func ResourceModule(module string) engine.Term
- func StringToAtom(s string) engine.Atom
- func StringToByteListTerm(s string) engine.Term
- func StringToCharacterCodeListTerm(s string) engine.Term
- func StringToCharacterListTerm(s string) engine.Term
- func StringToOctetListTerm(s string, env *engine.Env) (engine.Term, error)
- func TermHexToBytes(term engine.Term, env *engine.Env) ([]byte, error)
- func TextTermToString(term engine.Term, env *engine.Env) (string, error)
- func Tuple(args ...engine.Term) engine.Term
- func UnifyFunctional(in, out []engine.Term, options engine.Term, forwardConverter ConvertFunc, ...) (bool, *engine.Env, error)
- func UnifyFunctionalPredicate(in, out []engine.Term, options engine.Term, forwardConverter ConvertFunc, ...) *engine.Promise
- func UnwrapSDKContext(ctx context.Context, env *engine.Env) (sdk.Context, error)
- func ValidEmptyList() engine.Term
- func ValidEncoding(encoding string) engine.Term
- func WithError(exception engine.Exception, err error, env *engine.Env) engine.Exception
- type ConvertFunc
Constants ¶
This section is empty.
Variables ¶
var ( // AtomAs is the term used to indicate the as encoding type option. AtomAs = engine.NewAtom("as") // AtomAt are terms with principal functor (@)/1 used to represent special values in json objects. AtomAt = engine.NewAtom("@") // AtomDIDComponents is a term which represents a DID as a compound term `did_components(Method, ID, Path, Query, Fragment)`. AtomDIDComponents = engine.NewAtom("did_components") // AtomDot is the term used to represent the dot in a list. AtomDot = engine.NewAtom(".") // AtomEmpty is the term used to represent empty. AtomEmpty = engine.NewAtom("") // AtomEmptyArray is the term []. AtomEmptyArray = engine.NewAtom("[]") // AtomEmptyList is the term used to represent an empty list. AtomEmptyList = engine.NewAtom("[]") // AtomEncoding is the term used to indicate the encoding type option. AtomEncoding = engine.NewAtom("encoding") // AtomError is the term used to indicate the error. AtomError = engine.NewAtom("error") // AtomFalse is the term false. AtomFalse = engine.NewAtom("false") // AtomFragment is the term used to indicate the fragment component. AtomFragment = engine.NewAtom("fragment") // AtomHex is the term used to indicate the hexadecimal encoding type option. AtomHex = engine.NewAtom("hex") // AtomJSON are terms with principal functor json/1 used to represent json objects. AtomJSON = engine.NewAtom("json") // AtomNull is the term null. AtomNull = engine.NewAtom("null") // AtomOctet is the term used to indicate the byte encoding type option. AtomOctet = engine.NewAtom("octet") // AtomPadding is the term used to indicate the padding encoding type option. AtomPadding = engine.NewAtom("padding") // AtomPair are terms with principal functor (-)/2. // For example, the term -(A, B) denotes the pair of elements A and B. AtomPair = engine.NewAtom("-") // AtomPath is the term used to indicate the path component. AtomPath = engine.NewAtom("path") // AtomQueryValue is the term used to indicate the query value component. AtomQueryValue = engine.NewAtom("query_value") // AtomSegment is the term used to indicate the segment component. AtomSegment = engine.NewAtom("segment") // AtomText is the term used to indicate the atom text. AtomText = engine.NewAtom("text") // AtomTrue is the term true. AtomTrue = engine.NewAtom("true") // AtomUtf8 is the term used to indicate the UTF-8 encoding type option. AtomUtf8 = engine.NewAtom("utf8") )
var ( // AtomTypeAtom is the term used to represent the atom type. AtomTypeAtom = engine.NewAtom("atom") // AtomTypeByte is the term used to represent the byte type. AtomTypeByte = engine.NewAtom("byte") // AtomTypeCharacter is the term used to represent the character type. // A character type is a single character (e.g. 'a') identified in the Unicode standard. AtomTypeCharacter = engine.NewAtom("character") // AtomTypeCharacterCode is the term used to represent the character code type. // A character code type is a single character identified by its code point (a number) in the Unicode standard. AtomTypeCharacterCode = engine.NewAtom("character_code") // AtomTypeCharset is the term used to represent the charset type. // A charset type is a set of characters identified by its name in the IANA standard. AtomTypeCharset = engine.NewAtom("charset") // AtomTypeCryptographicAlgorithm is the term used to represent the cryptographic algorithm type. AtomTypeCryptographicAlgorithm = engine.NewAtom("cryptographic_algorithm") // AtomTypeDID is the term used to represent the DID type. // DID type is a compound with the name "did" and 5 arguments which are the components of the DID, in the form of // did(Method, ID, Path, Query, Fragment). AtomTypeDID = engine.NewAtom("did") // AtomTypeHashAlgorithm is the term used to represent the hash algorithm type. AtomTypeHashAlgorithm = engine.NewAtom("hash_algorithm") // AtomTypeIOMode is the term used to represent the IO mode type. // An IO mode specifies the direction of the IO operation represented as an atom. // Possible values are: read, write, append. AtomTypeIOMode = engine.NewAtom("io_mode") // AtomTypeStream is the term used to represent the stream type. AtomTypeStream = engine.NewAtom("stream") // AtomTypeText is the term used to represent the text type. // A text type is either an atom, a list of characters or a list of character codes. AtomTypeText = AtomText // AtomTypeList is the term used to represent the list type. AtomTypeList = engine.NewAtom("list") // AtomTypeNumber is the term used to represent the number type. AtomTypeNumber = engine.NewAtom("number") // AtomTypeOption is the term used to represent the option type. // An option is a compound with the name of the option as functor and one term argument which is // the value of the option. For instance: opt(v). AtomTypeOption = engine.NewAtom("option") // AtomTypePair is the term used to indicate the pair type. AtomTypePair = engine.NewAtom("pair") // AtomTypeJSON is the term used to indicate the json type. AtomTypeJSON = AtomJSON // AtomTypeURIComponent is the term used to represent the URI component type. AtomTypeURIComponent = engine.NewAtom("uri_component") )
var ( // AtomValidEncoding is the atom denoting a valid encoding. // The valid encoding atom is a compound with the name of the encoding which is a valid encoding with // regard to the predicate where it is used. // // For instance: valid_encoding(utf8), valid_encoding(hex). AtomValidEncoding = engine.NewAtom("encoding") // AtomValidEmptyList is the atom denoting a valid empty list. AtomValidEmptyList = engine.NewAtom("empty_list") )
var ( // AtomResourceContext is the atom denoting the "context" resource. // The context resource is a contextual data that contains all information needed to // process a request and produce a response with the blockchain. AtomResourceContext = engine.NewAtom("resource_context") // AtomResourceModule is the atom denoting the "module" resource. // The module resource is the representation of the module with which the interaction is made. // The module resource is denoted as a compound with the name of the module. AtomResourceModule = engine.NewAtom("resource_module") // AtomResourceGas is the atom denoting the "gas" resource. AtomResourceGas = engine.NewAtom("gas") )
var ( AtomOperationInput = engine.NewAtom("input") AtomOperationExecute = engine.NewAtom("execute") )
var ( AtomPermissionTypeStream = engine.NewAtom("stream") AtomPermissionForbiddenPredicate = engine.NewAtom("forbidden_predicate") )
var AtomObjectTypeSourceSink = engine.NewAtom("source_sink")
Functions ¶
func AssertAtom ¶
AssertAtom resolves a term and attempts to convert it into an engine.Atom if possible. If conversion fails, the function returns the empty atom and the error.
func AssertByte ¶
AssertByte resolves a term and attempts to convert it into a byte if possible. If conversion fails, the function returns the zero value and the error.
func AssertCharacter ¶
AssertCharacter resolves a term and attempts to convert it into an engine.Atom if possible. If conversion fails, the function returns the empty atom and the error.
func AssertCharacterCode ¶
AssertCharacterCode resolves a term and attempts to convert it into a rune if possible. If conversion fails, the function returns the zero value and the error.
func AssertIsGround ¶
AssertIsGround resolves a term and returns it if it is ground. If the term is not ground, the function returns nil and the instantiation error.
func AssertList ¶
AssertList resolves a term as a list and returns it as a engine.Compound. If conversion fails, the function returns nil and the error.
func AssertPair ¶
AssertPair resolves a term as a pair and returns the pair components. If conversion fails, the function returns nil and the error.
func AssertURIComponent ¶
AssertURIComponent resolves a term as a URI component and returns it as an URIComponent.
func AtomToString ¶
AtomToString try to convert a given atom to a string.
func ByteListTermToBytes ¶
ByteListTermToBytes try to convert a given list of bytes into native golang []byte.
func BytesToByteListTerm ¶
BytesToByteListTerm try to convert a given golang []byte into a list of bytes.
func CharacterCodeListTermToString ¶
CharacterCodeListTermToString try to convert a given list of character codes to a string. The character codes must be between 0 and 0x10ffff (i.e. a Rune).
func CharacterListTermToString ¶
CharacterListTermToString try to convert a given list of characters to a string. Characters is a list of atoms, each representing a single character.
func Decode ¶
Decode decodes the given byte slice with the given encoding. value is used for error reporting (the culprit).
func Encode ¶
Encode encodes the given string with the given encoding. value is used for error reporting (the culprit).
func ErrorTerm ¶
ErrorTerm returns a term representing the given error, suitable for use in the syntax_error/2 predicate. TODO: to be improved with specific error types.
func ExtractJSONTerm ¶
ExtractJSONTerm is a utility function that would extract all attribute of a JSON object that is represented in prolog with the `json` atom.
This function will ensure the json atom follow our json object representation in prolog.
A JSON object is represented like this :
``` json([foo-bar]) ```
That give a JSON object: `{"foo": "bar"}` Returns the map of all attributes with its term value.
func GetOption ¶
GetOption returns the value of the first option with the given name in the given options. An option is a compound with the given name as functor and one argument which is a term, for instance `opt(v)`. The options are either a list of options or an option. If no option is found nil is returned.
func GetOptionAsAtomWithDefault ¶
func GetOptionAsAtomWithDefault( name engine.Atom, options engine.Term, defaultValue engine.Term, env *engine.Env, ) (engine.Atom, error)
GetOptionAsAtomWithDefault is a helper function that returns the value of the first option with the given name in the given options.
func GetOptionWithDefault ¶
func GetOptionWithDefault( name engine.Atom, options engine.Term, defaultValue engine.Term, env *engine.Env, ) (engine.Term, error)
GetOptionWithDefault returns the value of the first option with the given name in the given options, or the given default value if no option is found.
func IsEmptyList ¶
IsEmptyList returns true if the given term is an empty list.
func JSONEmptyArray ¶
JSONEmptyArray returns is the compound term @([]). It is used to represent the empty array in json objects.
func JSONNull ¶
JSONNull returns the compound term @(null). It is used to represent the null value in json objects.
func ListIterator ¶
ListIterator returns a list iterator.
func OctetListTermToString ¶
OctetListTermToString try to convert a given list of bytes to a string. It's the same as CharacterCodeListTermToString, but expects the list to contain bytes. It's equivalent to the prolog encoding 'octet'.
func PredicateMatches ¶
PredicateMatches returns a function that matches the given predicate against the given other predicate. If the other predicate contains a slash, it is matched as is. Otherwise, the other predicate is matched against the first part of the given predicate. For example:
- matchPredicate("foo/0")("foo/0") -> true
- matchPredicate("foo/0")("foo/1") -> false
- matchPredicate("foo/0")("foo") -> true
- matchPredicate("foo/0")("bar") -> false
The function is curried, and is a binary relation that is reflexive, associative (but not commutative).
func ResourceContext ¶
ResourceContext returns a term representing the context resource.
func ResourceGas ¶
ResourceGas returns a term representing the gas resource with the given descriptor, consumed and limit at the given context.
func ResourceModule ¶
ResourceModule returns a term representing the module resource with the given name.
func StringToAtom ¶
StringToAtom converts a string to an atom.
func StringToByteListTerm ¶
StringToByteListTerm converts a string (utf8) to a term representing a list of bytes. This is equivalent to the prolog encoding 'text'.
func StringToCharacterCodeListTerm ¶
StringToCharacterCodeListTerm converts a string to a term representing a list of character codes.
func StringToCharacterListTerm ¶
StringToCharacterListTerm converts a string to a term representing a list of characters.
func StringToOctetListTerm ¶
StringToOctetListTerm converts a string (utf8) to a term representing a list of bytes. This is the same as StringToCharacterCodeListTerm, but it returns an error when a rune is greater than 0xff. This is equivalent to the prolog encoding 'octet'.
func TermHexToBytes ¶
TermHexToBytes try to convert an hexadecimal encoded atom to native golang []byte.
func TextTermToString ¶
TextTermToString try to convert a given Text term to a string. Text is an instantiated term which represents text as: an atom, a list of character codes, or list of characters.
func UnifyFunctional ¶
func UnifyFunctional( in, out []engine.Term, options engine.Term, forwardConverter ConvertFunc, backwardConverter ConvertFunc, env *engine.Env, ) (bool, *engine.Env, error)
UnifyFunctional is a generic unification which unifies a set of input terms with a set of output terms, using the given conversion functions maintaining the function's relationship.
The aim of this function is to simplify the implementation of a wide range of predicates which are essentially functional, like hash functions, encoding functions, etc.
The semantic of the unification is as follows:
- first all the variables are resolved
- if there's variables in the input and the output, the conversion is not possible and a not sufficiently instantiated error is returned.
- if there's no variables in the input, then the conversion is attempted from the input to the output and the result is unified with the output.
- if there's no variables in the output, then the conversion is attempted from the output to the input and the result is unified with the input.
The following table summarizes the behavior, where: - fi = fully instantiated (i.e. no variables) - !fi = not fully instantiated (i.e. at least one variable)
| input | output | result | |-------|--------|--------------------------------------| | !fi | !fi | error: not sufficiently instantiated | | fi | !fi | unify(forward(input), output) | | fi | fi | unify(forward(input), output) | | !fi | fi | unify(input,backward(output)) |
Conversion functions may produce an error in scenarios where the conversion is unsuccessful or infeasible due to the inherent characteristics of the function's relationship, such as the absence of a one-to-one correspondence (e.g. hash functions).
func UnifyFunctionalPredicate ¶
func UnifyFunctionalPredicate( in, out []engine.Term, options engine.Term, forwardConverter ConvertFunc, backwardConverter ConvertFunc, cont engine.Cont, env *engine.Env, ) *engine.Promise
UnifyFunctionalPredicate is the predicate version of UnifyFunctional returning a promise.
func UnwrapSDKContext ¶
UnwrapSDKContext retrieves a Context from a context.Context instance attached with WrapSDKContext.
func ValidEmptyList ¶
func ValidEncoding ¶
ValidEncoding returns a term representing the valid encoding with the given name.
Types ¶
type ConvertFunc ¶
type ConvertFunc func(value []engine.Term, options engine.Term, env *engine.Env) ([]engine.Term, error)
ConvertFunc is a function mapping a domain which is a list of terms with a codomain which is a set of terms. Domains and co-domains can have different cardinalities. options is a list of options that can be used to parameterize the conversion. All the terms provided are fully instantiated (i.e. no variables).