I try to use: (^10).map({0})
to generate a list with 10 '0'.
Is there another way to do it?
Asked
Active
Viewed 98 times
8

Sun Wenjie
- 123
- 6
-
2Note in this case you don't need parens `()`, just a well placed space (after the `^10`) and a colon `:`. `^10 .map:{0}`. It may still be advisable to leave the parens around `^10` though. – Brad Gilbert May 17 '18 at 15:47
-
2@BradGilbert Isn't that a change from how it used to be? If so, do you recall roughly when that happened? I'm surprised but tentatively pleased to see it. I've always hoped we could make stuff like `-1 ** 2` DWIM. My hopes are up given the change I think I'm seeing (or, even if it's always been the same, it seems to be that the precedence of a method call with a space is lower than the `^` prefix but the error message of `^10.foo` says a method call without the space has higher precedence). Fwiw, for a moment I thought you meant `^10 .map({0})` wouldn't work. (Now I see what you meant.) – raiph May 17 '18 at 20:21
1 Answers
12
0 xx 10
Generates a list of 10 integers numbered zero.
'0' xx 10
Generates a list of 10 strings consisting of the single character '0'.
See xx
infix op doc.
'0' x 10
Generates a single string consisting of a sequence of 10 '0' characters.
See x
infix op doc.

raiph
- 31,607
- 3
- 62
- 111
-
2Perhaps also good to know: if you want a infinite list of `0`s, simply say that: `0 xx Inf`, or even shorter using the `Whatever`: `0 xx *` – Elizabeth Mattijsen May 18 '18 at 08:43