1

I am trying to generate the least common multiple for all numbers from 1 to n as described in OEIS-A003418. In the DrRacket REPL I'm using the following code:

(lcm (apply values (build-list 256 add1)))

Which gives me a "result arity mismatch" error (expected 1, received 256). When I omit lcm I get a sequence from 1 to 256 output to the console. I'm uncertain as to the cause of the arity mismatch, since lcm is supposed to be able to take arbitrarily many arguments (according to the docs), and apply seems to be doing what I would expect when it is the outermost function and not an input to lcm. What am I missing? Also, if there is an easier way to write the LCM from 1 to n please feel free to share.

hatch22
  • 797
  • 6
  • 18

1 Answers1

1

There is no difference between fixed arity and non-fixed arity when you use apply:

(apply lcm (build-list 256 add1))
soegaard
  • 30,661
  • 4
  • 57
  • 106