Spent several hours today trying to figure out why my #elisp code was misbehaving. Turns out, I made a mistake while trying to be clever. Instead of doing:
(when (and cond1 cond2)
stuff
...)I did:
(and cond1 cond2
stuff
...)...which would only work if every instruction in
stuff returned a non-nil value.I should stop trying to be clever.
Edit: when, not while
like this
Dave Marquardt reshared this.
Dave Marquardt
in reply to Jonathan Lamothe • • •I was wondering why not use "if" rather than "when" here. Well, if is a bit different in that it only allows a single expression as the THEN part. But I wasn't so wrong. "when" is defined as a macro essentially like this:
(list 'if cond (cons 'progn body))
Jonathan Lamothe
in reply to Dave Marquardt • •whenwhen I don't have anelseclause. That way I don't have to bother with aprogn. I just wish that I had thought to extend that logic toand.Jonathan Lamothe
in reply to Jonathan Lamothe • •I should probably throw some comments in here, but essentially the
associn thewhenblock always returnsnilon the first iteration of the loop, and if it can't progress past that point, it'll always returnnilon subsequent loops and nothing will ever happen. As a result, any list I might feed into this function is always going to result in aniloutput.