diff --git a/src/sage/libs/gap/util.pxd b/src/sage/libs/gap/util.pxd index bb559f7c6a3..0bdc6d23e8e 100644 --- a/src/sage/libs/gap/util.pxd +++ b/src/sage/libs/gap/util.pxd @@ -42,5 +42,4 @@ cdef initialize() ### Evaluate string in GAP ################################################# ############################################################################ -# Evaluate a string cdef Obj gap_eval(str gap_string) except? NULL diff --git a/src/sage/libs/gap/util.pyx b/src/sage/libs/gap/util.pyx index 29fa347ff30..e6f064a41d7 100644 --- a/src/sage/libs/gap/util.pyx +++ b/src/sage/libs/gap/util.pyx @@ -293,6 +293,10 @@ cdef Obj gap_eval(str gap_string) except? NULL: r""" Evaluate a string in GAP. + This function cannot be used directly from Python, use + :meth:`~sage.libs.gap.libgap.Gap.eval` method on global ``libgap`` + variable instead. + INPUT: - ``gap_string`` -- string; a valid statement in GAP diff --git a/src/sage/structure/sage_object.pyx b/src/sage/structure/sage_object.pyx index 8605cc2c729..f73e7fc790b 100644 --- a/src/sage/structure/sage_object.pyx +++ b/src/sage/structure/sage_object.pyx @@ -741,17 +741,84 @@ cdef class SageObject: return True def _gap_(self, G=None): + """ + Return a Gap object. + + Unlike :meth:`_libgap_`, this method returns an instance of + :class:`sage.interfaces.gap.GapElement`, which wraps an object + in the GAP interpreter spawned as a subprocess of Sage. + + Typically you should not need to call this method directly, + instead just call :mod:`~sage.interfaces.gap` + on the object. See example below. + + EXAMPLES:: + + sage: a = gap(2/3); a + 2/3 + sage: type(a) + + + sage: a = (2/3)._gap_(); a + 2/3 + sage: type(a) + + """ if G is None: import sage.interfaces.gap G = sage.interfaces.gap.gap return self._interface_(G) def _gap_init_(self): + """ + Return a string that provides a representation of ``self`` in GAP. + + This method is indirectly used by :meth:`_libgap_` and :meth:`_gap_` + by essentially passing their output to + :meth:`libgap.eval ` + and :mod:`~sage.interfaces.gap` respectively, + unless the subclass overrides them with more efficient variants. + + EXAMPLES:: + + sage: (2/3)._gap_init_() + '2/3' + sage: Zmod(4)._gap_init_() + 'ZmodnZ(4)' + """ import sage.interfaces.gap I = sage.interfaces.gap.gap return self._interface_init_(I) def _libgap_(self): + """ + Return a libgap object. + + Unlike :meth:`_gap_`, this method returns an instance of + :class:`sage.libs.gap.libgap.GapElement`, which wraps an object + in libgap embedded in Sage. As explained in + :mod:`sage.libs.gap.libgap`, this is much faster. + + Typically you should not need to call this method directly, + instead use :mod:`~sage.libs.gap.libgap`. See example below. + + By default, this method makes use of :meth:`_gap_init_`. + Subclasses could override this method to provide a more efficient + implementation. + + EXAMPLES:: + + sage: a = libgap(2/3); a + 2/3 + sage: type(a) + + + TESTS:: + + sage: from sage.libs.gap.element import GapElement + sage: isinstance(a, GapElement) + True + """ from sage.libs.gap.libgap import libgap return libgap.eval(self)