MathGroup Archive 2002

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

Search the Archive

RE: Optional

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33694] RE: [mg33689] Optional
  • From: "David Park" <djmp at earthlink.net>
  • Date: Mon, 8 Apr 2002 03:04:21 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Ben,

In Version 4.1 this seems to work fine:

f[index_:1] := index

{f[], f[2]}
{1, 2}

That is the usual way of writing optional arguments.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

> From: Ben Langton [mailto:ben at quickmath.com]
To: mathgroup at smc.vnet.net
>
> Hi all,
>
> I am having a problem with the Optional function which I have
> reduced to the
> following snippet of code :
>
> f // Clear;
> f[Optional[index : {_Integer ...}, {1}]] := index;
> f[]
>
> My understanding of the Optional command is that the function f should
> accept a list of zero or more integers as its argument or, if that is
> missing, use the default value of {1}.
>
> Under version 3, f[] (f with no arguments) returns {1}, as I would expect,
> yet under version 4.1 it returns the function evaluated.
>
> Can anyone shed any light on why this code acts differently under the two
> different versions? What can I do to make it work as expected
> under version
> 4.1?
>
> Many thanks,
>
> Ben Langton
>



  • Prev by Date: list of digits to string
  • Next by Date: Re: huge number, ciphers after decimal point?
  • Previous by thread: Re: Optional
  • Next by thread: Re: Optional