factorial example, bring back println for now

pull/5/head
azur 2023-03-07 04:41:34 +07:00
parent 50fdc4fe97
commit e6b31b39b0
2 changed files with 14 additions and 0 deletions

8
example/fact.hlm Normal file
View File

@ -0,0 +1,8 @@
func fact (n : num) num =
if n == 0 then
1
else
n * fact(n - 1)
;
println(fact(5));

View File

@ -154,6 +154,12 @@ pub fn translate_js_expr(expr: Expr) -> JSExpr {
match *f {
Expr::Sym(ref s) => {
match s.as_str() {
"println" => JSExpr::Call(
Box::new(JSExpr::Method(
Box::new(JSExpr::Sym("console".to_string())),
"log".to_string(),
)),
args.into_iter().map(translate_js_expr).collect()),
"print" => JSExpr::Call(
Box::new(JSExpr::Method(
Box::new(JSExpr::Method(