MathGroup Archive 2013

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

Search the Archive

Re: Rather simple function returns curious result.


Clear[f];


f[run : {___List}] := Module[
   {n},
   n = run // Length;
   If[n != 2, n, {}]];


f /@ Table[{}, {n, 0, 4}, {n}]


{0, 1, {}, 3, 4}



Bob Hanlon




On Tue, Jul 2, 2013 at 12:48 AM, James Stein <mathgroup at stein.org> wrote:

> For reasons that escape me, the simple function below fails to return
> an empty List when n==2; Is this a bug? If not, what is the
> explanation? If the return value for n==2 is changed to an integer or
> a string, the function behaves as expected.(Of course, this bizarre
> function is the result of simplifying a more reasonable one.)
>
> Clear[ f ];
> f [run : { List___ } ] := Module [ { n },
>    n = run // Length;
>    If [ n != 2, Return [ n ] ];
>    Module [ { } ,
>     { } (* Return Empty List if n==2 *)
>     ]
>    ] ;
> f [ { } ]
> f [ { { } } ]
> f [ { { }, { } } ]
> f [ { { }, { }, { } } ]
> f [ { { }, { }, { }, { } } ]
>
> When I run the above, I get these four outputs:
> 0
> 1
> Sequence[{}, {}][]
> 3
> 4
>
>



  • Prev by Date: Re: where can I find CartesianMap code
  • Next by Date: Re: Changing a list with the information of other
  • Previous by thread: Re: Rather simple function returns curious result. Explanation
  • Next by thread: Re: Rather simple function returns curious result.