30 lines
881 B
Python
30 lines
881 B
Python
# Copyright (c) PARRRATE T&V 2021. All rights reserved.
|
|
|
|
from bu4.evaluation.av.evtype import evtype
|
|
from bu4.evaluation.constructs.eilambda import EILambda
|
|
from bu4.evaluation.constructs.evaluable import Evaluable
|
|
from bu4.indexing.constructs.indexed import Indexed
|
|
from bu4.parsing.codes import CODE_MAKE
|
|
|
|
__all__ = ('ILambda',)
|
|
|
|
|
|
class ILambda(Indexed):
|
|
def __init__(self, value: Indexed, table: list[int], *, memoize: bool):
|
|
self.value = value
|
|
self.table = table
|
|
self.memoize = memoize
|
|
|
|
def attach(self, ev: evtype) -> Evaluable:
|
|
return EILambda(
|
|
[ev[i] for i in self.table],
|
|
self.value,
|
|
memoize=self.memoize
|
|
)
|
|
|
|
def __str__(self):
|
|
return f'(){self.value}'
|
|
|
|
def __bytes__(self):
|
|
return bytes([CODE_MAKE, self.memoize, len(self.table), *self.table, *bytes(self.value)])
|