Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #15101 > unrolled thread

Re: Rather simple function returns curious result. Explanation

Started byDaniel <dosadchy@its.jnj.com>
First post2013-07-03 08:49 +0000
Last post2013-07-03 08:49 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Rather simple function returns curious result. Explanation Daniel <dosadchy@its.jnj.com> - 2013-07-03 08:49 +0000

#15101 — Re: Rather simple function returns curious result. Explanation

FromDaniel <dosadchy@its.jnj.com>
Date2013-07-03 08:49 +0000
SubjectRe: Rather simple function returns curious result. Explanation
Message-ID<kr0oj7$3e1$1@smc.vnet.net>
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
>

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web