# On what versions and OS's does ConstantArray[0, {}] work?

I've been using the combination

ConstantArray[0, {}]

(* 0 *)


in my code for some time, as a way for returning zero (i.e. a zero-dimensional array of zeroes) inside scalable code that can be made to produce empty arrays of arbitrary dimensions but also zeros. On my system (currently v11 over linux) it's always worked well since I introduced it.

However, when I tried to run the same code on other systems, you sometimes get the following:

ConstantArray[0, {}]
ConstantArray::ilsmn : Single or list of non-negative machine-sized integers
expected at position 2 of ConstantArray[0, {}]

(*Out[]:= ConstantArray[0, {}]*)


The above screenshot was taken over version 10 on OSX; a separate user also observed this in v8 over Windows 7.

I find this confusing, and I'm pretty sure it's a bug. In particular, the documentation for ConstantArray claims that its history is

Introduced in 2007 (6.0) | Updated in 2008 (7.0)

which means that there should be no change between v8 and v11. I will file a bug report shortly, but mostly I would like to build a workaround (since I want my code to be usable on systems like e.g. v10/OSX). At present, thus, my main question is: on which systems does this behaviour show up, and on which ones does it return a plain 0 without complaints? I suspect this depends both on the specific version and the operating system, but it'd be nice to know for sure.

• Seems to be OK in 11.01, Mac os – bill s Dec 8 '16 at 15:33
• Works for me on 11.0.1, Windows 10 – lowriniak Dec 8 '16 at 15:37
• I tried it on 10.4.1 running on OS X. No problem. – m_goldberg Dec 8 '16 at 15:43
• This fails in version 7.0.1 but works in 10.1.0 under Windows 7 x64. – Mr.Wizard Dec 8 '16 at 15:47
• I don't think you can call it a bug since there is nothing in the docs that indicates the zero should be expected behavior. The docs do say ConstantArray[c,dims] has Dimensions[dims] which fails here as Dimensions[{}] != Dimensions[0] – george2079 Dec 8 '16 at 15:57

This was a change introduced in version 10.1.0 (on all platforms).

The new behavior is more consistent with Array, e.g.

Array[f, {}]

(* f[] *)

Array[Function[0], {}]

(* 0 *)
`
• Thanks for this. So do all <10.1.0 versions produce the same error and the unevaluated return? – Emilio Pisanty Dec 8 '16 at 16:52
• (Either way, it still strikes me as a potential documentation bug - if this behaviour is settled, shouldn't it be reported in the documentation, and marked as the last change in the function?) – Emilio Pisanty Dec 8 '16 at 16:53
• Yes (starting with 6.0 of course). – ilian Dec 8 '16 at 16:53
• In some cases it would be safer to interpret the 'last updated in' markup as referring to the documentation page content, not necessarily the function implementation. – ilian Dec 8 '16 at 16:56
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.34407418966293335, "perplexity": 2261.481651343585}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-21/segments/1620243988961.17/warc/CC-MAIN-20210509062621-20210509092621-00440.warc.gz"}