Skip to content

User defined types #2901

@linas

Description

@linas

Seems its about time to start on proper runtime user-defined types. The simplest approach would seem to be to add a new type, say DynamicTypeNode, inheriting from TypeNode, and allowing constructions such as this:

	(TypeDefinitionLink
		(DynamicTypeNode "CatNode")
		(TypeNode "ConceptNode"))

after which the user would be able to writing things like (CatNode “Fuzzykins”).

Links are only a little harder. For example:

	(TypeDefinitionLink
		(DynamicTypeNode "CatLink")
		(EvaluationLink
			(TypeNode "PredicateNode")
			(TypeNode "ConceptNode")))

which would allow the user to then write things like

	(CatLink
		(PredicateNode "has")
		(ConceptNode "fur"))

while anything else would throw a syntax error. Full support would need to include support for SignatureLink, ArrowLink, and all the other type infrastructure, but that should be "easy", because that code is already there.

Under the covers (i.e. in the actual C++ code) this would have to be supported with a new DynamicTypeLink, so that (CatNode “Fuzzykins”) becomes, under the covers,

	(DynamicTypeLink
		(DynamicTypeNode "CatNode")
		(ConceptNode "Fuzzykins”)

i.e. it becomes exactly what the type definition called for. Pretty much all that the implementation needs to do is to modify the node/link printers to print the user-defined types. That, plus type-checking to force the user to use what they declared they would use... TruthValues would need to pretend they live in the right place, but this is probably trivial (no code changes needed). I believe that pattern matching support will also be trivial (no changes needed).

TypeDefinitionLink would special case the existing DefineLink. Obviously, once a type has been defined and used, it cannot be deleted ... at least, nut until all the instances are deleted first.

If you are reading this, and think this is a good idea, please upvote.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions