lispy#

Provides a module for Scheme Interpreter in Python.

Classes:

Env([params, args, outer])

An environment: a dict of {'var':val} pairs, with an outer Env.

InputPort(file)

An input port.

Procedure(params, exp, env)

A user-defined Scheme procedure.

Symbol

Symbol.

Functions:

Sym(s[, symbol_table])

Find or create unique Symbol entry for str s in symbol table.

add_globals(self)

Add some Scheme standard procedures.

atom(token)

Numbers become numbers; #t and #f are booleans; "..." string; otherwise Symbol.

callcc(proc)

Call proc with current continuation; escape only.

cons(x, y)

Form a pair.

count_unescaped_quotes(line)

Get count of unescaped quotes.

eval(x[, env])

Evaluate an expression in an environment.

expand(x[, toplevel])

Walk tree of x, making optimizations/fixes, and signaling SyntaxError.

expand_quasiquote(x)

Expand `x => 'x; `,x => x; `(,@x y) => (append x y)

is_pair(x)

Check whether given value type is pair or not.

let(*args)

Get variable values.

load(file_name)

Eval every expression from a file.

parse(in_port)

Parse a program: read and expand/error-check it.

read(in_port)

Read a Scheme expression from an input port.

readchar(in_port)

Read the next character from an input port.

repl([prompt, in_port, out])

A prompt-read-eval-print loop.

require(x, predicate[, msg])

Signal a syntax error if predicate is false.

to_string(x)

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

find(var)

Find the innermost Env where var appears.

__init__(params=(), args=(), outer=None)#
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)

next_token()

Return the next token, reading new text into line buffer if needed.

Attributes:

__init__(file)#
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)

__init__(params, exp, env)#
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.

class ansys.fluent.core.filereader.lispy.Symbol#

Bases: str

Symbol.

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