Arc Forumnew | comments | leaders | submitlogin
4 points by fallintothis 5010 days ago | link | parent

Bug report: aif knows there will be no destructuring in the variable (its variable is it), so it needn't worry whether the variable is actually an expression in certain contexts. But if you pass a destructuring expression to rif (which uses the same logic), there will be problems.

  arc> (rif (a b) (list 1 2) 'c 'd)
  Error: "Function call on inappropriate object 1 (2)"
  arc> (macex1 '(rif (a b) (list 1 2) 'c 'd))
  (let (a b) (list 1 2) (if (a b) (quote c) (quote d)))
It needs to be rewritten more like iflet.

  (mac rif (var expr . body)
    (w/uniq gv
      `(let ,gv ,expr
         (if ,gv
             (let ,var ,gv ,(car body))
             ,(if (cddr body)
                  `(rif ,var ,@(cdr body))
                  (cadr body))))))

  arc> (rif (a b) (list 1 2) (+ a b) 'c)
  3
  arc> (rif (a b) nil (+ a b) (list 3 4) (- a b))
  -1
  arc> (rif (a b) nil (+ a b) nil (- a b) 'c)
  c


1 point by evanrmurphy 5010 days ago | link

Good catch.

-----