mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
factorial example, bring back println for now
This commit is contained in:
parent
50fdc4fe97
commit
e6b31b39b0
8
example/fact.hlm
Normal file
8
example/fact.hlm
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
func fact (n : num) num =
|
||||||
|
if n == 0 then
|
||||||
|
1
|
||||||
|
else
|
||||||
|
n * fact(n - 1)
|
||||||
|
;
|
||||||
|
|
||||||
|
println(fact(5));
|
|
@ -154,6 +154,12 @@ pub fn translate_js_expr(expr: Expr) -> JSExpr {
|
||||||
match *f {
|
match *f {
|
||||||
Expr::Sym(ref s) => {
|
Expr::Sym(ref s) => {
|
||||||
match s.as_str() {
|
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(
|
"print" => JSExpr::Call(
|
||||||
Box::new(JSExpr::Method(
|
Box::new(JSExpr::Method(
|
||||||
Box::new(JSExpr::Method(
|
Box::new(JSExpr::Method(
|
||||||
|
|
Loading…
Reference in a new issue