21 lines
648 B
Python
21 lines
648 B
Python
class Atom:
|
|
car: Atom | int | str | bool | None
|
|
cdr: Atom | None
|
|
|
|
def __init__(self, car: Atom|int|str|bool|None, cdr: Atom|None):
|
|
self.car = car
|
|
self.cdr = cdr
|
|
|
|
def setval(self, atom: Atom | int | str | bool | None):
|
|
self.car = atom
|
|
|
|
def append(self, atom: Atom):
|
|
self.cdr = atom
|
|
|
|
def __str__(self):
|
|
if type(self.car) is Atom:
|
|
return "(" + self.car.__str__() + ("" if self.cdr is None else (" " + self.cdr.__str__())) + ")"
|
|
elif self.car is None:
|
|
return "()"
|
|
else:
|
|
return self.car + ("" if self.cdr is None else self.cdr.__str__()) |