Subject: Re: cond-let-p
From: Erik Naggum <erik@naggum.net>
Date: Thu, 14 Feb 2002 13:58:51 GMT
Newsgroups: comp.lang.lisp
Message-ID: <3222683933311432@naggum.net>

* Manuel Giraud <giraud@sor.inria.fr>
| Is there in CL a form that let you do stuff like that : 
| 
| (cond-let ((a (func)) (* a a))
|           (t (error "meuh")))
| 
| Where a clause is accepted if (func) returns a non-nil value and then 'a'
| is bound to this value in the remaining consequent.

  You are probably aware of the ugly Scheme hack with -> to pass the result
  of the expression to a function in the body.  I toyed with a funcond
  (hybrid of funcall and cond) once that went like this:

(funcond ((func) (lambda (x) (* x x)))
         (t (lambda (x) (declare (ignore x)) (error "meuh"))))

  For fairly obvious reasons, I dropped this, having learned something
  about language design.

  The not too infrequently used way to do this, however, goes like this:

(let (x)
  (cond ((setq x (func))
         (* x x))
        (t (error "meuh"))))

  Which is probably a macro should do if you do not like to see it directly
  in your own code.

///
-- 
  In a fight against something, the fight has value, victory has none.
  In a fight for something, the fight is a loss, victory merely relief.