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

Function atom

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

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

(token)

Source from the content-addressed store, hash-verified

78quotes = {"'":_quote, "`":_quasiquote, ",":_unquote, ",@":_unquotesplicing}
79
80def atom(token):
81 'Numbers become numbers; #t and #f are booleans; "..." string; otherwise Symbol.'
82 if token == '#t': return True
83 elif token == '#f': return False
84 elif token[0] == '"': return token[1:-1]
85 try: return int(token)
86 except ValueError:
87 try: return float(token)
88 except ValueError:
89 try: return complex(token.replace('i', 'j', 1))
90 except ValueError:
91 return Sym(token)
92
93def to_string(x):
94 "Convert a Python object back into a Lisp-readable string."

Callers 1

read_aheadFunction · 0.70

Calls 2

SymFunction · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected