Sather    hoch http://www.gnu.org/software/sather
  ähnliche Sprachen: Blue   Eiffel  
  Beschreibung: Sather is an Eiffel-like language. It features:
  • Pre/Post Conditions, Invariants
  • Closures
  • Iterators
  • Multiple Inheritance through mixins
  • Parameterized Classes
  • Abstact datatypes (similar to Java's interfaces), classes, partial classes, code sharing by "including", immutable classes
  • Supertypes (inserting classes not below, but above an existing class)
  • Contravariance conformance - unlike Eiffel's unsafe covariance.
  • Short cuts for attributes, constants etc, or variable declaration without specifying explicitly the type.
  • Garbage Collector
  • Very fast


  Fakultät   Michael Neumann
class MAIN is

  fac(n : INT) : INT is
    if n <= 1 then
      return 1;
    else
      return n * fac(n-1);
    end
  end;

  main is
    #OUT + fac(6) + "\n";
  end;

end;
Berechnet die Fakultät. Ergibt 720.


 Hello World   Michael Neumann
class MAIN is

   main is
      #OUT + "Hello World\n";
   end; -- main
   
end; -- class MAIN
Gibt "Hello World" auf dem Bildschirm aus.


 Squares (1)   Michael Neumann
class MAIN is

  squares : STR is
    r ::= "";          -- implicit type
    loop r := r + (1.upto!(10) ^ 2) + " " end;
    return r;
  end;

  main is
    #OUT + squares + "\n";
  end;

end;
Gibt die Quadrate von 1 bis 10 aus.


 Squares (2)   Michael Neumann
class MAIN is

  -- squares! is an iterator yielding the squares of the 
  -- numbers from "from" to "to".
  squares!(once from : INT, once to : INT) : INT is
    loop
      i ::= from.upto!(to);
      yield i * i
    end
  end;

  main is
    loop #OUT + squares!(1, 10) + " " end;
    #OUT + "\n";
  end;

end;
Gibt die Quadrate von 1 bis 10 aus.


 Squares (3)   Michael Neumann
class MAIN is

  squares is
    a : ARRAY{INT}    := |1,2,3,4,5,6,7,8,9,10| ;
    b : ROUT{INT}:INT := bind(_.pow(2));  -- a closure 

    a.map(b);

    loop #OUT + a.elt! + " " end;
  end;

  main is
    squares;
    #OUT + "\n";
  end;

end;
Gibt die Quadrate von 1 bis 10 aus.