Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Re: Rather simple function returns curious result. Explanation
Replies: 0

 Daniel Posts: 59 Registered: 7/24/12
Re: Rather simple function returns curious result. Explanation
Posted: Jul 3, 2013 4:49 AM

You probably intended to write (and it works as expected)
> f [run : { ___List } ]
which means that you expect a list of zero or more lists

> f [run : { List___ } ]
in which you expect a list of expressions, the Sequence of which you name List (and that is a bad idea)

> 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
>