From: ······@bridgetrix.com
Subject: Applying AND
Date: 
Message-ID: <ncohen-2606991146510001@max3-64.ip.realtime.net>
Is there a good way to apply AND to a list.  I'm translating a compound
logical expression, and it would seem clean to have a line of the code
look like:


((eql (car wff) 'and)
   (apply AND (translate-exp (cdr wff))))

Something like:

((eql (car wff) 'and)
   (not (find nil (translate-exp (cdr wff)))))  OR

   (every #identify ...)

   works, but isn't as satisfying.  

  Any ideas?

   Neil

Neil Cohen
Bridge Trix
Producers of the Bobby Wolff Bridge Mentoring Series
http://www.bridgetrix.com

From: Johan Kullstam
Subject: Re: Applying AND
Date: 
Message-ID: <m2pv2iyh2j.fsf@sophia.axel.nom>
······@bridgetrix.com writes:

> Is there a good way to apply AND to a list.  I'm translating a compound
> logical expression, and it would seem clean to have a line of the code
> look like:
> 
> 
> ((eql (car wff) 'and)
>    (apply AND (translate-exp (cdr wff))))
> 
> Something like:
> 
> ((eql (car wff) 'and)
>    (not (find nil (translate-exp (cdr wff)))))  OR
> 
>    (every #identify ...)
> 
>    works, but isn't as satisfying.  

what exactly do you find wrong with

(every #'identity ....)

???

it works.  it satisfies me.  *shrug*

-- 
J o h a n  K u l l s t a m
[········@ne.mediaone.net]
Don't Fear the Penguin!
From: Vassil Nikolov
Subject: Re: Applying AND
Date: 
Message-ID: <l03130300b39adfffa928@195.138.129.68>
On 1999-06-26 11:46 -0600,
······@bridgetrix.com wrote:

  > Is there a good way to apply AND to a list.  I'm translating a compound
  > logical expression, and it would seem clean to have a line of the code
  > look like:
  > 
  > 
  > ((eql (car wff) 'and)
  >    (apply AND (translate-exp (cdr wff))))
  > 
  > Something like:
  > 
  > ((eql (car wff) 'and)
  >    (not (find nil (translate-exp (cdr wff)))))  OR
  > 
  >    (every #identify ...)
  > 
  >    works, but isn't as satisfying.  
  > 
  >   Any ideas?

Strictly speaking, AND cannot be applied, of course, as it is not
a function, and to achieve precisely the same effect, one should
call EVAL.  In more detail:

Assume L is the list ((FOO X) (BAR Y)).  The effect of
(AND (FOO X) (BAR Y)) can be achieved by (EVAL `(AND ,@L)) or
(EVAL (CONS 'AND L)).  Note that  (EVERY #'IDENTITY L) returns T.

If, on the other hand, the list which contains the arguments
to be passed to AND contains the logical values, not the forms,
then I, too, cannot see any problem with (NOT (FIND NIL ...)) or
(EVERY #'IDENTITY ...).

In any case, I think it would be better to have instead code along
the following lines:

  ((symbolp (first wff))
   (funcall (op-handler (first wff)) (mapcar #'wff-eval (rest wff))))

(data-driven, instead of a big COND), or one could use a generic
function call instead of the whole COND:

  (wff-op (first wff) (mapcar #'wff-eval (rest wff)))

and

  (defmethod wff-op ((op (eql 'and)) args)
    (every #'identity args))

  (defmethod wff-op ((op (eql 'or)) args)
    (some #'identity args))

etc.  (Of course, whether WFF-EVAL is or is not a better name than
TRANSLATE-EXP is a matter of overall program design and style.)


Vassil Nikolov
Permanent forwarding e-mail: ········@poboxes.com
For more: http://www.poboxes.com/vnikolov
  Abaci lignei --- programmatici ferrei.
From: CMFCaseiro
Subject: Re: Applying AND
Date: 
Message-ID: <m3so7eld4g.fsf@localhost.localdomain>
······@bridgetrix.com writes:

> Is there a good way to apply AND to a list.  I'm translating a compound
> logical expression, and it would seem clean to have a line of the code
> look like:
> 
> 
> ((eql (car wff) 'and)
>    (apply AND (translate-exp (cdr wff))))

it's not (apply AND ...) but (apply #'and ...),

but the prooblem is not that, the problem is that "and" is a macro and
apply and funcall don't work with macros, only with functions.

If you want you can do:
(reduce #'(lambda (a b)
						(and a b))
				(translate-exp (cdr wff))
				:initial-value nil)



-- 
CMFCaseiro
From: CMFCaseiro
Subject: Re: Applying AND
Date: 
Message-ID: <m3g13da0s6.fsf@localhost.localdomain>
CMFCaseiro <···············@rnl.ist.utl.pt> writes:

> ······@bridgetrix.com writes:
> 
> > Is there a good way to apply AND to a list.  I'm translating a compound
> > logical expression, and it would seem clean to have a line of the code
> > look like:
> > 
> > 
> > ((eql (car wff) 'and)
> >    (apply AND (translate-exp (cdr wff))))
> 
> it's not (apply AND ...) but (apply #'and ...),
> 
> but the prooblem is not that, the problem is that "and" is a macro and
> apply and funcall don't work with macros, only with functions.
> 
> If you want you can do:
> (reduce #'(lambda (a b)
> 						(and a b))
> 				(translate-exp (cdr wff))
> 				:initial-value nil)


It could not be ":initial-value nil", because in that case the answer
will always be nil. It must be ":initial-value t", but in this case if
the list don't have any element, the answer is "t", what is no
correct.

Why I say that (every #'identity ...) is not satisfatory ????



-- 
CMFCaseiro
From: Rob Warnock
Subject: Re: Applying AND
Date: 
Message-ID: <7l77nk$352c0@fido.engr.sgi.com>
CMFCaseiro  <···············@rnl.ist.utl.pt> wrote:
+---------------
| It could not be ":initial-value nil", because in that case the answer
| will always be nil. It must be ":initial-value t", but in this case if
| the list don't have any element, the answer is "t", what is no correct.
+---------------

But it *is* correct! After all, that's what "(and)" gives you:

	> (and)
	T
	> (every #'identity '())
	T
	>

Why should the applicative version behave any different than the macro??
You'd just confuse people...


-Rob

-----
Rob Warnock, 8L-855		····@sgi.com
Applied Networking		http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		FAX: 650-933-0511
Mountain View, CA  94043	PP-ASEL-IA