taking a break..
authorThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Sun, 12 Jan 2025 16:16:58 +0000 (16:16 +0000)
committerThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Sun, 12 Jan 2025 16:16:58 +0000 (16:16 +0000)
developer/document🖉/precise_loop.html [new file with mode: 0644]
developer/example/IndexTree/Example_SRTM_Diagonal.java
developer/example/IndexTree/SRTM_Diagonal.java

diff --git a/developer/document🖉/precise_loop.html b/developer/document🖉/precise_loop.html
new file mode 100644 (file)
index 0000000..8ca21b2
--- /dev/null
@@ -0,0 +1,131 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP&display=swap" rel="stylesheet">
+  <title>Precise Loops in RT Code</title>
+  <style>
+    body {
+      font-family: 'Noto Sans JP', Arial, sans-serif;
+      background-color: hsl(0, 0%, 0%);
+      color: hsl(42, 100%, 80%);
+      padding: 2rem;
+    }
+    .page {
+      padding: 3rem;
+      margin: 1.25rem auto;
+      max-width: 46.875rem;
+      background-color: hsl(0, 0%, 0%);
+      box-shadow: 0 0 0.625rem hsl(42, 100%, 50%);
+    }
+    h1 {
+      font-size: 1.5rem;
+      text-align: center;
+      color: hsl(42, 100%, 84%);
+      text-transform: uppercase;
+      margin-top: 1.5rem;
+    }
+    h2 {
+      font-size: 1.25rem;
+      color: hsl(42, 100%, 84%);
+      text-align: center;
+      margin-top: 2rem;
+    }
+    h3 {
+      font-size: 1.125rem;
+      color: hsl(42, 100%, 75%);
+      margin-top: 1.5rem;
+    }
+    p, li {
+      color: hsl(42, 100%, 90%);
+      text-align: justify;
+      margin-bottom: 1rem;
+    }
+    code {
+      font-family: 'Courier New', Courier, monospace;
+      background-color: hsl(0, 0%, 25%);
+      padding: 0.125rem 0.25rem;
+      color: hsl(42, 100%, 90%);
+    }
+  </style>
+</head>
+<body>
+<div class="page">
+  <header>
+    <h1>Precise Loops in RT Code</h1>
+    <p>© 2024 Thomas Walker Lynch - All Rights Reserved.</p>
+  </header>
+
+  <h2>Introduction</h2>
+  <p>In RT code, precise loops are an important construct designed to ensure that all iterations over a collection or sequence maintain clarity, correctness, and alignment with RT coding conventions. This document explains the characteristics, structure, and benefits of precise loops.</p>
+
+  <h2>Definition of Precise Loops</h2>
+  <p>A precise loop is a structured iteration pattern that ensures the following:</p>
+  <ul>
+    <li>Guards against empty collections by validating the precondition <code>can_read</code> before entering the loop.</li>
+    <li>Eliminates redundant checks by embedding exit conditions within the loop structure.</li>
+    <li>Preserves loop state through controlled stepping mechanisms.</li>
+  </ul>
+
+  <h3>Core Principles</h3>
+  <p>Precise loops consist of the following:</p>
+  <ul>
+    <li><strong>Initialization:</strong> Validate the readiness of the data source (e.g., an iterator or SRTM).</li>
+    <li><strong>Iterative Processing:</strong> Execute operations while maintaining control of the stepping mechanism.</li>
+    <li><strong>Termination:</strong> Exit the loop cleanly when no further elements are available.</li>
+  </ul>
+
+  <h2>Structure of a Precise Loop</h2>
+  <p>The following example demonstrates a typical precise loop for iterating over an SRTM:</p>
+  <pre><code>if( srtm.can_read() ){
+  do{
+    // Process the current element
+    process( srtm.read() );
+
+    // Advance to the next element
+    if( !srtm.can_step() ) break;
+    srtm.step();
+  }while( true );
+}</code></pre>
+
+  <h3>Key Characteristics</h3>
+  <ul>
+    <li><strong>Guard Clause:</strong> The <code>if</code> statement ensures the loop is entered only if the SRTM can read elements.</li>
+    <li><strong>Controlled Stepping:</strong> The <code>srtm.step()</code> call advances the iterator with a clear exit condition.</li>
+    <li><strong>Clear Termination:</strong> The loop exits as soon as <code>can_step</code> returns false.</li>
+  </ul>
+
+  <h2>Advantages of Precise Loops</h2>
+  <p>Using precise loops in RT code offers several benefits:</p>
+  <ul>
+    <li><strong>Clarity:</strong> Simplified and consistent iteration logic enhances readability.</li>
+    <li><strong>Efficiency:</strong> Reduces unnecessary checks, minimizing runtime overhead.</li>
+    <li><strong>Robustness:</strong> Ensures correctness by maintaining explicit control over loop state transitions.</li>
+    <li><strong>Expressiveness:</strong> Precise loops encapsulate logic succinctly, making the code easier to understand and maintain.</li>
+    <li><strong>Alignment with RT Philosophy:</strong> They embody the disciplined approach inherent to RT coding practices.</li>
+    <li><strong>Optimization Potential:</strong> The explicit structure of precise loops enables more predictable performance optimizations.</li>
+    <li><strong>Aesthetic Discipline:</strong> Their clean and minimalistic design promotes visually appealing and structured code.</li>
+  </ul>
+
+  <h2>Examples in Practice</h2>
+  <p>Here is an example of a precise loop for formatting a <code>Label</code>:</p>
+  <pre><code>StringBuilder formatted = new StringBuilder("Label(");
+Ariadne_SRTM_List<BigInteger> value_srtm = Ariadne_SRTM_List.make(Arrays.asList(value));
+if( value_srtm.can_read() ){
+  do{
+    formatted.append(value_srtm.read().toString());
+    if( !value_srtm.can_step() ) break;
+    formatted.append(" ,");
+    value_srtm.step();
+  }while( true );
+}
+formatted.append(")");</code></pre>
+  <p>This approach eliminates the need for special cases when inserting separators, ensuring consistent and concise code regardless of the collection size.</p>
+
+  <h2>Conclusion</h2>
+  <p>Precise loops represent a fundamental aspect of RT coding practices, providing a structured and reliable way to iterate over sequences. By adopting precise loops, developers can write code that is not only efficient and clear but also adheres to the highest standards of consistency and maintainability.</p>
+  <p>Their additional benefits, such as expressiveness, alignment with RT philosophy, optimization potential, and aesthetic discipline, further reinforce their value in creating high-quality, sustainable software.</p>
+</div>
+</body>
+</html>
index 6473a04..9b69fee 100644 (file)
@@ -1,39 +1,22 @@
 import java.util.List;
