-
Notifications
You must be signed in to change notification settings - Fork 2
Generic knowledge representation
Looking for methods to make dynamic software systems able to do symbolic computations and software transformations, I found Marvin Minsky's book A Framework for Representing Knowledge.
Frames seem to be an ideal model for data and program representation, which can be thought more widely as the knowledge. When we speak about knowledge, we think not only static data structures but also methods for its transformations.
When I look on frame concept, with some extensions to be able to hold data in order, I see its native conformance with most features we want in the homoiconic software model:
- generic objects encapsulate their states in slots (attributes)
- loosen OOP not requires classes so allows more flexible abstraction
- attribute grammar elements widely used in compilers design
- slots and nested vector able to work as a stack provides Forth-like virtual machine if we allow frames to execute its slots
- original Minsky concept also proposes executable ability, which allows doing inference in a procedural manner (computable slots)
Mainstream languages with hard typing such as Java and C++ require all data containers must hold single type only. To implement heterogenous containers like lists available in Python and JavaScript, we must inherit all types from the base virtual class Frame, and use containers holds Frame* pointers. It has some disadvantage -- we need to do boxing for all types including primitives like numbers and strings.
class Frame:
def __init__(self,V):
self.type = self.__class__.__name__.lower()
self.val = V
self.slot = { }
self.nest = [ ]
- type is a class/type tag mark every object
- val is a single scalar value has a type of implementation language
- slot is a string-keyed associative array point to other frames
- nest is ordered container works simultaneously as vector, stack, and queue
As you see, any primitive object in a system will have extra fields, which increases memory consumptions. On the other side, numbers can have optional attributes like unit and tolerance (good for CAD systems).