MathGroup Archive 2002

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

Search the Archive

Re: Optional

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33700] Re: Optional
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 9 Apr 2002 01:02:05 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <a8m3i8$obr$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,


why not use

f[]={1}
f[index : {_Integer ...}] := index

Ben Langton wrote:
> 
> 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.

Sequence[] can't match the first pattern {_Integer...} and so the
optional argument is never used.

Regards
  Jens


  • Prev by Date: Re: Default Output Format
  • Next by Date: Re: Functions in Mathematica
  • Previous by thread: Re: Optional
  • Next by thread: Re: Optional