aif bug and fix 18 points by byronsalty 4401 days ago | 6 comments One would expect that if you use the multiple ifs in the else if then "it" should get remapped on the subsequent tests. For example:`````` (aif 3 it 'else) 3 `````` So I'd think the following would be 3 also:`````` (aif () 'a 3 it 'else) nil `````` In the original version of aif it would return "nil" as it never gets reset after the first test.This is a simple fix:Original:`````` (mac aif (expr . body) `(let it ,expr (if it ,@body))) `````` Changed:`````` (mac aif (expr . body) (if (<= (len body) 2) `(let it ,expr (if it ,@body)) `(let it ,expr (if it ,(car body) (aif ,@(cdr body)))))) `````` Should I commit this to the git repo?
 1 point by byronsalty 4393 days ago | link So I had to see PG's solution in arc1. Pretty nice as it removes some duplication and has a simpler (and more efficient) way to determine if a sub aif is needed:`````` (mac aif (expr . body) `(let it ,expr (if it ,@(if (cddr body) `(,(car body) (aif ,@(cdr body))) body)))) `````` Duplication is removed by simple branching inside the `(let it ,expr ... part. And (cddr body) is shorter and more efficient than (<= (len body) 2).-----
 1 point by icemaze 4398 days ago | link I believe it should be:`````` (<= (len body) 1) `````` Also, this doesn't work with odd arguments. Working to fix that.-----
 1 point by icemaze 4398 days ago | link Here it is:`````` (mac aif args (let ln (len args) (if (is ln 0) nil (is ln 1) (car args) `(let it ,(car args) (if it ,(cadr args) (aif ,@(cddr args)))))))``````-----