I want to find the result of something like
A and B and C and D
I have a list of the boolean expressions (in this example,
A,B,C,D,etc...). This list can be arbitrarily long.
I thought I can use the command 'map' to apply 'and' to the list,
but can't figure how to do it.
Let m be the list.
> m:=[true,true,true,false];
> map(`and`,m);
Error, wrong number (or type) of parameters in function and
it works in this example:
> map(`and`,true,true);
but not in this example (more than 2 arguments to and):
> map(`and`,true,true,true);
Error, wrong number (or type) of parameters in function and
Any way, as you see I am having trouble with this.
Is there a way to map 'and' to a list of boolean, such that if
only ONE boolean is false, then the return is false?
fyi, in Mathematica, I can do it like this:
In[29]:=m = {True, True, True}
Out[29]={True, True, True}
In[30]:=And @@ m
Out[30]=True
In[31]:= m = {True, True, False}
Out[31]= {True, True, False}
In[32]:= And @@ m
Out[32]= False
One can use something like that,
And:=proc(L::list(boolean))
if member(false,L) then false
elif member(FAIL,L) then FAIL
else true fi end:
Alec
andmap(eval ,m);
Here's one way to do it:
> X:=[true,true,false,true]:
> not has(X,false);
false
And if the values in the list are boolean expression other than true and
false:
> Y:=[1<2,1=1,2<1]:
> not has(map(evalb,Y),false);
false
Edwin Clark
Or, in case m is a list of boolean expressions other than true or false:
>andmap(evalb,[1 =1, 1<2,2<1,x=x]);