Home /Modules/alphabet/Letter.sleela

Letter.sleela

lib/alphabet/Letter.sleela · 115 line(s) · sleela

<< lib/alphabet/Letter.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines Letter, a single glyph in an Alphabet — the symbol, its
     position in the written order, and whether it is a vowel. The humblest,
     most important class a user of Sleela will ever meet, because everything
     written is written out of these.
   
   Letter is a NATURAL / LOADABLE MODULE sharing the common module contract
   (load / loaded / moduleName / describe). It holds glyph state only; an
   Alphabet owns an ordered run of Letters.
   
   Syntax 1.8+: Letter now also offers a one-line CONSTRUCTOR —
   `new Letter(glyph, order, vowel)` — so a glyph can be built in a single
   expression (`let a = new Letter("A", 1, true);`) instead of the load()+set()
   two-step. The two-step contract (load / set) is retained unchanged, so every
   existing 1.3 caller — including Alphabet.append()'s `new Letter(); load()` —
   keeps working: a zero-argument `new Letter()` is still valid under 1.8.
   
   Family: alphabet. >>
#sleela 2.5
material;
< Unified SLeeLa SDK front-end object. >
class Letter {
  < ---- 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 = 10327;
  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-07";
  < 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; }

  static final String MODULE = "Letter";

  int loadedFlag;
  < the character itself, e.g. "A" >
  String glyph;
  < 1-based position within its alphabet >
  int order;
  < true for vowels, false otherwise >
  boolean vowel;

  < --- syntax 1.8 constructor -------------------------------------------- >
  < Build a fully formed Letter in one expression. Marks the module loaded, so >
  < a constructed Letter satisfies loaded() just like a load()+set() one. >
  Letter(String symbol, int position, boolean isVowel) {
    this.loadedFlag = 1;
    this.glyph = symbol;
    this.order = position;
    this.vowel = isVowel;
  }

  < --- loadable-module contract (zero-arg path, unchanged) ---------------- >
  < A zero-argument `new Letter()` remains valid under 1.8; load() initialises >
  < an empty glyph for the classic two-step build used by Alphabet.append(). >
  void load() { loadedFlag = 1; glyph = ""; order = 0; vowel = false; }
  boolean loaded() { return loadedFlag == 1; }
  String moduleName() { return MODULE; }

  void set(String symbol, int position, boolean isVowel) {
    if (symbol != null) { glyph = symbol; }
    if (position >= 0) { order = position; }
    vowel = isVowel;
  }

  String symbol() { return glyph; }
  int position() { return order; }
  boolean isVowel() { return vowel; }
  boolean isConsonant() { return !vowel; }

  boolean sameAs(Letter other) {
    if (other == null) { return false; }
    return glyph == other.symbol();
  }

  String yn(boolean v) { if (v) { return "yes"; } return "no"; }

  String describe() {
    return MODULE + " '" + glyph + "' order=" + order + " vowel=" + yn(vowel);
  }
}