My photo

Mildred's Website

Tags:
My avatar

GoogleTalk, Jabber, XMPP address:
mildred@jabber.fr


GPG Public Key
(Fingerprint 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 9A7D 2E2B)

PIPE(E)

Tue 29 Mar 2011, 02:34 PM comp en lisaac

Inspired from ruby #Array:

Section Header

  + name := PIPE(E);

Section Private

  + blc :{;BOOLEAN,E};

Section Public

  - create blc_:{;BOOLEAN,E} :SELF <-
  (
    blc := blc_;
    Self
  );

  - read :(BOOLEAN,E) <- blc.value

  - map blc:{E;X} :PIPE(X) <-
  ( // Upvalue Self
    PIPE(X).clone.make {
      + have_e :BOOLEAN;
      + e :E;
      (have_e, e) := Self.read;
      have_e.if {
        e := blc.value e;
      };
      have_e, e
    }
  );

  - select blc:{E;BOOLEAN} :PIPE(E) <-
  ( // Upvalue Self
    PIPE(E).clone.make {
      + have_e :BOOLEAN;
      + e :E;
      (have_e, e) := Self.read;
      have_e.if {
        blc.value e.if_false {
          have_e := FALSE;
        };
      };
      have_e, e
    }
  );

  - flatten_1 :PIPE(X) <-
  ( // Upvalue Self, buffer
    + buffer :PIPE(X);
    PIPE(X).clone.make {
      + have_e, have_x :BOOLEAN;
      + e :E;
      + x :X;
      buffer.is_null.if_false {
        (have_e, e) := buffer.read;
        have_e.if_false {
          buffer := NULL;
        };
      };
      buffer.is_null.if {
        (have_e, e) := Self.read;
        have_e.if {
          (buffer ?= e).is_null.if_false {
            (have_x, x) := buffer.read
            // TODO: cas où have_e = FALSE (buffer est vide)
          };
        };
      };
      have_x, x
    }
  );

  - to_array_of_e :ARRAY(E) <-
  ( + result :ARRAY(E);
    + have_e :BOOLEAN;
    + e :E;
    {(have_e, e) := read;
    have_e
    }.while_do {
      result.add_last e;
    };
    result
  );

TODO: