Comments
Loading Dream Comments...
You must be logged in to write a comment - Log In
We start off by setting up this code's GHOST (Global Hosting Online Segment Table), which is a kernel (::SHE::) table mapping the segments that our code references (called "virtual addresses") into LBA's (Logical Block Addresses) and their corresponding page frames.
£::DEMO::
£::MATHS::
£::UTILS::
This is modelled on the "#include" lines found at the beginning of every C++ (or C) program.
Then we define two functions, "formula" and "main".
formula <:: { (a=%!1, b=%!2, c=%!3, x, y);
The "struct" in round parentheses is a "frame" of local variables. It represents datanames (a, b, c, x, y) visible to the following function, just as in C++ you may say "int a, b, c;". As ::SHE+ILA: is a dynamic interactive language, we don't need to bind a datatype to each variable, just name it (so it gets a place on the "stack").
Note that "%" represents the implicit parameter to the function, which is passed as a Buf (i.e. a vector of values or internal addresses), and "!" is "quick subscript" operator (somewhat like "[...]"). So %!1 gives us the first passed parameter, %!2 the second, and so on. (The number of actual parameters passed is "#%" , i.e. the length of the vector "%").
Then we come to the function body.
x <:: (0 - b + sqrt (b^2 - 4*a*c)) $/ (2*a);
and similarly for y. This is the standard quadratic formula, setting locals x and y to the two roots of the equation (whose coefficients are a, b, c).
Then comes our final expression (x, y) which is our return value (no need for the keyword "return", we do it the Algol 68 way :)