From: Fabian <fb...@t-...> - 2010-05-21 10:30:50
|
Hallo Ralf, I have taken a look at it and it can very easily be extended for nested lambda expression. Its just one simple addition: (consp expr) -> (and (consp expr) (<> 'lambda (car expr))) which ensures, that he doesn't parses the arguments of nested lambdas. You can find the changes below, plus one trivial fix when you have a lambda without arguments. with best regards, Fabian ;;--------------------------- (defun lambda-largest-positional-arg (expr) (if (and (consp expr) (<> 'lambda (car expr)));;<----- (apply max 0 (mapcar lambda-largest-positional-arg expr)) (or (*lambda-positional-symbol* expr) 0) )) (defun lambda-has-ellipsis (expr) (if (and (consp expr) (<> 'lambda (car expr)));;<----- (apply or (mapcar lambda-has-ellipsis expr)) (= expr '..) )) (defun lambda-ellipsify (expr) (if (and (consp expr) (<> 'lambda (car expr)));;<----- (let (((head . tail) expr)) (if (= head '..) (if tail (error 'lambdafy "syntax-error: ellipsis must terminate s-expression") '..) (cons (lambda-ellipsify head) (lambda-ellipsify tail)) )) expr)) (defun lambdafy (expr) (let ((n (lambda-largest-positional-arg expr))) (if (lambda-has-ellipsis expr) (if (> n 0) (let ((args (domapcar ((i (range n))) (symbol-concat '$ (named (str i)))))) (rplacd (last args) '..) `(lambda ,args ,(lambda-ellipsify expr)) ) `(lambda .. ,(lambda-ellipsify expr)) ) `(lambda (,@(domapcar ((i (if (= n 0) () (range n))));;<----- (symbol-concat '$ (named (str i)))) ) ,expr) ))) On Thu, May 20, 2010 at 07:28:24AM -0700, Ralf Juengling wrote: > > Hm, I never thought about nested lambdas when I wrote the compact > lambda macro. While I think it's probably better to define a function > when lambdas become more complicated, this is clearly a bug in the > macro. > > It might take me a while before I have time to look at it. If you > want to take a shot at fixing it, the definition is in sys/sysenv.lsh. > > Thanks for reporting, > Ralf > |