(define Fact
(lambda (N)
(if (= N 0) 1
(* N (Fact (- N 1))))) ; a lot of closing parentheses here
; use Fact
Python: def Fact(N):
if N == 0:
return 1
else:
return N * Fact(N - 1)
# use Fact
MANOOL: { let rec
{ Fact =
{ proc { N } as
: if N == 0 then 1 else
N * Fact[N - 1]
}
}
in
-- use Fact
}
Note that in the past, personally, I would prefer rather an "absolutely beautiful" Ada/VHDL/PL-SQL syntax: if ... then
...
else
...
end if; -- "very" explicit terminator
and: while ... loop
...
end loop; -- ditto
Note that also, personally, I do not like the Python/Nim/Occam approach to code indentation, but that's a whole new (orthogonal) story, and if you like, I could expose my rationale separately... for I := 0 to 99 do
if A[I] = Value then {note the lack of indentation}
Found := I;
... and that is the point of those colons in MANOOL: instead of writing: { for ... do
{ if ... then ... else
...
}
}
one can write: { for ... do
: if ... then ... else -- note that ":" is aligned with the braces since their syntactic roles are very similar
... -- but anyway MANOOL is a free-form language
}
Note that those colons are actually a means to get some "right-associative" syntax rules in the language (which are useful in the cases mentioned above). -- factorial
{ {extern "manool.org.18/std/0.2/all"} in
: let
{ Fact =
{ proc { N } as
: unless N.IsI48[] & (N >= 1 - 1) signal
{if (~)[N.IsI48[]] then TypeMismatch else InvariantViolation}
else
: var { Res = 1 } in
: do Res after
: while N <> 0 do Res = N * Res; N = N + ~1
}
}
in
Out.WriteLine[/* Out; */ "Factorial of 10 is "; Fact[10]$]
}
It has absolutely all syntactic features and even makes sense!
But what do you think about the article idea itself (apart from the syntax matters as it is orthogonal anyway)?