Arc Forumnew | comments | leaders | submitlogin
3 points by absz 6467 days ago | link | parent

Unfortunately, your definition is broken. You just defined and, not aand. What you miss in aand is that it is bound to the previously-evaluated clause, so we have

  arc> (aand 3 (prn it) 10 (prn it) t)
  3
  10
  t
Yours, on the other hand (band), results in

  arc> (band 3 (prn it) 10 (prn it) t)
  Error: "reference to undefined identifier: __it"
. However, and is defined as

  (mac and args
    " Evaluates arguments till false is found else returns the last one.
      See also [[or]] [[aand]] [[andf]] [[andmap]] "
    (if args
        (if (cdr args)
            `(if ,(car args) (and ,@(cdr args)))
            (car args))
        't))
, which is roughly equivalent to your aand.

Also, a formatting tip: surround code by two blank lines and indent it to get it to format properly.



1 point by jeff303 6467 days ago | link

Ack, OK somehow I didn't even think to read the definition of and before. Now I can see how my definition is basically equivalent.

I noticed it being bound in aand before but wasn't sure why. Your example of applying prn seems useful but are there any other common similar idioms? Thanks for the reply.

-----

1 point by absz 6467 days ago | link

Well, you can write (aand (complex-expression 'that (might return) "nil") (frobnicate it)), but I can't think of any specific examples off the top of my head. There's also aif and awhen, which do similar things, and which are probably slightly more useful.

-----