Home /Modules/user-interface/philosophers-constructor.sleela

philosophers-constructor.sleela

lib/user-interface/example/science/philosophers-constructor.sleela · 87 line(s) · sleela

<< example/science/philosophers-constructor.sleela
   A runnable SLeeLa example of the philosophers "perfect Constructor" (the
   lib/philosophers package): a Guide chain written with the "::" growth
   separator, a time-bounded contract, a favor mechanism, and the orthogonal
   Ordain axis.

   This example shows BOTH outcomes: first a Constructor whose favor is GRANTED
   (the object lives free), then one whose favor is WITHHELD (construction does
   not run) -- so the honest-runnability contract is visible.

   Run:
     SLEELA_SHA256_MANIFEST=./security/sha256-manifest.json \
     ./impl/build/sleela run example/science/philosophers-constructor.sleela >>
#sleela 2.5
material;
<< Family: example. Worker-class runnable; baseline metadata identity per the
   Metadata Class standard (SLEELA.syntax section 15). >>
class PhilosophersConstructorExample {
  String metaVersion = "1.0.0";
  int metaId = 0;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-24";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-24";
  int metaScienceRating = 6;
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }

  < Build one Constructor, run it for a duration, and print its report. >
  void buildOne(String title, int quorum, int seconds) {
    print("-- " + title + " --");

    SLPhilosopherConstructor ctor = new SLPhilosopherConstructor();
    ctor.create();
    ctor.admit(3);

    ctor.guide("Patch", 3, true);
    ctor.guide("Seed", 4, false);
    ctor.guide("Aim", 6, true);
    ctor.guide("Guide", 12, true);

    print("chain:  " + ctor.chainText());
    print("colors: " + ctor.colorManifest());

    ctor.requireNotice(quorum);

    << Only two imparts name seated Guides (Patch, Aim); so two Notices are
       caught. With quorum 2 favor is granted; with quorum 3 it is withheld. >>
    String[] imparts = new String[3];
    imparts[0] = "Patch";
    imparts[1] = "Aim";
    imparts[2] = "Approach";

    boolean alive = ctor.run(imparts, seconds);
    print("verdict: " + ctor.verdict());
    print("lives free: " + alive + "   phase: " + ctor.phase() + "   quorum: " + quorum);
    print("");
  }

  void main() {
    print("=== philosophers: the perfect Constructor (example) ===");

    < Read the orthogonal Ordain axis over a few seatings. >
    SLOrdain ordain = new SLOrdain();
    ordain.create();
    print("ordain(Patch): " + ordain.reading(3));
    print("ordain(Aim):   " + ordain.reading(6));
    print("ordain(crown): " + ordain.reading(20));
    print("");

    < favor granted: quorum 2, two Notices caught >
    buildOne("favor granted", 2, 90);

    < favor withheld: quorum 3, still only two Notices caught >
    buildOne("favor withheld", 3, 90);

    print("done");
  }
}