mirror of https://github.com/microsoft/schemy.git
useful comments
parent
7f50ecf63c
commit
1120fc6b2e
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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))))))
|
Loading…
Reference in New Issue