Skip to main content
deleted 2 characters in body
Source Link

The most elegant way I see is to use:

f[list_] := Module[{},
   <do other stuff...>
]

f[list_]/;ArrayDepth[list]==1 := f[{list}]

When ArrayDepth[list] == 1, it will put it on a list.

The DownValues evaluation order goes from the more restrictive case for the more generic one.

Update:

Using @0x4A4DJ.M.'s comment, we could write it as:

 f[list_?VectorQ] := f[{list}]

The most elegant way I see is to use:

f[list_] := Module[{},
   <do other stuff...>
]

f[list_]/;ArrayDepth[list]==1 := f[{list}]

When ArrayDepth[list] == 1, it will put it on a list.

The DownValues evaluation order goes from the more restrictive case for the more generic one.

Update:

Using @0x4A4D comment, we could write it as:

 f[list_?VectorQ] := f[{list}]

The most elegant way I see is to use:

f[list_] := Module[{},
   <do other stuff...>
]

f[list_]/;ArrayDepth[list]==1 := f[{list}]

When ArrayDepth[list] == 1, it will put it on a list.

The DownValues evaluation order goes from the more restrictive case for the more generic one.

Update:

Using J.M.'s comment, we could write it as:

 f[list_?VectorQ] := f[{list}]
added 102 characters in body
Source Link
Murta
  • 26.4k
  • 6
  • 77
  • 168

The most elegant way I see is to use:

f[list_] := Module[{},
   <do other stuff...>
]

f[list_]/;ArrayDepth[list]==1 := f[{list}]

When ArrayDepth[list] == 1, it will put it on a list.

The DownValues evaluation order goes from the more restrictive case for the more generic one.

Update:

Using @0x4A4D comment, we could write it as:

 f[list_?VectorQ] := f[{list}]

The most elegant way I see is to use:

f[list_] := Module[{},
   <do other stuff...>
]

f[list_]/;ArrayDepth[list]==1 := f[{list}]

When ArrayDepth[list] == 1, it will put it on a list.

The DownValues evaluation order goes from the more restrictive case for the more generic one.

The most elegant way I see is to use:

f[list_] := Module[{},
   <do other stuff...>
]

f[list_]/;ArrayDepth[list]==1 := f[{list}]

When ArrayDepth[list] == 1, it will put it on a list.

The DownValues evaluation order goes from the more restrictive case for the more generic one.

Update:

Using @0x4A4D comment, we could write it as:

 f[list_?VectorQ] := f[{list}]
Source Link
Murta
  • 26.4k
  • 6
  • 77
  • 168

The most elegant way I see is to use:

f[list_] := Module[{},
   <do other stuff...>
]

f[list_]/;ArrayDepth[list]==1 := f[{list}]

When ArrayDepth[list] == 1, it will put it on a list.

The DownValues evaluation order goes from the more restrictive case for the more generic one.