2.1.1.1.1.2. racketinterpreter.classes.data¶
-
class
Boolean
(value: bool)¶ Bases:
racketinterpreter.classes.data.Data
A boolean.
- Example
>>> Boolean(True) #t >>> Boolean(False) #f
-
class
ComplexNum
(real: racketinterpreter.classes.data.RealNum, imaginary: racketinterpreter.classes.data.RealNum)¶ Bases:
racketinterpreter.classes.data.Number
A complex number.
A number with a real and imaginary part.
-
property
imaginary
¶
-
is_integer
() → bool¶ - Example
>>> ComplexNum(Integer(1), Integer(0)).is_integer() True >>> ComplexNum(RationalNum(4, 3), Integer(0)).is_integer() False >>> ComplexNum(Integer(1), Integer(2)).is_integer() False
-
is_zero
() → bool¶ - Example
>>> ComplexNum(InexactNum(0.0), Integer(0)).is_zero() True >>> ComplexNum(RationalNum(3, 4), Integer(0)).is_zero() False >>> ComplexNum(Integer(5), Integer(2)).is_zero() False
-
property
precedence
¶ An indicator of which object’s method will be called for binary operations.
When performing binary operations on Numbers, the implementation on the object with the higher precedence will be used.
- Returns
This object’s precedence.
- Return type
int
-
property
real
¶
-
property
-
class
ConsList
(value: List[racketinterpreter.classes.data.Data])¶ Bases:
racketinterpreter.classes.data.List
A constructed (non-empty) list.
-
class
Data
(value: Optional[Any] = None)¶ Bases:
object
Data from the output of the interpretation process.
- Parameters
value – The value of the data.
-
class
DataType
¶ Bases:
type
The metaclass of a class representing data.
-
class
ExactNum
(numerator: int, denominator: int = 1)¶ Bases:
racketinterpreter.classes.data.RealNum
-
property
precedence
¶ An indicator of which object’s method will be called for binary operations.
When performing binary operations on Numbers, the implementation on the object with the higher precedence will be used.
- Returns
This object’s precedence.
- Return type
int
-
property
-
class
InexactNum
(value: float)¶ Bases:
racketinterpreter.classes.data.RealNum
-
property
precedence
¶ An indicator of which object’s method will be called for binary operations.
When performing binary operations on Numbers, the implementation on the object with the higher precedence will be used.
- Returns
This object’s precedence.
- Return type
int
-
property
-
class
Integer
(value: int)¶ Bases:
racketinterpreter.classes.data.ExactNum
-
property
denominator
¶ The denominator of the number.
- Raises
AttributeError – If this number does not have a denominator an error will be raised.
- Returns
The denominator.
- Return type
int
-
property
numerator
¶ The numerator of the number.
- Raises
AttributeError – If this number does not have a numerator an error will be raised.
- Returns
The numerator.
- Return type
int
-
property
precedence
¶ An indicator of which object’s method will be called for binary operations.
When performing binary operations on Numbers, the implementation on the object with the higher precedence will be used.
- Returns
This object’s precedence.
- Return type
int
-
property
-
class
List
(value: List[racketinterpreter.classes.data.Data])¶ Bases:
racketinterpreter.classes.data.Data
A list.
- Example
>>> List([Integer(68), Boolean(False), Symbol("'sym")]) (list 68 #f 'sym) >>> List([]) '()
-
class
NaturalNum
(value: int)¶
-
class
Number
(value: Union[complex, float, int])¶ Bases:
racketinterpreter.classes.data.Data
A number.
-
property
denominator
¶ The denominator of the number.
- Raises
AttributeError – If this number does not have a denominator an error will be raised.
- Returns
The denominator.
- Return type
int
-
property
imaginary
¶
-
is_integer
() → bool¶ Is this number an integer?
- Raises
NotImplementedError – By default an implementation is not provided in the Number base class.
- Returns
True if this number is an integer.
- Return type
bool
-
is_zero
() → bool¶ Is this number equal to zero?
- Raises
NotImplementedError – By default an implementation is not provided in the Number base class.
- Returns
True if this number is equal to zero.
- Return type
bool
-
property
numerator
¶ The numerator of the number.
- Raises
AttributeError – If this number does not have a numerator an error will be raised.
- Returns
The numerator.
- Return type
int
-
property
precedence
¶ An indicator of which object’s method will be called for binary operations.
When performing binary operations on Numbers, the implementation on the object with the higher precedence will be used.
- Returns
This object’s precedence.
- Return type
int
-
property
real
¶
-
property
-
class
Procedure
(name: str)¶ Bases:
racketinterpreter.classes.data.Data
A procedure.
- Example
>>> Procedure('factorial') #<procedure:factorial>
-
class
RationalNum
(numerator: int, denominator: int)¶ Bases:
racketinterpreter.classes.data.ExactNum
-
property
denominator
¶ The denominator of the number.
- Raises
AttributeError – If this number does not have a denominator an error will be raised.
- Returns
The denominator.
- Return type
int
-
property
numerator
¶ The numerator of the number.
- Raises
AttributeError – If this number does not have a numerator an error will be raised.
- Returns
The numerator.
- Return type
int
-
property
precedence
¶ An indicator of which object’s method will be called for binary operations.
When performing binary operations on Numbers, the implementation on the object with the higher precedence will be used.
- Returns
This object’s precedence.
- Return type
int
-
property
-
class
RealNum
(value: Union[float, int])¶ Bases:
racketinterpreter.classes.data.Number
-
property
imaginary
¶
-
is_integer
() → bool¶ Is this number an integer?
- Raises
NotImplementedError – By default an implementation is not provided in the Number base class.
- Returns
True if this number is an integer.
- Return type
bool
-
is_zero
() → bool¶ Is this number equal to zero?
- Raises
NotImplementedError – By default an implementation is not provided in the Number base class.
- Returns
True if this number is equal to zero.
- Return type
bool
-
property
precedence
¶ An indicator of which object’s method will be called for binary operations.
When performing binary operations on Numbers, the implementation on the object with the higher precedence will be used.
- Returns
This object’s precedence.
- Return type
int
-
property
real
¶
-
property
-
class
String
(value: str)¶ Bases:
racketinterpreter.classes.data.Data
A string.
- Example
>>> String('Hello World!') "Hello World!" >>> String('') ""
-
copy
() → racketinterpreter.classes.data.String¶ Create a copy of this string.
- Example
>>> String('Hello World!').copy() "Hello World!"
-
islower
() → racketinterpreter.classes.data.Boolean¶
-
isnumeric
() → racketinterpreter.classes.data.Boolean¶
-
isspace
() → racketinterpreter.classes.data.Boolean¶
-
isupper
() → racketinterpreter.classes.data.Boolean¶
-
lower
() → racketinterpreter.classes.data.String¶ Create a copy of a lowercase version of this string.
- Example
>>> String('Hello World!').lower() "hello world!"
-
upper
() → racketinterpreter.classes.data.String¶ Create a copy of an uppercase version of this string.
- Example
>>> String('Hello World!').upper() "HELLO WORLD!"
-
class
StructData
¶ Bases:
object
Data representing a struct.
-
class
StructDataFactory
¶ Bases:
object
A factory for creating struct data types.
-
static
create
(struct_name: str, fields: List[str]) → racketinterpreter.classes.data.StructDataType¶
-
static
-
class
StructDataType
¶ Bases:
type
The metaclass of a class representing a struct.
-
class
Symbol
(value: str)¶ Bases:
racketinterpreter.classes.data.Data
A symbol.
- Example
>>> Symbol("'anything") 'anything >>> Symbol("'can=be_a-symbo1") 'can=be_a-symbo1