Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

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

Advanced Search

Back to Topic List Back to Topic List  
Daniel

Posts: 56
Registered: 7/24/12
Re: Rather simple function returns curious result. Explanation
Posted: Jul 3, 2013 4:49 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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

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





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.