|
[Date Index]
[Thread Index]
[Author Index]
Re: Using a logical Or in the function definition
- To: mathgroup at smc.vnet.net
- Subject: [mg86694] Re: [mg86687] Using a logical Or in the function definition
- From: Adriano Pascoletti <adriano.pascoletti at dimi.uniud.it>
- Date: Wed, 19 Mar 2008 05:21:04 -0500 (EST)
- References: <200803180951.EAA18708@smc.vnet.net>
Use Alternatives (|):
In[1]:= ab[(r_Integer) | (r_Rational), (s_Integer) | (s_Rational)] :=
r/s;
In[2]:= ab[3, 7]
Out[2]= 3/7
In[3]:= ab[3/2, 21/4]
Out[3]= 2/7
In[4]:= ab[3/2, 7]
Out[4]= 3/14
In[5]:= ab[3.2, 4]
Out[5]= ab[3.2, 4]
Adriano Pascoletti
On 18 mar 2008, at 10:51, ahallam at iastate.edu wrote:
> I would like to use Or in the function definition as in
>
> ab[ Or[r_Integer,r_Rational], Or[s_Integer,s_Rational] ]:=r/s;
>
> In other words, I want the function to take integers or ratios of
> integers as arguments, but not real numbers which are not rational.
>
> But if I give the function integer arguments, it does not evaluate.
>
> If I try
>
> ar[ r_Integer , Or[s_Integer , s_Rational]] := r/s;
>
> and give an integer first argument it works and so on.
>
Prev by Date:
Re: Using a logical Or in the function definition
Next by Date:
Exceptions Style Problem
Previous by thread:
Using a logical Or in the function definition
Next by thread:
Re: Using a logical Or in the function definition
|