From: Stephen E. Bacher
Subject: Re: Problem with (apply #'or <list>)?
Date: 
Message-ID: <RNETMAIL9102220834209SEB1525@MVS.DRAPER.COM>
In article <··············@ccvax.ucd.ie> Eamonn Webster
<····@ccvax.ucd.ie> writes:

>I agree that it seems odd that special forms can't be APPLYed or FUNCALLed,
>however in your particular example, what you are missing are the functions
>EVERY, SOME, NOTANY and NOTEVERY, (CLtL, 1st Ed, page 250).
>
>  (apply #'or list-of-values)     == (some list-of-values)
>  (apply #'and list-of-values)    == (every list-of-values)

Wrong - should be:

   (apply #'or list-of-values)     == (some #'identity list-of-values)
   (apply #'and list-of-values)    == (every #'identity list-of-values)

If you don't have the IDENTITY function, use #'(lambda (x) x).

Or (n.p.i.), for the "and" case: (not (member nil list-of-values))

>As for the reason why special forms cannot be FUNCALLed or APPLYe, I reckon
>it has to do with the fact that it is unknown which (if any) args are to
>be evaluated or not.
>
>If SOME or EVERY won't do the job, you could use
> (eval (cons 'or list-of-values))....

NO WAY.  E.g.:

 (setq list-of-values '(a b c d e))
 (apply #'or list-of-values)

 ...pretending for a minute that the above works somehow...

 ==> (apply #'or '(a b c d e))

 But...

 (eval (cons 'or list-of-values))

 ==> (eval (cons 'or '(a b c d e)))
 ==> (eval '(or a b c d e))
 ==> *ERROR* ; if you're lucky

 What would work is

 (eval (cons 'or (mapcar #'(lambda (x) (list 'quote x)) list-of-values))

 The point is, however, that it is usually a bad idea to use EVAL.
 At least in this case it won't fail, since there are no variable
 scoping issues afoul of which to run.  But you take an efficiency hit.

 In general, if you find yourself using EVAL, you're probably taking
 a wrong approach somewhere.

 - SEB
From: ····@ccvax.ucd.ie
Subject: Re: Problem with (apply #'or <list>)?
Date: 
Message-ID: <47977.27d3f055@ccvax.ucd.ie>
In article ·······@mvs.draper.com ("Stephen E. Bacher") 

> In article <··············@ccvax.ucd.ie> Eamonn Webster
> <····@ccvax.ucd.ie> writes:
> 
>>  (apply #'or list-of-values)     == (some list-of-values)
>>  (apply #'and list-of-values)    == (every list-of-values)
> 
> Wrong - should be:
> 
>    (apply #'or list-of-values)     == (some #'identity list-of-values)
>    (apply #'and list-of-values)    == (every #'identity list-of-values)
> 
> If you don't have the IDENTITY function, use #'(lambda (x) x).

Thanks for the correction, I realised that I'd made a mistake the 
moment I had sent the mail, and it was too late.

I was thinking I'd got away with it when the discussion moved on to
the number of primitives that Common Lisp should have.

However he missed my second mistake and introduces one of his own
in my original note I wrote :
>>As for the reason why special forms cannot be FUNCALLed or APPLYe, I reckon
>>it has to do with the fact that it is unknown which (if any) args are to
>>be evaluated or not.
>>
OR and AND are MACROS not SPECIAL FORMS, but the comment still stands.

However the criticism that my use of EVAL doesn't work is invalid.
EVAL is a function, and thus evaluates the argument. So 
> 
>  ==> (eval (cons 'or '(a b c d e)))
>  ==> (eval '(or a b c d e))
>  ==> *ERROR* ; if you're lucky
is wrong.

>  In general, if you find yourself using EVAL, you're probably taking
>  a wrong approach somewhere.
> 
As for the use of eval. Well I occasionally work in other languages
and a common problem is that I want the user to enter not simply a
value, but an expression, (querying a database, for plotting graphs,
entering rules in a rule based traffic simulator).
In other languages you must read the input, parse it and evaluate it.
Referring to program variables is a pain.

In Lisp I can simply evaluate the form, being prepared to beep the user 
if any errors occur.


Eamonn Webster                       ····@ccvax.ucd.ie
Department of Computer Science       ····@ccvax.bitnet
University College Dublin            
Belfield
Dublin 4
Ireland

Phone  +353-1-693244 ext 2484        Fax: +353-1-697262