From: Manuel Giraud
Subject: cond-let-p
Date: 
Message-ID: <qs38z9w4bdg.fsf@yoko.inria.fr>
Hi,
        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.

-- 
Jake:"See those berries? That's our breakfast! See that stream? That's
our drinking water!"
Daria:"See that skeleton? That's our future." 
-From "The Teachings Of Don Jake." 

_Manuel Giraud_

From: Michael Parker
Subject: Re: cond-let-p
Date: 
Message-ID: <9f023346.0202140757.5e1370b9@posting.google.com>
Manuel Giraud <······@sor.inria.fr> wrote in message news:<···············@yoko.inria.fr>...
> Hi,
>         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.

Not built-in.  The cond in scheme does this, although with a different
syntax.  I've got a CL version of the scheme cond on my webpage at
http://www.geocities.com/mparker762.  It's called bcond (for binding
cond),
accepts basically the scheme syntax, and goes to some effort to be
efficient
about it all.
From: Dr. Edmund Weitz
Subject: Re: cond-let-p
Date: 
Message-ID: <m3aducuwin.fsf@bird.agharta.de>
Manuel Giraud <······@sor.inria.fr> writes:

> Hi,
>         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.

Maybe something like that:

(defmacro cond-let (&rest clauses)
  (if (null clauses)
      nil
      (let* ((first-clause (car clauses))
             (let-form (car first-clause))
             (var (car let-form)))
        (if (eq let-form t)
            `(progn ,@(cdr first-clause))
            `(let (,let-form)
              (if ,var
                  ,@(cdr first-clause)
                  (cond-let ,@(cdr clauses))))))))

Edi.

-- 

Dr. Edmund Weitz
Hamburg
Germany

The Common Lisp Cookbook
<http://agharta.de/cookbook/>
From: Erik Naggum
Subject: Re: cond-let-p
Date: 
Message-ID: <3222683933311432@naggum.net>
* Manuel 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.
From: Wolfhard Buß
Subject: Re: cond-let-p
Date: 
Message-ID: <m3ofisne2c.fsf@buss-14250.user.cis.dfn.de>
Manuel Giraud <······@sor.inria.fr> writes:

> 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.

I don't like cond-let ;)
But there is Paul Graham's anaphoric version of cond

 (defmacro acond (&rest clauses)
   (if (null clauses)
       nil
       (let ((cl1 (car clauses))
             (sym (gensym)))
         `(let ((,sym ,(car cl1)))
            (if ,sym
                (let ((it ,sym)) ,@(cdr cl1))
                (acond ,@(cdr clauses)))))))

which binds the 'free' variable it to the value of
the condition.

Example:
 (acond ((1+ 20) (+ it it))
        (t (error "meuh"))))
 => 42

-- 
Some Lispers don't like anaphorisms.
From: Thomas F. Burdick
Subject: Re: cond-let-p
Date: 
Message-ID: <xcvr8nnam28.fsf@apocalypse.OCF.Berkeley.EDU>
·····@gmx.net (Wolfhard Bu�) writes:

> Manuel Giraud <······@sor.inria.fr> writes:
> 
> > 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.
> 
> I don't like cond-let ;)

Me neither, but I like it more than Graham's weird stealing of IT.

> But there is Paul Graham's anaphoric version of cond
> 
>  (defmacro acond (&rest clauses)
>    (if (null clauses)
>        nil
>        (let ((cl1 (car clauses))
>              (sym (gensym)))
>          `(let ((,sym ,(car cl1)))
>             (if ,sym
>                 (let ((it ,sym)) ,@(cdr cl1))
>                 (acond ,@(cdr clauses)))))))
> 
> which binds the 'free' variable it to the value of
> the condition.
> 
> Example:
>  (acond ((1+ 20) (+ it it))
>         (t (error "meuh"))))
>  => 42

I prefer to use:

  (defmacro binding-cond (var &rest clauses)
    `(let (,var)
       (cond ,(loop for (pred . body) in clauses
                    if (eq pred t) collect (cons pred body)
                    else collect `((setf ,var ,pred) ,@body)))))

Example:

  (binding-cond this
    ((member x foo) foo)
    ((member y foo) (binding-cond that
                      ((member x bar) bar)
                      ((member y bar) (frob this that))
                      (t y)))
    (t x))

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Larry Clapp
Subject: Re: cond-let-p
Date: 
Message-ID: <19lh4a.35r.ln@rabbit.ddts.net>
In article <···············@yoko.inria.fr>, Manuel Giraud wrote:
> Hi,
>         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.

Paul Graham defines a condlet macro in On Lisp.  See page 146.  On Lisp is
available online at www.paulgraham.com.

-- Larry Clapp, who's gotten up to p. 147 in On Lisp.  :)
From: Pekka P. Pirinen
Subject: Re: cond-let-p
Date: 
Message-ID: <uvgcs2c66.fsf@globalgraphics.com>
Larry Clapp <······@theclapp.org> writes:
> In article <···············@yoko.inria.fr>, Manuel Giraud wrote:
> >         Is there in CL a form that let you do stuff like that : 
> > 
> >         (cond-let ((a (func)) (* a a))
> >                   (t (error "meuh")))
> 
> Paul Graham defines a condlet macro in On Lisp.  See page 146.  On Lisp is
> available online at www.paulgraham.com.

Everybody and their dog seems to be doing this.  LispWorks has an
extension called WHEN-LET
<http://www.xanalys.com/software_tools/reference/lwl42/LWRM-U/html/lwref-u-257.htm#pgfId-889998>
that is like WHEN rather than COND:
  (when-let (position (search string1 string2))
    (print position))
We haven't often missed an else-branch, but perhaps that's one of
those things that you don't miss, but you end up using a lot if it's
available.
-- 
Pekka P. Pirinen
     "A man never speaks of himself without losing something.  What he says
in his disfavor is always believed but when he commends himself, he arouses
mistrust."   - Michel Montaigne
From: Francis Leboutte
Subject: Re: cond-let-p
Date: 
Message-ID: <8ln97u8tb90tp7orfqe8krblabmotbm5u6@4ax.com>
···············@globalgraphics.com (Pekka P. Pirinen) wrote:


>Everybody and their dog seems to be doing this.  LispWorks has an
>extension called WHEN-LET
><http://www.xanalys.com/software_tools/reference/lwl42/LWRM-U/html/lwref-u-257.htm#pgfId-889998>
>that is like WHEN rather than COND:
>  (when-let (position (search string1 string2))
>    (print position))

my dog is lazy, he is doing:

>U(9): (when-bind (v -1 #'oddp #'minusp)
           T)
t


when-bind var form &rest predicates

--
www.algo.be
Logo programming : www.algo.be/logo.html