Write Antril, run it in your browser and share it with a link. Programs are compiled to WebAssembly and run on your machine, not on the server.
Running programs is unavailable right now: the WebAssembly linker (wasm-ld, part of LLVM) is not installed on this server. You can still write, share and download code.
importSystem;
intonamespaceShapes
{
publicinterfaceIShape
{
Area() : f64;
Describe() : str => "a shape of area " + Area();
}
publicbaseclassShape : IShape
{
public:
Area() : f64;
virtualName() : str => "shape";
}
publicclassCircle : Shape
{
f64 radius;
public:
new(f64 radius) { this.radius = radius; }
overrideArea() : f64 => 3.14 * radius * radius;
overrideName() : str => "circle";
}
publicfinalclassSquare : Shape
{
f64 side;
public:
new(f64 side) { this.side = side; }
overrideArea() : f64 => side * side;
}
Main()
{
List<Shape> shapes = newList<Shape>();
shapes.Add(newCircle(1));
shapes.Add(newSquare(2));
loop (Shape s in shapes)
Console.WriteLine(s.Name() + ": " + s.Area());
IShape i = newSquare(3);
Console.WriteLine(i.Describe());
Shape first = shapes[0];
if (first isCircle c)
Console.WriteLine("a circle of area " + c.Area());
Square? square = first asSquare;
Console.WriteLine(square == null);
}
}
Output
Press Run (or Ctrl+Enter) to compile and run the program.
Input
What Console.ReadLine() reads, one line at a time.
Ctrl+Enter runs. Tab indents (Shift+Tab outdents); press Esc, then Tab, to leave the editor. A program may run for 10 seconds.