function_factory does not allow GAP comments in the body
Issue #8
resolved
sage: ff=libgap.function_factory('function(x) return x^2;\
end;')
sage: ff=libgap.function_factory('function(x) return x^2;\
....: # blah \
....: end;')
and one cannot terminate the latter. If one has a Python file with the latter function in the body (see attachment), one gets
/home/dima/tmp/f.py in <module>()
1 ff=libgap.function_factory('function(x) return x^2;\
2 # blah \
----> 3 end;')
/home/dima/software/sage/src/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedMethodCaller.__call__ (/home/dima/software/sage/src/build/cythonized/sage/misc/cachefunc.c:10746)()
1859 return cache[k]
1860 except KeyError:
-> 1861 w = self._cachedmethod._instance_call(self._instance, *args, **kwds)
1862 cache[k] = w
1863 return w
/home/dima/software/sage/src/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedMethod._instance_call (/home/dima/software/sage/src/build/cythonized/sage/misc/cachefunc.c:14256)()
2515
2516 """
-> 2517 return self._cachedfunc.f(inst, *args, **kwds)
2518
2519 def __call__(self, inst, *args, **kwds):
/home/dima/software/sage/src/sage/libs/gap/libgap.pyx in sage.libs.gap.libgap.Gap.function_factory (/home/dima/software/sage/src/build/cythonized/sage/libs/gap/libgap.c:4190)()
456 <Gap function "Print">
457 """
--> 458 return make_GapElement_Function(self, gap_eval(function_name))
459
460 def set_global(self, variable, value):
/home/dima/software/sage/src/sage/libs/gap/util.pyx in sage.libs.gap.util.gap_eval (/home/dima/software/sage/src/build/cythonized/sage/libs/gap/util.c:4840)()
286 sig_off()
287 except RuntimeError as msg:
--> 288 raise ValueError('libGAP: '+str(msg).strip())
289
290 if libGAP_Symbol != libGAP_S_SEMICOLON:
ValueError: libGAP: Syntax error: end expected
^
This makes it hard to have nontrivial GAP functions in function_factory()
Comments (3)
-
reporter -
reporter - changed status to resolved
there is nothing to fix, thus...
-
repo owner On a related note, backslash line continuation does not add a return to the string so the # comments out everything after it.
Multiline strings work
- Log in to comment
here is a way around it: