h3rald / min

A small but practical concatenative programming language and shell
https://min-lang.org
MIT License
310 stars 23 forks source link

times operator should handle 0 as well #176

Closed h3rald closed 2 years ago

h3rald commented 2 years ago

While trying to define a function that creates a sequence of numbers provided a length of the list, I noticed that times does not accept 0 as a number of times to repeat a quote. I'd argue that repeating something 0 times is perfectly valid and useful:

(empty swap dup (pred dup (swons) dip) swap times pop) ^iota

$ 2 iota
 (
   0
   1
  )
$ 10 iota
 (
   0
   1
   2
   3
   4
   5
   6
   7
   8
   9
  )

Here is the problem:

$ 0 iota
(!) <repl>(1,49) [times]: A non-zero natural number is required
    <repl>(1,49) in symbol: times
    <repl>(1,6) in symbol: iota

Was expecting the empty list as the result

0 iota
()

Originally posted by @DanielAjoy in https://github.com/h3rald/min/discussions/175

h3rald commented 2 years ago

Fixed in v0.37.0