Lisp Interface - Interpreter Interfaces

Skip to content
Back to top
View this page
Edit this page

# Lisp Interface

EXAMPLES:

Sage

    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'

Python

    >>> 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

    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

[Python]

    >>> 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)

  Bases: `Expect`

  EXAMPLES:

  Sage

      sage: from sage.interfaces.lisp import lisp
      sage: lisp == loads(dumps(lisp))
      True

  Python

      >>> from sage.all import *
      >>> from sage.interfaces.lisp import lisp
      >>> lisp == loads(dumps(lisp))
      True

  console()

    Spawn a new Lisp command-line session.

    EXAMPLES:

    Sage

        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.
        ...

    Python

        >>> 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)

    EXAMPLES:

    Sage

        sage: lisp.eval('(+ 2 2)')
        '4'

    Python

        >>> from sage.all import *
        >>> lisp.eval('(+ 2 2)')
        '4'

  function_call(function, args=None, kwds=None)

    Call the Lisp function with given `args` and `kwds`. For Lisp functions, the `kwds` are ignored.

    EXAMPLES:

    Sage

        sage: lisp.function_call('sin', ['2'])
        0.9092974
        sage: lisp.sin(2)
        0.9092974

    Python

        >>> from sage.all import *
        >>> lisp.function_call('sin', ['2'])
        0.9092974
        >>> lisp.sin(Integer(2))
        0.9092974

  get(var)

    EXAMPLES:

    Sage

        sage: lisp.set('x', '2')
        sage: lisp.get('x')
        '2'

    Python

        >>> from sage.all import *
        >>> lisp.set('x', '2')
        >>> lisp.get('x')
        '2'

  help(command)

    EXAMPLES:

    Sage

        sage: lisp.help('setq')
        Traceback (most recent call last):
        ...
        NotImplementedError

    Python

        >>> from sage.all import *
        >>> lisp.help('setq')
        Traceback (most recent call last):
        ...
        NotImplementedError

  kill(var)

    EXAMPLES:

    Sage

        sage: lisp.kill('x')
        Traceback (most recent call last):
        ...
        NotImplementedError

    Python

        >>> from sage.all import *
        >>> lisp.kill('x')
        Traceback (most recent call last):
        ...
        NotImplementedError

  set(var, value)

    Set the variable var to the given value.

    EXAMPLES:

    Sage

        sage: lisp.set('x', '2')
        sage: lisp.get('x')
        '2'

    Python

        >>> from sage.all import *
        >>> lisp.set('x', '2')
        >>> lisp.get('x')
        '2'

  version()

    Return the version of Lisp being used.

    EXAMPLES:

    Sage

        sage: lisp.version()
        'Version information is given by lisp.console().'

    Python

        >>> from sage.all import *
        >>> lisp.version()
        'Version information is given by lisp.console().'

class sage.interfaces.lisp.LispElement(parent, value, is_name=False, name=None)

  Bases: `RingElement`, `ExpectElement`

class sage.interfaces.lisp.LispFunction(parent, name)

  Bases: `ExpectFunction`

class sage.interfaces.lisp.LispFunctionElement(obj, name)

  Bases: `FunctionElement`

sage.interfaces.lisp.lisp_console()

  Spawn a new Lisp command-line session.

  EXAMPLES:

  Sage

      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.
      ...

  Python

      >>> 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.
      ...

sage.interfaces.lisp.reduce_load_Lisp()

  EXAMPLES:

  Sage

      sage: from sage.interfaces.lisp import reduce_load_Lisp
      sage: reduce_load_Lisp()
      Lisp Interpreter

  Python

      >>> from sage.all import *
      >>> from sage.interfaces.lisp import reduce_load_Lisp
      >>> reduce_load_Lisp()
      Lisp Interpreter