Home /Modules/moral-capacitor/SLMoralCharge.sleela

SLMoralCharge.sleela

lib/moral-capacitor/SLMoralCharge.sleela · 107 line(s) · sleela

<< lib/moral-capacitor/SLMoralCharge.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLMoralCharge — the stored moral charge of a Moral
     Capacitor(TM). Charge is the signed sum of per-framework contributions:
     each ethical framework that endorses the operation adds charge, each that
     objects subtracts it. Charge is bounded by a maximum (a capacitor has finite
     capacity) and floored at zero on the discharge decision (negative net charge
     is simply "no moral basis"). The charge keeps per-framework attribution so a
     verdict can report which lens contributed what.
   
   Family: moral-capacitor. Held by SLMoralCapacitor. >>
#sleela 2.5
material;
class SLMoralCharge {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 10912;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-10";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }
  < net stored charge (may be negative before flooring) >
  int total;
  < capacity ceiling >
  int maxCharge;
  < number of frameworks that contributed >
  int contributions;
  < Per-framework running tallies (index by SLMoralFramework ordinal 1..5). >
  int deonCharge; int utilCharge; int virtueCharge; int benefCharge; int consentCharge;
  int configured;

  void configure(int capacity) {
    total = 0; maxCharge = capacity; contributions = 0;
    deonCharge = 0; utilCharge = 0; virtueCharge = 0; benefCharge = 0; consentCharge = 0;
    configured = 1;
  }

  < Add a framework's signed contribution (bounded to the capacity ceiling). >
  void add(int frameworkOrdinal, int delta) {
    total = total + delta;
    if (total > maxCharge) { total = maxCharge; }
    contributions = contributions + 1;
    if (frameworkOrdinal == 1)      { deonCharge = deonCharge + delta; }
    else if (frameworkOrdinal == 2) { utilCharge = utilCharge + delta; }
    else if (frameworkOrdinal == 3) { virtueCharge = virtueCharge + delta; }
    else if (frameworkOrdinal == 4) { benefCharge = benefCharge + delta; }
    else if (frameworkOrdinal == 5) { consentCharge = consentCharge + delta; }
  }

  < Reset to empty (the capacitor discharges after a decision). >
  void reset() {
    total = 0; contributions = 0;
    deonCharge = 0; utilCharge = 0; virtueCharge = 0; benefCharge = 0; consentCharge = 0;
  }

  < Net charge, floored at zero for the discharge comparison. >
  int level() { if (total < 0) { return 0; } return total; }
  int rawTotal()    { return total; }
  int capacity()    { return maxCharge; }
  int contributors(){ return contributions; }

  < The framework ordinal that contributed the most positive charge (0 if none). >
  int dominantFramework() {
    int best = 0; int bestVal = 0;
    if (deonCharge > bestVal)    { best = 1; bestVal = deonCharge; }
    if (utilCharge > bestVal)    { best = 2; bestVal = utilCharge; }
    if (virtueCharge > bestVal)  { best = 3; bestVal = virtueCharge; }
    if (benefCharge > bestVal)   { best = 4; bestVal = benefCharge; }
    if (consentCharge > bestVal) { best = 5; bestVal = consentCharge; }
    return best;
  }
}