Lisp Interface#
EXAMPLES:
sage: lisp.eval('(* 4 5)')
'20'
sage: a = lisp(3); b = lisp(5)
sage: a + b
8
sage: a * b
15
sage: a / b
3/5
sage: a - b
-2
sage: a.sin()
0.14112
sage: b.cos()
0.2836622
sage: a.exp()
20.085537
sage: lisp.eval('(+ %s %s)'%(a.name(), b.name()))
'8'
>>> from sage.all import *
>>> lisp.eval('(* 4 5)')
'20'
>>> a = lisp(Integer(3)); b = lisp(Integer(5))
>>> a + b
8
>>> a * b
15
>>> a / b
3/5
>>> a - b
-2
>>> a.sin()
0.14112
>>> b.cos()
0.2836622
>>> a.exp()
20.085537
>>> lisp.eval('(+ %s %s)'%(a.name(), b.name()))
'8'
One can define functions and the interface supports object-oriented notation for calling them:
sage: lisp.eval('(defun factorial (n) (if (= n 1) 1 (* n (factorial (- n 1)))))')
'FACTORIAL'
sage: lisp('(factorial 10)')
3628800
sage: lisp(10).factorial()
3628800
sage: a = lisp(17)
sage: a.factorial()
355687428096000
>>> from sage.all import *
>>> lisp.eval('(defun factorial (n) (if (= n 1) 1 (* n (factorial (- n 1)))))')
'FACTORIAL'
>>> lisp('(factorial 10)')
3628800
>>> lisp(Integer(10)).factorial()
3628800
>>> a = lisp(Integer(17))
>>> a.factorial()
355687428096000
- AUTHORS:
– William Stein (first version) – William Stein (2007-06-20): significant improvements.
- class sage.interfaces.lisp.Lisp(maxread=None, script_subdirectory=None, logfile=None, server=None, server_tmpdir=None)[source]#
Bases:
Expect
EXAMPLES:
sage: lisp == loads(dumps(lisp)) True
>>> from sage.all import * >>> lisp == loads(dumps(lisp)) True
- console()[source]#
Spawn a new Lisp command-line session.
EXAMPLES:
sage: lisp.console() #not tested ECL (Embeddable Common-Lisp) ... Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya Copyright (C) 1993 Giuseppe Attardi Copyright (C) 2000 Juan J. Garcia-Ripoll ECL is free software, and you are welcome to redistribute it under certain conditions; see file 'Copyright' for details. Type :h for Help. Top level. ...
>>> from sage.all import * >>> lisp.console() #not tested ECL (Embeddable Common-Lisp) ... Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya Copyright (C) 1993 Giuseppe Attardi Copyright (C) 2000 Juan J. Garcia-Ripoll ECL is free software, and you are welcome to redistribute it under certain conditions; see file 'Copyright' for details. Type :h for Help. Top level. ...
- eval(code, strip=True, **kwds)[source]#
EXAMPLES:
sage: lisp.eval('(+ 2 2)') '4'
>>> from sage.all import * >>> lisp.eval('(+ 2 2)') '4'
- function_call(function, args=None, kwds=None)[source]#
Calls the Lisp function with given args and kwds. For Lisp functions, the kwds are ignored.
EXAMPLES:
sage: lisp.function_call('sin', ['2']) 0.9092974 sage: lisp.sin(2) 0.9092974
>>> from sage.all import * >>> lisp.function_call('sin', ['2']) 0.9092974 >>> lisp.sin(Integer(2)) 0.9092974
- get(var)[source]#
EXAMPLES:
sage: lisp.set('x', '2') sage: lisp.get('x') '2'
>>> from sage.all import * >>> lisp.set('x', '2') >>> lisp.get('x') '2'
- help(command)[source]#
EXAMPLES:
sage: lisp.help('setq') Traceback (most recent call last): ... NotImplementedError
>>> from sage.all import * >>> lisp.help('setq') Traceback (most recent call last): ... NotImplementedError
- kill(var)[source]#
EXAMPLES:
sage: lisp.kill('x') Traceback (most recent call last): ... NotImplementedError
>>> from sage.all import * >>> lisp.kill('x') Traceback (most recent call last): ... NotImplementedError
- class sage.interfaces.lisp.LispElement(parent, value, is_name=False, name=None)[source]#
Bases:
RingElement
,ExpectElement
- class sage.interfaces.lisp.LispFunction(parent, name)[source]#
Bases:
ExpectFunction
- class sage.interfaces.lisp.LispFunctionElement(obj, name)[source]#
Bases:
FunctionElement
- sage.interfaces.lisp.is_LispElement(x)[source]#
EXAMPLES:
sage: from sage.interfaces.lisp import is_LispElement sage: is_LispElement(2) doctest:...: DeprecationWarning: the function is_LispElement is deprecated; use isinstance(x, sage.interfaces.abc.LispElement) instead See https://github.com/sagemath/sage/issues/34804 for details. False sage: is_LispElement(lisp(2)) True
>>> from sage.all import * >>> from sage.interfaces.lisp import is_LispElement >>> is_LispElement(Integer(2)) doctest:...: DeprecationWarning: the function is_LispElement is deprecated; use isinstance(x, sage.interfaces.abc.LispElement) instead See https://github.com/sagemath/sage/issues/34804 for details. False >>> is_LispElement(lisp(Integer(2))) True
- sage.interfaces.lisp.lisp_console()[source]#
Spawn a new Lisp command-line session.
EXAMPLES:
sage: lisp.console() #not tested ECL (Embeddable Common-Lisp) ... Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya Copyright (C) 1993 Giuseppe Attardi Copyright (C) 2000 Juan J. Garcia-Ripoll ECL is free software, and you are welcome to redistribute it under certain conditions; see file 'Copyright' for details. Type :h for Help. Top level. ...
>>> from sage.all import * >>> lisp.console() #not tested ECL (Embeddable Common-Lisp) ... Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya Copyright (C) 1993 Giuseppe Attardi Copyright (C) 2000 Juan J. Garcia-Ripoll ECL is free software, and you are welcome to redistribute it under certain conditions; see file 'Copyright' for details. Type :h for Help. Top level. ...