h3rald / min

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

Add `range` function to Num library (+unit tests, +documentation) #109

Closed drkameleon closed 3 years ago

drkameleon commented 3 years ago

Exactly as we said :) #108

The implementation covers an optional third element in the argument/quotation which may function as a step. Also, it supports range regardless of the direction: if a<b it generates an upwards range, while if a>=b it generates a downwards range.

Here's the relevant part from the unit tests:

  ((1 5) range (1 2 3 4 5) ==) assert
  ((5 1) range (5 4 3 2 1) ==) assert
  ((4 7) range (4 5 6 7) ==) assert
  ((7 4) range (7 6 5 4) ==) assert
  ((1 6 2) range (1 3 5) ==) assert
  ((1 6 3) range (1 4) ==) assert
  ((0 6 2) range (0 2 4 6) ==) assert
  ((6 1 2) range (6 4 2) ==) assert
  ((6 1 3) range (6 3) ==) assert
  ((6 0 2) range (6 4 2 0) ==) assert