Files
sybil/examples/factorial.sy
Alek Ratzloff d77bf48fe9 Add name-scanning pass to compiler
Compile::discover_locals now takes a Vec<SpExpr> instead of a single
SpExpr. It is also called before the compiler starts building the list
of instructions so that all names in the scope are available at
compile-time.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2022-02-16 15:19:14 -08:00

27 lines
315 B
Plaintext

[ :x x x ] :dup
[
dup!
[dup! 1 -! factorial! *!]
[:_ 1]
if!
]
:factorial
[
dup! print!
"! = " print!
factorial!
println!
]
:do-factorial
1 do-factorial!
2 do-factorial!
3 do-factorial!
4 do-factorial!
5 do-factorial!
6 do-factorial!
7 do-factorial!
8 do-factorial!
9 do-factorial!