-import com.ReasoningTechnology.Ariadne.Ariadne_SRTM_List;
 
-public class Example_SRTM_Diagonal {
+public class Example_SRTM_Diagonal{
 
   public static void main(String[] args){
     System.out.println("Starting IndexTree SRTM Example");
 
     // Instantiate the IndexTree Diagonal SRTM
     SRTM_Diagonal srtm = SRTM_Diagonal.make();
-
     int step_count = 0;
-    do{
-      System.out.println("Diagonal " + step_count + ":");
-
-      // Read and print the current diagonal
-      List<Label> diagonal = srtm.read();
-      Ariadne_SRTM_List<Label> diagonal_srtm = Ariadne_SRTM_List.make(diagonal);
-
-      if( diagonal_srtm.can_read() ){
-        do{
-          Label label = diagonal_srtm.read();
-          System.out.print(label);
-
-          if( !diagonal_srtm.can_step() ) break;
-          System.out.println(" ");
-          diagonal_srtm.step();
-
-        }while(true);
-      }
-
-      step_count++;
-      if( step_count == 5 ) break; // Stop after 5 diagonals
-
-      srtm.step();
-    }while( true );
+    if( srtm.can_read() ){
+      do{
+        System.out.println(step_count ": " + diagonal);
+        if( !srtm.can_step() ) break;
+        if( step_count == 4 ) break; // Stop after 5 diagonals
+        step_count++;
+        srtm.step();
+      }while(true);
+    }
   }
 
 }
index c0a766c..a17592e 100644 (file)
@@ -123,9 +123,28 @@ public class SRTM_Diagonal extends Ariadne_SRTM{
   // Implementation of instance interface
   //
 
+  @Override
+  public String toString(){
+    StringBuilder formatted = new StringBuilder("SRTM_Diagonal(");
+    Ariadne_SRTM_List<Label> diagonal_srtm = Ariadne_SRTM_List.make(diagonal);
+
+    if( diagonal_srtm.can_read() ){
+      do{
+        formatted.append(diagonal_srtm.read().toString());
+        if( !diagonal_srtm.can_step() ) break;
+        diagonal_srtm.step();
+        formatted.append(" ,");
+      }while(true);
+    }
+
+    formatted.append(")");
+    return formatted.toString();
+  }
+
+
   @Override
   @SuppressWarnings("unchecked")
-  public List<Label> read() {
+  public List<Label> read(){
     return (List<Label>)super.read(); // Cast to ensure type consistency
   }