示例#1
0
文件: prolog.py 项目: EdTsft/swilite
 def get_atom(self):
     """An `Atom` object representing this term, if it is a prolog atom."""
     a = atom_t()
     self._require_success_expecting_type(
         PL_get_atom(self._handle, byref(a)),
         'atom')
     return Atom._from_handle(a.value)
示例#2
0
文件: prolog.py 项目: EdTsft/swilite
    def get_info(self):
        """Returns name, arity, and module of this predicate.

        Returns:
            Predicate.Info:
        """
        name = atom_t()
        arity = c_int()
        module = module_t()
        PL_predicate_info(self._handle,
                          byref(name), byref(arity), byref(module))
        return self.Info(name=Atom._from_handle(name.value),
                         arity=arity.value,
                         module=Module._from_handle(module.value))
示例#3
0
文件: prolog.py 项目: EdTsft/swilite
    def get_compound_name_arity(self):
        """The name and arity of this term, if it is a compound term.

        The same as `get_name_arity` but fails for atoms.

        Returns:
            NameArity: Named tuple of name (`string`) and arity (`int`).
        """
        name = atom_t()
        arity = c_int()
        self._require_success_expecting_type(
            PL_get_compound_name_arity(self._handle, byref(name),
                                       byref(arity)),
            'compound term')
        return self.NameArity(name=Atom._from_handle(name.value),
                              arity=arity.value)
示例#4
0
文件: prolog.py 项目: EdTsft/swilite
    def get_name_arity(self):
        """The name and arity of this term, if it is a compound term or an atom.

        Compound terms with arity 0 give the same result as an atom.
        To distinguish them use `is_compound` and/or `get_compound_name_arity`.

        Returns:
            NameArity: namedtuple (name, arity)
        """

        name = atom_t()
        arity = c_int()
        self._require_success_expecting_type(
            PL_get_name_arity(self._handle, byref(name), byref(arity)),
            'compound term', 'atom')
        return self.NameArity(name=Atom._from_handle(name.value),
                              arity=arity.value)