MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: A variable defaulting to a previous variable?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121958] Re: A variable defaulting to a previous variable?
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Fri, 7 Oct 2011 04:48:07 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201110060825.EAA22765@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

Clear[f]
f[x_] := f[x, x]
f[x_, y_] := x + y
f[2, 3]
f[3]

5

6

Bobby

On Thu, 06 Oct 2011 03:25:54 -0500, Brentt <brenttnewman at gmail.com> wrote:

> How would one go about making a variable default to a previous variable?
>
> I would like results like this:
>
> In[1]= f[x_, y_: x] := x+y;
>> In[2]= f[2,3]
>> Out[1]= 5
>> In[3]= f[3]
>> Out[1]= 6
>>
>
>
>
> But, of course, Mathematica won't let me use a previous argument for the
> default of the next argument. Is there a way to do this?


-- 
DrMajorBob at yahoo.com



  • Prev by Date: Re: average of the consecutive coin tosses
  • Next by Date: Re: importing data into a CDF
  • Previous by thread: A variable defaulting to a previous variable?
  • Next by thread: Re: A variable defaulting to a previous variable?