From 67319bf0410196787c753225f46057bc7c94beec Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 23 Dec 2012 05:31:15 +0000 Subject: Move towards standard Scheme syntax. git-svn-id: http://svn.drobilla.net/resp/trunk@442 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/compile.cpp | 2 +- src/constrain.cpp | 6 +++--- src/cps.cpp | 10 +++++----- src/depoly.cpp | 2 +- src/expand.cpp | 8 ++++---- src/flatten.cpp | 16 ++++++++-------- src/lift.cpp | 14 +++++++------- src/pprint.cpp | 10 +++++----- src/repl.cpp | 4 ++-- src/simplify.cpp | 8 ++++---- test/ack.resp | 7 ------- test/ack.scm | 7 +++++++ test/closure.resp | 6 ------ test/closure.scm | 6 ++++++ test/def.resp | 8 -------- test/def.scm | 8 ++++++++ test/deffn.resp | 3 --- test/deffn.scm | 3 +++ test/fac.resp | 7 ------- test/fac.scm | 7 +++++++ test/inlinefn.resp | 1 - test/inlinefn.scm | 1 + test/let-over-fn.resp | 7 ------- test/let-over-fn.scm | 7 +++++++ test/let.resp | 7 ------- test/let.scm | 7 +++++++ test/match.resp | 14 -------------- test/match.scm | 14 ++++++++++++++ test/nest.resp | 6 ------ test/nest.scm | 6 ++++++ test/poly.resp | 6 ------ test/poly.scm | 6 ++++++ test/quote.resp | 24 ------------------------ test/quote.scm | 24 ++++++++++++++++++++++++ test/string.resp | 4 ---- test/string.scm | 4 ++++ test/tup.resp | 6 ------ test/tup.scm | 6 ++++++ wscript | 26 +++++++++++++------------- 39 files changed, 159 insertions(+), 159 deletions(-) delete mode 100644 test/ack.resp create mode 100644 test/ack.scm delete mode 100644 test/closure.resp create mode 100644 test/closure.scm delete mode 100644 test/def.resp create mode 100644 test/def.scm delete mode 100644 test/deffn.resp create mode 100644 test/deffn.scm delete mode 100644 test/fac.resp create mode 100644 test/fac.scm delete mode 100644 test/inlinefn.resp create mode 100644 test/inlinefn.scm delete mode 100644 test/let-over-fn.resp create mode 100644 test/let-over-fn.scm delete mode 100644 test/let.resp create mode 100644 test/let.scm delete mode 100644 test/match.resp create mode 100644 test/match.scm delete mode 100644 test/nest.resp create mode 100644 test/nest.scm delete mode 100644 test/poly.resp create mode 100644 test/poly.scm delete mode 100644 test/quote.resp create mode 100644 test/quote.scm delete mode 100644 test/string.resp create mode 100644 test/string.scm delete mode 100644 test/tup.resp create mode 100644 test/tup.scm diff --git a/src/compile.cpp b/src/compile.cpp index 64dee08..69cce6d 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -230,7 +230,7 @@ resp_compile(CEnv& cenv, const AST* ast) throw() return compile_cons(cenv, call); else if (form == ".") return compile_dot(cenv, call); - else if (form == "def") + else if (form == "define") return compile_def(cenv, call); else if (form == "def-type") return compile_def_type(cenv, call); diff --git a/src/constrain.cpp b/src/constrain.cpp index e6e81a3..baa4ca8 100644 --- a/src/constrain.cpp +++ b/src/constrain.cpp @@ -173,7 +173,7 @@ constrain_fn(TEnv& tenv, Constraints& c, const ATuple* call) throw(Error) for (++i; i != call->end(); ++i) { const AST* exp = *i; const ATuple* call = exp->to_tuple(); - if (call && is_form(call, "def")) { + if (call && is_form(call, "define")) { const ASymbol* sym = call->list_ref(1)->as_symbol(); THROW_IF(defs.count(sym) != 0, call->loc, (format("`%1%' defined twice") % sym->str()).str()); @@ -429,11 +429,11 @@ constrain_list(TEnv& tenv, Constraints& c, const ATuple* tup) throw(Error) constrain_cons(tenv, c, tup); else if (form == ".") constrain_dot(tenv, c, tup); - else if (form == "def") + else if (form == "define") constrain_def(tenv, c, tup); else if (form == "def-type") constrain_def_type(tenv, c, tup); - else if (form == "fn") + else if (form == "lambda") constrain_fn(tenv, c, tup); else if (form == "if") constrain_if(tenv, c, tup); diff --git a/src/cps.cpp b/src/cps.cpp index c55f728..bb375a8 100644 --- a/src/cps.cpp +++ b/src/cps.cpp @@ -63,7 +63,7 @@ cps_fn(CEnv& cenv, const ATuple* fn, const AST* cont) assert(fn->fst()); assert(copyProt.head); List copy; - copy.push_back(cenv.penv.sym("fn")); + copy.push_back(cenv.penv.sym("lambda")); copy.push_back(copyProt); for (ATuple::const_iterator i = fn->iter_at(2); i != fn->end(); ++i) @@ -105,7 +105,7 @@ cps_call(CEnv& cenv, const ATuple* call, const AST* k) std::vector::const_reverse_iterator a = args.rbegin(); for (ExpVec::const_reverse_iterator e = exprs.rbegin(); e != exprs.rend(); ++e, ++a) { if (!is_value(cenv, *e)) { - cont = resp_cps(cenv, *e, tup(Cursor(), cenv.penv.sym("fn"), + cont = resp_cps(cenv, *e, tup(Cursor(), cenv.penv.sym("lambda"), tup(Cursor(), *a, 0), cont, 0)); @@ -145,7 +145,7 @@ cps_if(CEnv& cenv, const ATuple* aif, const AST* k) } else { /* const ASymbol* const condSym = cenv.penv.gensym("c"); - const ATuple* contFn = tup(loc, tenv.penv.sym("fn"), + const ATuple* contFn = tup(loc, tenv.penv.sym("lambda"), tup(cond->loc, argSym, tenv.penv.gensym("_k"), 0), tup(loc, tenv.penv.sym("if"), argSym, exp->(tenv, cont), @@ -166,9 +166,9 @@ resp_cps(CEnv& cenv, const AST* ast, const AST* k) throw() if (call) { const ASymbol* const sym = call->fst()->to_symbol(); const std::string form = sym ? sym->sym() : ""; - if (form == "def") + if (form == "define") return cps_def(cenv, call, k); - else if (form == "fn") + else if (form == "lambda") return cps_fn(cenv, call, k); else if (form == "if") return cps_if(cenv, call, k); diff --git a/src/depoly.cpp b/src/depoly.cpp index c6de0c1..0ee89c1 100644 --- a/src/depoly.cpp +++ b/src/depoly.cpp @@ -112,7 +112,7 @@ resp_depoly(CEnv& cenv, Code& code, const AST* ast) throw() const ATuple* const call = ast->as_tuple(); const ASymbol* const sym = call->fst()->to_symbol(); const std::string form = sym ? sym->sym() : ""; - assert(form != "fn"); + assert(form != "lambda"); if (form == "quote") return ast; else if (form == "def-type") diff --git a/src/expand.cpp b/src/expand.cpp index b50d627..0cbe118 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -41,7 +41,7 @@ expand_fn(PEnv& penv, const AST* exp, void* arg) THROW_IF(++a == tup->end(), exp->loc, "Unexpected end of `fn' form"); THROW_IF(!(*a)->to_tuple(), (*a)->loc, "First argument of `fn' is not a list"); const ATuple* prot = (*a++)->to_tuple(); - List ret(new ATuple(penv.sym("fn"), NULL, exp->loc)); + List ret(new ATuple(penv.sym("lambda"), NULL, exp->loc)); ret.push_back(prot); while (a != tup->end()) ret.push_back(penv.expand(*a++)); @@ -67,7 +67,7 @@ expand_def(PEnv& penv, const AST* exp, void* arg) argsExp.head->loc = exp->loc; List fnExp; - fnExp.push_back(penv.sym("fn")); + fnExp.push_back(penv.sym("lambda")); fnExp.push_back(argsExp.head); for (++i; i != tup->end(); ++i) fnExp.push_back(*i); @@ -94,9 +94,9 @@ PEnv::expand(const AST* exp) THROW_IF(tup->empty(), exp->loc, "Call to empty list"); - if (is_form(tup, "def")) + if (is_form(tup, "define")) return expand_def(*this, exp, NULL); - else if (is_form(tup, "fn")) + else if (is_form(tup, "lambda")) return expand_fn(*this, exp, NULL); else return expand_list(*this, tup); diff --git a/src/flatten.cpp b/src/flatten.cpp index 424e5a6..ca849fa 100644 --- a/src/flatten.cpp +++ b/src/flatten.cpp @@ -32,7 +32,7 @@ flatten_def(CEnv& cenv, Code& code, const ATuple* def) throw() const ASymbol* const sym = def->list_ref(1)->as_symbol(); const AST* const body = def->list_ref(2); - if (!is_form(body, "fn")) { + if (!is_form(body, "lambda")) { code.push_back(def); return NULL; } @@ -89,7 +89,7 @@ flatten_do(CEnv& cenv, Code& code, const ATuple* ado) throw() code.push_back(ret); } const ASymbol* sym = cenv.penv.gensym("doval"); - List def(Cursor(), cenv.penv.sym("def"), sym, ret, NULL); + List def(Cursor(), cenv.penv.sym("define"), sym, ret, NULL); code.push_back(def); cenv.setTypeSameAs(sym, ado); return sym; @@ -103,7 +103,7 @@ flatten_if(CEnv& cenv, Code& code, const ATuple* aif) throw() cond = aif->frst()->as_symbol(); } else { cond = cenv.penv.gensym("ifcond"); - List def(Cursor(), cenv.penv.sym("def"), cond, + List def(Cursor(), cenv.penv.sym("define"), cond, resp_flatten(cenv, code, aif->frst()), 0); cenv.setTypeSameAs(cond, aif->frst()); code.push_back(def); @@ -131,7 +131,7 @@ flatten_if(CEnv& cenv, Code& code, const ATuple* aif) throw() code.push_back(else_goto); List end(Cursor(), cenv.penv.sym("if-end"), if_lab, NULL); - List def(Cursor(), cenv.penv.sym("def"), result, end.head, NULL); + List def(Cursor(), cenv.penv.sym("define"), result, end.head, NULL); code.push_back(def); cenv.setTypeSameAs(end, aif); @@ -150,7 +150,7 @@ flatten_call(CEnv& cenv, Code& code, const ATuple* call) throw() arg = flat_i; } else { const ASymbol* sym = cenv.penv.gensym(); - List def(Cursor(), cenv.penv.sym("def"), sym, flat_i, NULL); + List def(Cursor(), cenv.penv.sym("define"), sym, flat_i, NULL); code.push_back(def); arg = sym; cenv.setTypeSameAs(sym, *i); @@ -159,7 +159,7 @@ flatten_call(CEnv& cenv, Code& code, const ATuple* call) throw() copy.push_back(arg); } const ASymbol* sym = cenv.penv.gensym(); - List def(Cursor(), cenv.penv.sym("def"), sym, copy.head, NULL); + List def(Cursor(), cenv.penv.sym("define"), sym, copy.head, NULL); code.push_back(def); cenv.setTypeSameAs(copy, call); @@ -175,10 +175,10 @@ resp_flatten(CEnv& cenv, Code& code, const AST* ast) throw() const ATuple* const call = ast->as_tuple(); const ASymbol* const sym = call->fst()->to_symbol(); const std::string form = sym ? sym->sym() : ""; - assert(form != "fn"); + assert(form != "lambda"); if (form == "quote") return ast; - else if (form == "def") + else if (form == "define") return flatten_def(cenv, code, call); else if (form == "def-type") return flatten_def_type(cenv, code, call); diff --git a/src/lift.cpp b/src/lift.cpp index 7f236d1..7fa834f 100644 --- a/src/lift.cpp +++ b/src/lift.cpp @@ -76,7 +76,7 @@ lift_def(CEnv& cenv, Code& code, const ATuple* def) throw() const ASymbol* const sym = def->list_ref(1)->as_symbol(); const AST* const body = def->list_ref(2); cenv.def(sym, body, cenv.type(body), NULL); - if (is_form(body, "fn")) + if (is_form(body, "lambda")) cenv.setName(body->as_tuple(), sym->str()); assert(def->list_ref(1)->to_symbol()); @@ -126,7 +126,7 @@ lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() for (ATuple::const_iterator p = fn->prot()->begin(); p != fn->prot()->end(); ++p) { const AST* paramType = (*tp++); - if (is_form(paramType, "Fn")) { + if (is_form(paramType, "lambda")) { const ATuple* fnType = new ATuple(cenv.tenv.var(), paramType->as_tuple(), paramType->loc); paramType = tup((*p)->loc, cenv.tenv.Tup, fnType, NULL); } @@ -136,7 +136,7 @@ lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() } // Write function prototype first for mutual and/or nested recursion - List declProt(fn->loc, cenv.penv.sym("fn"), 0); + List declProt(fn->loc, cenv.penv.sym("lambda"), 0); declProt.push_back(implProt); List decl(fn->loc, cenv.penv.sym("prot"), cenv.penv.sym(implNameStr), 0); decl.push_back(declProt); @@ -157,7 +157,7 @@ lift_fn(CEnv& cenv, Code& code, const ATuple* fn) throw() // Create definition for implementation fn const ASymbol* implName = cenv.penv.sym(implNameStr); - const ATuple* def = tup(fn->loc, cenv.penv.sym("def"), implName, impl.head, NULL); + const ATuple* def = tup(fn->loc, cenv.penv.sym("define"), implName, impl.head, NULL); // Define types before lifting body with return type as a variable List implT(Cursor(), type->fst(), implProtT.head, retTVar, 0); @@ -244,7 +244,7 @@ lift_call(CEnv& cenv, Code& code, const ATuple* call) throw() copy.push_front(cenv.penv.sym(cenv.liftStack.top().implName)); copy.push_front(cenv.penv.sym("call")); cenv.setTypeSameAs(copy, call); - } else if (is_form(call->fst(), "fn")) { + } else if (is_form(call->fst(), "lambda")) { /* Special case: ((fn ...) ...) * Lifting (fn ...) yields: (Closure _impl ...). * We don't want (call (. (Closure _impl ...) 1) (Closure _impl ...) ...), @@ -307,13 +307,13 @@ resp_lift(CEnv& cenv, Code& code, const AST* ast) throw() return lift_args(cenv, code, call); else if (form == ".") return lift_dot(cenv, code, call); - else if (form == "def") + else if (form == "define") return lift_def(cenv, code, call); else if (form == "def-type") return call; else if (form == "do") return lift_args(cenv, code, call); - else if (form == "fn") + else if (form == "lambda") return lift_fn(cenv, code, call); else if (form == "if") return lift_args(cenv, code, call); diff --git a/src/pprint.cpp b/src/pprint.cpp index bbb4904..ff19331 100644 --- a/src/pprint.cpp +++ b/src/pprint.cpp @@ -37,7 +37,7 @@ newline(ostream& out, unsigned indent) static inline void print_annotation(ostream& out, const AST* ast, unsigned indent, CEnv* cenv, bool print) { - if (is_form(ast, "def")) + if (is_form(ast, "define")) return; if (print) { @@ -143,8 +143,8 @@ print_to(ostream& out, const AST* ast, unsigned indent, CEnv* cenv, bool types) out << " "; } - if (form == "def") { - if (tup->rrst() && is_form(tup->frrst(), "fn")) { + if (form == "define") { + if (tup->rrst() && is_form(tup->frrst(), "lambda")) { // Abreviate (def (fn (...) ...)) out << "(" << (*i++) << " "; const ATuple* const fn = tup->frrst()->as_tuple(); @@ -179,7 +179,7 @@ print_to(ostream& out, const AST* ast, unsigned indent, CEnv* cenv, bool types) newline(out, indent + 2); print_list(out, tup, i, indent + 2, cenv, types, false); - } else if (form == "fn") { + } else if (form == "lambda") { // Print prototype (possibly with parameter type annotations) const ATuple* pat = (*i++)->as_tuple(); out << "("; @@ -266,7 +266,7 @@ pprint(ostream& out, const AST* ast, CEnv* cenv, bool types) print_to(out, ast, 0, cenv, types); print_annotation(out, ast, 0, cenv, types); out << endl; - if ((is_form(ast, "def") && is_form(ast->as_tuple()->frrst(), "fn")) + if ((is_form(ast, "define") && is_form(ast->as_tuple()->frrst(), "lambda")) || is_form(ast, "fn-end") || is_form(ast, "def-type")) out << endl; diff --git a/src/repl.cpp b/src/repl.cpp index 25da08a..9709656 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -134,7 +134,7 @@ compile(CEnv& cenv, const Code& parsed, Code& defs, bool& hasMain, const char* m for (Code::const_iterator i = stages.back().begin(); i != stages.back().end(); ++i) { const ATuple* call = (*i)->to_tuple(); if (call && (is_form(*i, "def-type") - || (is_form(*i, "def") && is_form(call->frrst(), "fn")))) { + || (is_form(*i, "define") && is_form(call->frrst(), "lambda")))) { resp_flatten(cenv, defs, call); } else if (call && is_form(*i, "prot")) { defs.push_back(*i); @@ -151,7 +151,7 @@ compile(CEnv& cenv, const Code& parsed, Code& defs, bool& hasMain, const char* m if (!exprs.empty()) { const ASymbol* main = cenv.penv.sym(mainName); - List mainT(Cursor(), cenv.penv.sym("Fn"), new ATuple(Cursor()), retT, NULL); + List mainT(Cursor(), cenv.penv.sym("lambda"), new ATuple(Cursor()), retT, NULL); cenv.def(main, NULL, mainT, NULL); defs.push_back( diff --git a/src/simplify.cpp b/src/simplify.cpp index d8d23f2..f1b1bec 100644 --- a/src/simplify.cpp +++ b/src/simplify.cpp @@ -65,7 +65,7 @@ simplify_match(CEnv& cenv, Code& code, const ATuple* match) throw() const ASymbol* tsym = cenv.penv.gensym("__tag"); - List def(match->loc, cenv.penv.sym("def"), tsym, tval.head, NULL); + List def(match->loc, cenv.penv.sym("define"), tsym, tval.head, NULL); cenv.setType(tval.head, cenv.tenv.named("Symbol")); List copyIf; @@ -98,13 +98,13 @@ simplify_match(CEnv& cenv, Code& code, const ATuple* match) throw() const ATuple* prot = new ATuple(osym, 0, Cursor()); const ATuple* protT = new ATuple(texp, 0, Cursor()); - List fn(Cursor(), cenv.penv.sym("fn"), prot, 0); + List fn(Cursor(), cenv.penv.sym("lambda"), prot, 0); int idx = 0; ATuple::const_iterator ti = texp->iter_at(1); for (ATuple::const_iterator j = pat->iter_at(1); j != pat->end(); ++j, ++ti, ++idx) { const AST* index = new ALiteral(T_INT32, idx, Cursor()); const AST* dot = tup(Cursor(), cenv.penv.sym("."), osym, index, 0); - const AST* def = tup(Cursor(), cenv.penv.sym("def"), *j, dot, 0); + const AST* def = tup(Cursor(), cenv.penv.sym("define"), *j, dot, 0); fn.push_back(def); } @@ -144,7 +144,7 @@ simplify_let(CEnv& cenv, Code& code, const ATuple* call) throw() { const ATuple* vars = call->list_ref(1)->to_tuple(); - List fn(Cursor(), cenv.penv.sym("fn"), NULL); + List fn(Cursor(), cenv.penv.sym("lambda"), NULL); List fnProt; List fnArgs; diff --git a/test/ack.resp b/test/ack.resp deleted file mode 100644 index 76fb397..0000000 --- a/test/ack.resp +++ /dev/null @@ -1,7 +0,0 @@ -(def (ack m n) - (if (= 0 m) (+ n 1) - (= 0 n) (ack (- m 1) 1) - (ack (- m 1) (ack m (- n 1))))) - -(ack 3 10) - diff --git a/test/ack.scm b/test/ack.scm new file mode 100644 index 0000000..b996bf6 --- /dev/null +++ b/test/ack.scm @@ -0,0 +1,7 @@ +(define (ack m n) + (if (= 0 m) (+ n 1) + (= 0 n) (ack (- m 1) 1) + (ack (- m 1) (ack m (- n 1))))) + +(ack 3 10) + diff --git a/test/closure.resp b/test/closure.resp deleted file mode 100644 index 8dad1c1..0000000 --- a/test/closure.resp +++ /dev/null @@ -1,6 +0,0 @@ -(def (multiplier factor) - (fn (x) (* (+ x 0) factor))) - -(def doubler (multiplier 2)) - -(doubler 3) diff --git a/test/closure.scm b/test/closure.scm new file mode 100644 index 0000000..baaaead --- /dev/null +++ b/test/closure.scm @@ -0,0 +1,6 @@ +(define (multiplier factor) + (lambda (x) (* (+ x 0) factor))) + +(define doubler (multiplier 2)) + +(doubler 3) diff --git a/test/def.resp b/test/def.resp deleted file mode 100644 index 52605b0..0000000 --- a/test/def.resp +++ /dev/null @@ -1,8 +0,0 @@ -(def foo - (fn (x) - (def y x) - (def z (+ x 1)) - z)) - -(foo 3) - diff --git a/test/def.scm b/test/def.scm new file mode 100644 index 0000000..6730b9d --- /dev/null +++ b/test/def.scm @@ -0,0 +1,8 @@ +(define foo + (lambda (x) + (define y x) + (define z (+ x 1)) + z)) + +(foo 3) + diff --git a/test/deffn.resp b/test/deffn.resp deleted file mode 100644 index c413ecd..0000000 --- a/test/deffn.resp +++ /dev/null @@ -1,3 +0,0 @@ -(def f (fn (x) (+ x 1))) - -(f 2) diff --git a/test/deffn.scm b/test/deffn.scm new file mode 100644 index 0000000..3550a39 --- /dev/null +++ b/test/deffn.scm @@ -0,0 +1,3 @@ +(define f (lambda (x) (+ x 1))) + +(f 2) diff --git a/test/fac.resp b/test/fac.resp deleted file mode 100644 index 0fb687c..0000000 --- a/test/fac.resp +++ /dev/null @@ -1,7 +0,0 @@ -; Factorial -(def (fac n) - (if (= 0 n) 1 - (* n (fac (- n 1))))) - -(fac 6) - diff --git a/test/fac.scm b/test/fac.scm new file mode 100644 index 0000000..0ed384d --- /dev/null +++ b/test/fac.scm @@ -0,0 +1,7 @@ +; Factorial +(define (fac n) + (if (= 0 n) 1 + (* n (fac (- n 1))))) + +(fac 6) + diff --git a/test/inlinefn.resp b/test/inlinefn.resp deleted file mode 100644 index 2f055bd..0000000 --- a/test/inlinefn.resp +++ /dev/null @@ -1 +0,0 @@ -((fn (x) (+ x 1)) 1) diff --git a/test/inlinefn.scm b/test/inlinefn.scm new file mode 100644 index 0000000..d5073e8 --- /dev/null +++ b/test/inlinefn.scm @@ -0,0 +1 @@ +((lambda (x) (+ x 1)) 1) diff --git a/test/let-over-fn.resp b/test/let-over-fn.resp deleted file mode 100644 index be3131f..0000000 --- a/test/let-over-fn.resp +++ /dev/null @@ -1,7 +0,0 @@ -(def inc - (let (x 1) - (fn (y) (+ x y)))) - -(inc 1) - - \ No newline at end of file diff --git a/test/let-over-fn.scm b/test/let-over-fn.scm new file mode 100644 index 0000000..5fc3b78 --- /dev/null +++ b/test/let-over-fn.scm @@ -0,0 +1,7 @@ +(define inc + (let (x 1) + (lambda (y) (+ x y)))) + +(inc 1) + + \ No newline at end of file diff --git a/test/let.resp b/test/let.resp deleted file mode 100644 index 49623a6..0000000 --- a/test/let.resp +++ /dev/null @@ -1,7 +0,0 @@ -(def one 1) - -(let (two (+ one 1) - three (+ one 2)) - (+ two three)) - - \ No newline at end of file diff --git a/test/let.scm b/test/let.scm new file mode 100644 index 0000000..67858b6 --- /dev/null +++ b/test/let.scm @@ -0,0 +1,7 @@ +(define one 1) + +(let (two (+ one 1) + three (+ one 2)) + (+ two three)) + + \ No newline at end of file diff --git a/test/match.resp b/test/match.resp deleted file mode 100644 index 0df0568..0000000 --- a/test/match.resp +++ /dev/null @@ -1,14 +0,0 @@ -; A Shape is either a Circle (w/ radius) or a Rectangle (w/ width/height) -(def-type (Shape) - (Circle Float) - (Rectangle Float Float)) - -; Return the area of s -(def (area s) - (match s - (Rectangle w h) (* w h) - (Circle r) (* 3.14159 r))) - -(def s (Rectangle 3.0 4.0)) - -(area s) \ No newline at end of file diff --git a/test/match.scm b/test/match.scm new file mode 100644 index 0000000..db19be1 --- /dev/null +++ b/test/match.scm @@ -0,0 +1,14 @@ +; A Shape is either a Circle (w/ radius) or a Rectangle (w/ width/height) +(def-type (Shape) + (Circle Float) + (Rectangle Float Float)) + +; Return the area of s +(define (area s) + (match s + (Rectangle w h) (* w h) + (Circle r) (* 3.14159 r))) + +(define s (Rectangle 3.0 4.0)) + +(area s) \ No newline at end of file diff --git a/test/nest.resp b/test/nest.resp deleted file mode 100644 index c15c453..0000000 --- a/test/nest.resp +++ /dev/null @@ -1,6 +0,0 @@ -(def (f x) - (def (g y) - (* y 2)) - (g (+ x 1))) - -(f 3) diff --git a/test/nest.scm b/test/nest.scm new file mode 100644 index 0000000..dac0f96 --- /dev/null +++ b/test/nest.scm @@ -0,0 +1,6 @@ +(define (f x) + (define (g y) + (* y 2)) + (g (+ x 1))) + +(f 3) diff --git a/test/poly.resp b/test/poly.resp deleted file mode 100644 index 1857fdf..0000000 --- a/test/poly.resp +++ /dev/null @@ -1,6 +0,0 @@ -(def (eq x y) (= x y)) - -(eq 1 2) -(eq 1 1) -(eq 10.0 20.0) -(eq 10.0 10.0) diff --git a/test/poly.scm b/test/poly.scm new file mode 100644 index 0000000..d642a0d --- /dev/null +++ b/test/poly.scm @@ -0,0 +1,6 @@ +(define (eq x y) (= x y)) + +(eq 1 2) +(eq 1 1) +(eq 10.0 20.0) +(eq 10.0 10.0) diff --git a/test/quote.resp b/test/quote.resp deleted file mode 100644 index 638e81b..0000000 --- a/test/quote.resp +++ /dev/null @@ -1,24 +0,0 @@ -(def-type (Expr) - (Symbol Symbol) - (Int Int) - (List Expr Expr) - (Empty)) - - -(def list (quote (2 a b c))) - -(def (len l) - (match l - (Symbol s) - 1 - - (Int i) - 1 - - (List h t) - (+ 1 (len t)) - - (Empty) - 0)) - -(len list) \ No newline at end of file diff --git a/test/quote.scm b/test/quote.scm new file mode 100644 index 0000000..4895d2e --- /dev/null +++ b/test/quote.scm @@ -0,0 +1,24 @@ +(def-type (Expr) + (Symbol Symbol) + (Int Int) + (List Expr Expr) + (Empty)) + + +(define list (quote (2 a b c))) + +(define (len l) + (match l + (Symbol s) + 1 + + (Int i) + 1 + + (List h t) + (+ 1 (len t)) + + (Empty) + 0)) + +(len list) \ No newline at end of file diff --git a/test/string.resp b/test/string.resp deleted file mode 100644 index ff980a9..0000000 --- a/test/string.resp +++ /dev/null @@ -1,4 +0,0 @@ -(def greeting "Hello, world!") - -greeting - diff --git a/test/string.scm b/test/string.scm new file mode 100644 index 0000000..1e1e81e --- /dev/null +++ b/test/string.scm @@ -0,0 +1,4 @@ +(define greeting "Hello, world!") + +greeting + diff --git a/test/tup.resp b/test/tup.resp deleted file mode 100644 index e856f81..0000000 --- a/test/tup.resp +++ /dev/null @@ -1,6 +0,0 @@ -(def t (Tup 1 2 3 4 5)) -(. t 0) -(. t 1) -(. t 2) -(. t 3) -(. t 4) diff --git a/test/tup.scm b/test/tup.scm new file mode 100644 index 0000000..502db54 --- /dev/null +++ b/test/tup.scm @@ -0,0 +1,6 @@ +(define t (Tup 1 2 3 4 5)) +(. t 0) +(. t 1) +(. t 2) +(. t 3) +(. t 4) diff --git a/wscript b/wscript index 4b2744d..ffd1da4 100644 --- a/wscript +++ b/wscript @@ -96,26 +96,26 @@ def test(ctx): Logs.error("ERROR: %s" % prog) # Basic lexical sanity - run_test('./test/def.resp', '4 : Int') - run_test('./test/deffn.resp', '3 : Int') - run_test('./test/inlinefn.resp', '2 : Int') - run_test('./test/nest.resp', '8 : Int') + run_test('./test/def.scm', '4 : Int') + run_test('./test/deffn.scm', '3 : Int') + run_test('./test/inlinefn.scm', '2 : Int') + run_test('./test/nest.scm', '8 : Int') # Basic data types - run_test('./test/string.resp', '"Hello, world!" : String') - run_test('./test/tup.resp', '5 : Int') + run_test('./test/string.scm', '"Hello, world!" : String') + run_test('./test/tup.scm', '5 : Int') # Recursive arithmetic functions - run_test('./test/fac.resp', '720 : Int') - run_test('./test/ack.resp', '8189 : Int') + run_test('./test/fac.scm', '720 : Int') + run_test('./test/ack.scm', '8189 : Int') # Closures - run_test('./test/closure.resp', '6 : Int') - run_test('./test/let-over-fn.resp', '2 : Int') - run_test('./test/let.resp', '5 : Int') + run_test('./test/closure.scm', '6 : Int') + run_test('./test/let-over-fn.scm', '2 : Int') + run_test('./test/let.scm', '5 : Int') # Algebraic data types - run_test('./test/match.resp', '12.0000 : Float') + run_test('./test/match.scm', '12.0000 : Float') # Quoting - run_test('./test/quote.resp', '4 : Int') + run_test('./test/quote.scm', '4 : Int') -- cgit v1.2.1