useful comments

pull/8/head
KFL 2018-04-15 12:05:45 -07:00
parent 7f50ecf63c
commit 1120fc6b2e
2 changed files with 7 additions and 6 deletions

View File

@ -259,18 +259,17 @@ namespace Schemy
Symbol def = (Symbol)xs[0];
object v = xs[1]; // sym or (sym+)
List<object> body = xs.Skip(2).ToList(); // expr or expr+
if (v is List<object>)
if (v is List<object>) // defining function: ([define|define-macro] (f arg ...) body)
{
// (define (f args) body)
var args = (List<object>)v;
Utils.CheckSyntax(xs, args.Count > 0);
var f = args[0];
var @params = args.Skip(1).ToList();
return expand(new List<object> { def, f, Enumerable.Concat(new object[] { Symbol.LAMBDA, @params }, body).ToList() }, false);
}
else
else // defining variable: ([define|define-macro] id expr)
{
Utils.CheckSyntax(xs, xs.Count == 3); // (define x expr)
Utils.CheckSyntax(xs, xs.Count == 3);
Utils.CheckSyntax(xs, v is Symbol);
var expr = expand(xs[2], false);
if (Symbol.DEFINE_MACRO.Equals(def))
@ -385,6 +384,9 @@ namespace Schemy
}
else if (Symbol.LAMBDA.Equals(exprList[0]))
{
// Two lambda forms:
// - (lambda (arg ...) body): each arg is bound to a value
// - (lambda args body): args is bound to the parameter list
Union<Symbol, List<Symbol>> parameters;
if (exprList[1] is Symbol)
{

View File

@ -18,5 +18,4 @@
(define rest (cdr args))
(define test1 (if (equal? (car first) 'else) '#t (car first)))
(define expr1 (car (cdr first)))
`(if ,test1 ,expr1
(cond ,@rest))))))
`(if ,test1 ,expr1 (cond ,@rest))))))