lispy#
Provides a module for Scheme Interpreter in Python.
Classes:
|
An environment: a dict of {'var':val} pairs, with an outer Env. |
|
An input port. |
|
A user-defined Scheme procedure. |
Symbol. |
Functions:
|
Find or create unique Symbol entry for str s in symbol table. |
|
Add some Scheme standard procedures. |
|
Numbers become numbers; #t and #f are booleans; "..." string; otherwise Symbol. |
|
Call proc with current continuation; escape only. |
|
Form a pair. |
|
Get count of unescaped quotes. |
|
Evaluate an expression in an environment. |
|
Walk tree of x, making optimizations/fixes, and signaling SyntaxError. |
Expand |
|
|
Check whether given value type is pair or not. |
|
Get variable values. |
|
Eval every expression from a file. |
|
Parse a program: read and expand/error-check it. |
|
Read a Scheme expression from an input port. |
|
Read the next character from an input port. |
|
A prompt-read-eval-print loop. |
|
Signal a syntax error if predicate is false. |
|
Convert a Python object back into a Lisp-readable string. |
- class ansys.fluent.core.filereader.lispy.Env(params=(), args=(), outer=None)#
Bases:
dict
An environment: a dict of {‘var’:val} pairs, with an outer Env.
Methods:
- __init__(params=(), args=(), outer=None)#
Initialize Env.
- find(var)#
Find the innermost Env where var appears.
- Raises:
LookupError
If a key or index used on a mapping or sequence is invalid.
- class ansys.fluent.core.filereader.lispy.InputPort(file)#
Bases:
object
An input port.
Retains a line of chars.
Methods:
__init__
(file)Initialize InputPort.
Return the next token, reading new text into line buffer if needed.
Attributes:
- __init__(file)#
Initialize InputPort.
- next_token()#
Return the next token, reading new text into line buffer if needed.
- tokenizer = '\\s*(,@|[(\'`,)]|"(?:[\\\\].|[^\\\\"])*"|;.*|[^\\s(\'"`,;)]*)(.*)'#
- class ansys.fluent.core.filereader.lispy.Procedure(params, exp, env)#
Bases:
object
A user-defined Scheme procedure.
Methods:
__init__
(params, exp, env)Initialize Procedure.
- __init__(params, exp, env)#
Initialize Procedure.
- ansys.fluent.core.filereader.lispy.Sym(s, symbol_table={'=': '=', 'and': 'and', 'append': 'append', 'args': 'args', 'begin': 'begin', 'car': 'car', 'cdr': 'cdr', 'cons': 'cons', 'define': 'define', 'define-macro': 'define-macro', 'if': 'if', 'lambda': 'lambda', 'length': 'length', 'let': 'let', 'null?': 'null?', 'quasiquote': 'quasiquote', 'quote': 'quote', 'set!': 'set!', 'unquote': 'unquote', 'unquote-splicing': 'unquote-splicing'})#
Find or create unique Symbol entry for str s in symbol table.
- ansys.fluent.core.filereader.lispy.add_globals(self)#
Add some Scheme standard procedures.
- ansys.fluent.core.filereader.lispy.atom(token)#
Numbers become numbers; #t and #f are booleans; “…” string; otherwise Symbol.
- ansys.fluent.core.filereader.lispy.callcc(proc)#
Call proc with current continuation; escape only.
- Raises:
RuntimeWarning
If continuation can’t be continued.
- ansys.fluent.core.filereader.lispy.cons(x, y)#
Form a pair.
- ansys.fluent.core.filereader.lispy.count_unescaped_quotes(line)#
Get count of unescaped quotes.
- ansys.fluent.core.filereader.lispy.eval(x, env={'*': <built-in function mul>, '+': <built-in function add>, '-': <built-in function sub>, '/': <built-in function truediv>, '<': <built-in function lt>, '<=': <built-in function le>, '=': <built-in function eq>, '>': <built-in function gt>, '>=': <built-in function ge>, '__doc__': 'This module provides access to mathematical functions for complex\nnumbers.', '__file__': '/home/ansys/actions-runner/_work/_tool/Python/3.11.10/x64/lib/python3.11/lib-dynload/cmath.cpython-311-x86_64-linux-gnu.so', '__loader__': <_frozen_importlib_external.ExtensionFileLoader object>, '__name__': 'cmath', '__package__': '', '__spec__': ModuleSpec(name='cmath', loader=<_frozen_importlib_external.ExtensionFileLoader object>, origin='/home/ansys/actions-runner/_work/_tool/Python/3.11.10/x64/lib/python3.11/lib-dynload/cmath.cpython-311-x86_64-linux-gnu.so'), 'acos': <built-in function acos>, 'acosh': <built-in function acosh>, 'append': <built-in function add>, 'apply': <function add_globals.<locals>.<lambda>>, 'asin': <built-in function asin>, 'asinh': <built-in function asinh>, 'atan': <built-in function atan>, 'atan2': <built-in function atan2>, 'atanh': <built-in function atanh>, 'boolean?': <function add_globals.<locals>.<lambda>>, 'call/cc': <function callcc>, 'car': <function add_globals.<locals>.<lambda>>, 'cbrt': <built-in function cbrt>, 'cdr': <function add_globals.<locals>.<lambda>>, 'ceil': <built-in function ceil>, 'close-input-port': <function add_globals.<locals>.<lambda>>, 'close-output-port': <function add_globals.<locals>.<lambda>>, 'comb': <built-in function comb>, 'cons': <function cons>, 'copysign': <built-in function copysign>, 'cos': <built-in function cos>, 'cosh': <built-in function cosh>, 'degrees': <built-in function degrees>, 'display': <function add_globals.<locals>.<lambda>>, 'dist': <built-in function dist>, 'e': 2.718281828459045, 'eof-object?': <function add_globals.<locals>.<lambda>>, 'eq?': <built-in function is_>, 'equal?': <built-in function eq>, 'erf': <built-in function erf>, 'erfc': <built-in function erfc>, 'eval': <function add_globals.<locals>.<lambda>>, 'exp': <built-in function exp>, 'exp2': <built-in function exp2>, 'expm1': <built-in function expm1>, 'fabs': <built-in function fabs>, 'factorial': <built-in function factorial>, 'floor': <built-in function floor>, 'fmod': <built-in function fmod>, 'frexp': <built-in function frexp>, 'fsum': <built-in function fsum>, 'gamma': <built-in function gamma>, 'gcd': <built-in function gcd>, 'hypot': <built-in function hypot>, 'inf': inf, 'infj': infj, 'isclose': <built-in function isclose>, 'isfinite': <built-in function isfinite>, 'isinf': <built-in function isinf>, 'isnan': <built-in function isnan>, 'isqrt': <built-in function isqrt>, 'lcm': <built-in function lcm>, 'ldexp': <built-in function ldexp>, 'length': <built-in function len>, 'lgamma': <built-in function lgamma>, 'list': <function add_globals.<locals>.<lambda>>, 'list?': <function add_globals.<locals>.<lambda>>, 'load': <function add_globals.<locals>.<lambda>>, 'log': <built-in function log>, 'log10': <built-in function log10>, 'log1p': <built-in function log1p>, 'log2': <built-in function log2>, 'modf': <built-in function modf>, 'nan': nan, 'nanj': nanj, 'nextafter': <built-in function nextafter>, 'not': <built-in function not_>, 'null?': <function add_globals.<locals>.<lambda>>, 'open-input-file': <built-in function open>, 'open-output-file': <function add_globals.<locals>.<lambda>>, 'pair?': <function is_pair>, 'perm': <built-in function perm>, 'phase': <built-in function phase>, 'pi': 3.141592653589793, 'polar': <built-in function polar>, 'port?': <function add_globals.<locals>.<lambda>>, 'pow': <built-in function pow>, 'prod': <built-in function prod>, 'radians': <built-in function radians>, 'read': <function read>, 'read-char': <function readchar>, 'rect': <built-in function rect>, 'remainder': <built-in function remainder>, 'sin': <built-in function sin>, 'sinh': <built-in function sinh>, 'sqrt': <built-in function sqrt>, 'symbol?': <function add_globals.<locals>.<lambda>>, 'tan': <built-in function tan>, 'tanh': <built-in function tanh>, 'tau': 6.283185307179586, 'trunc': <built-in function trunc>, 'ulp': <built-in function ulp>, 'write': <function add_globals.<locals>.<lambda>>})#
Evaluate an expression in an environment.
- ansys.fluent.core.filereader.lispy.expand(x, toplevel=False)#
Walk tree of x, making optimizations/fixes, and signaling SyntaxError.
- ansys.fluent.core.filereader.lispy.expand_quasiquote(x)#
Expand
`x
=>'x
;`,x
=>x
;`(,@x y)
=>(append x y)
.
- ansys.fluent.core.filereader.lispy.is_pair(x)#
Check whether given value type is pair or not.
- ansys.fluent.core.filereader.lispy.let(*args)#
Get variable values.
- ansys.fluent.core.filereader.lispy.load(file_name)#
Eval every expression from a file.
- ansys.fluent.core.filereader.lispy.parse(in_port)#
Parse a program: read and expand/error-check it.
- ansys.fluent.core.filereader.lispy.read(in_port)#
Read a Scheme expression from an input port.
- ansys.fluent.core.filereader.lispy.readchar(in_port)#
Read the next character from an input port.
- ansys.fluent.core.filereader.lispy.repl(prompt='lispy> ', in_port=<ansys.fluent.core.filereader.lispy.InputPort object>, out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)#
A prompt-read-eval-print loop.
- ansys.fluent.core.filereader.lispy.require(x, predicate, msg='wrong length')#
Signal a syntax error if predicate is false.
- Raises:
SyntaxError
If syntax is invalid.
- ansys.fluent.core.filereader.lispy.to_string(x)#
Convert a Python object back into a Lisp-readable string.