MCPcopy
hub / github.com/fluentpython/example-code-2e / to_string

Function to_string

18-with-match/lispy/original/lispy.py:93–101  ·  view source on GitHub ↗

Convert a Python object back into a Lisp-readable string.

(x)

Source from the content-addressed store, hash-verified

91 return Sym(token)
92
93def to_string(x):
94 "Convert a Python object back into a Lisp-readable string."
95 if x is True: return "#t"
96 elif x is False: return "#f"
97 elif isa(x, Symbol): return x
98 elif isa(x, str): return repr(x)
99 elif isa(x, list): return '('+' '.join(map(to_string, x))+')'
100 elif isa(x, complex): return str(x).replace('j', 'i')
101 else: return str(x)
102
103def load(filename):
104 "Eval every expression from a file."

Callers 4

replFunction · 0.85
__init__Method · 0.85
add_globalsFunction · 0.85
requireFunction · 0.85

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected