From: Thomas Walker Lynch Date: Fri, 31 Jan 2025 10:12:02 +0000 (+0000) Subject: check in to support minor release of the GraphIndexTree example X-Git-Url: https://git.reasoningtechnology.com/usr/lib/python2.7/opcode.py?a=commitdiff_plain;h=4eba519a6b47d2b613692a513780e1420f7702c3;p=Ariadne check in to support minor release of the GraphIndexTree example --- diff --git a/developer/bash/Build b/developer/bash/Build deleted file mode 100755 index 2a18026..0000000 --- a/developer/bash/Build +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -java com.ReasoningTechnology."Ariadne".Build diff --git a/developer/deprecated/TM_SR_ND_Depth_initialize.java b/developer/deprecated/TM_SR_ND_Depth_initialize.java new file mode 100644 index 0000000..0dcb244 --- /dev/null +++ b/developer/deprecated/TM_SR_ND_Depth_initialize.java @@ -0,0 +1,57 @@ + // Given a context_path_tm and path_member_set. + // Initializes the path_member_set. Leaves head on last cell of context_path_tm. + // Returns a successful initlaization flag and possibly not null cycle_node_label + public class initialize{ + static public initialize f(context_path_tm ,path_member_set){ + initialize instance = new initialize(); + instance.g(context_path_tm ,path_member_set); + return instance; + } + public Label first_in_path_cycle_node_label = null; + public boolean success = false; + + protected void g(context_path_tm ,path_member_set){ + + if( context_path.isEmpty() ){ + System.out.println("TM_SR_NX_Depth::initialize required context_path is empty."); + success = false; + return; + } + + boolean is_cycle_node = false; + Ariadne_TM_SR_NX sibling_tm = null; + Ariadne_Label path_node_label = null; + + do{ + sibling_tm = context_path_tm.read(); + path_node_label = sibling_tm.read(); + if(path_node_label == null){ + System.out.println("TM_SR_NX_Depth::complete_context_path hit null path label on path"); + success = false; + return; + } + + is_cycle_node = path_member_set.contains(path_node_label); + if( is_cycle_node ) break; + + path_member_set.add( path_node_label ); + + if( !context_path_tm.can_step() ) break; + context_path_tm.step(); + + }while(true); + + if( is_cycle_node && context_path_tm.can_step() ){ + System.out.println + ( + "TM_SR_NX_Depth::initialize_path_member_set: cycle found in initial context_path." + ); + first_in_path_cycle_node_label = path_node_label; + success = false; + return; + } + + success = true; + return; + } + } diff --git "a/developer/document\360\237\226\211/bugs.txt" "b/developer/document\360\237\226\211/bugs.txt" index b4971df..2b975f7 100644 --- "a/developer/document\360\237\226\211/bugs.txt" +++ "b/developer/document\360\237\226\211/bugs.txt" @@ -87,3 +87,121 @@ 2025-01-24T10:54:26Z[] global substitute in this file _ND -> _NX +2025-01-26T15:35:15Z[] + + Chat GPT explaining why Java is giving a type mismatch error on two identical types. + Of course we should give Java a break, as it is a young experimental language. + + Yes, you're absolutely right! The generic bounds at the top of the class declaration guarantee that both GraphType and SiblingContext are tied to the same LabelType. Specifically: + + SiblingContext extends Ariadne_TM_SR_NX_F ensures that SiblingContext is a subtype of Ariadne_TM_SR_NX_F. + GraphType extends Ariadne_Graph_FD ensures that GraphType is a type of graph using the same LabelType. + Thus, conceptually, the cast should always be safe because graph.start() returns a type that satisfies the bounds of SiblingContext. The problem is that Java's type system is not sophisticated enough to understand this guarantee at runtime. + + + ``` + public class + Ariadne_Graph_FD + < LabelType extends Ariadne_Label ,NodeType extends Ariadne_Node_FD > + extends Ariadne_Graph + { + ... + @Override public Ariadne_TM_SR_NX_F start(){ + return Ariadne_TM_SR_NX_Array.make(start_list); + } + + ``` + + ``` + public class Ariadne_ContextStack + < + LabelType extends Ariadne_Label + ,NodeType extends Ariadne_Node_FD + ,SiblingContext extends Ariadne_TM_SR_NX_F + ,GraphType extends Ariadne_Graph_FD + > + { + ... + protected Ariadne_ContextStack(GraphType graph){ + this.graph = graph; + this.context_path = new ArrayList<>(); + this.context_path.add( graph.start() ); // <--- type mismatch error this line + this.path_member_set = new HashSet<>(); + } + + ... + + private final List context_path; + + ``` + + Sure looks to me like graph.start() is said to return the same Ariadne_TM_SR_NX_F, as that accepted by context_path.add(). The two + 'LabelType' are tied together at the top of the class ContextStack declaration. + However the compiler says: + + ``` + javac🖉/Ariadne_ContextStack.java:72: error: incompatible types: Ariadne_TM_SR_NX_F cannot be converted to SiblingContext + this.context_path.add( graph.start() ); + ^ + where LabelType,SiblingContext are type-variables: + LabelType extends Ariadne_Label declared in class Ariadne_ContextStack + SiblingContext extends Ariadne_TM_SR_NX_F declared in class Ariadne_ContextStack + ``` + + This is only one of many type errors that appear to be the same sort of thins. + It is a scary proposition to be start correcting the compiler and inserting + a bunch of casts. And which of these casts would be a mistake? + + small variation: + + ``` + javac🖉/Ariadne_ContextStack.java:74: error: incompatible types: Ariadne_TM_SR_NX_F cannot be converted to SiblingContext + SiblingContext s = t; + ``` + + add insult to injury, it gives a syntax error when a cast is added: + ``` + this.context_path.add( (SiblingContext)graph.start() ); + ``` + ``` + javac🖉/Ariadne_ContextStack.java:77: error: illegal start of type + this.context_path.add( (SiblingContext)graph.start() ); + ^ + ``` + + I thought I was going to be doing graph research, instead I am using + my time to learn the quirks of Java. Is it a more valuable activity? + + This works, but issues a warning, which can be surpressed. Great, a + language made to patch the main language. Very useful of the main + language needs patching: + + ``` + @SuppressWarnings("unchecked") + SiblingContext sc = (SiblingContext) graph.start(); + this.context_path.add( sc ); + ``` + +2025-01-31T07:43:30Z[] + + Suppose class A parent, class B child type. Java does not allow + class B to have static methods with the same type signature as + static methods in class A. + + This clobbers the factory method pattern because the factory is + always called `make`. + + The 'cure' is to require each class to have a unique factory + method name. Perhaps make_. So basically like a constructor + with 'make_' prepended. However, statics are already called + with their type name, so then a call to make would look like: + + T x = T.make_T(); + + Type names tend to be long in Java and there is no type + alias facility, so that will surely span more than one line. + + How many times can a person write type the same thing without + making an error? It is a game of 'Simon Says'. + + diff --git a/developer/example/GraphCycleCFinder/TM_SR_ND_Depth.java b/developer/example/GraphCycleCFinder/TM_SR_ND_Depth.java deleted file mode 100644 index ca02b2b..0000000 --- a/developer/example/GraphCycleCFinder/TM_SR_ND_Depth.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - -Each member of a `path` list is a node label. A path is created by traversing the graph. - -Imagine expanding each member of a path into a sibling list tm, with the cell under -the head being the label on the path. This is the context_path. - -Because a context path holds the siblings, it can be used as the state variable during -a tree traversal. - -*/ - -import java.util.HashSet; -import java.util.ArrayList; -import java.util.List; - -import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX; -import com.ReasoningTechnology.Ariadne.Ariadne_Graph; -import com.ReasoningTechnology.Ariadne.Ariadne_Node; -import com.ReasoningTechnology.Ariadne.Ariadne_Label; -import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX_Array; -import com.ReasoningTechnology.Ariadne.Ariadne_TM_SR_NX_List; - -class TM_SR_NX_Depth extends Ariadne_TM_SR_NX