Quadratic equation in Io

Example for versions Io-2008-01-07

To output several pieces of data in one line, a simple trick is used: these pieces of data form a list, and then the list is concatenated using join command, and the result is printed as one string.

A := File standardInput readLine asNumber;
if(A==0, 
   "Not a quadratic equation." println;
   return;
);
B := File standardInput readLine asNumber;
C := File standardInput readLine asNumber;
D := B*B-4*A*C;
A2 := 2*A;
if(D==0,
   list("x = ", (-B/A2) asString) println;
   return;
);
sqrtD := D abs sqrt;
if(D>0,
   list("x1 = ", ((-B+sqrtD)/A2) asString) join println;
   list("x2 = ", ((-B-sqrtD)/A2) asString) join println,
   list("x1 = (", (-B/A2) asString, ", ", (sqrtD/A2) asString, ")") join println;
   list("x2 = (", (-B/A2) asString, ", ", (-sqrtD/A2) asString, ")") join println;
);