elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.7k stars 300 forks source link

RFC: move `rand` and `randint` to the `math:` namespace or a `random:` namespace #962

Open krader1961 opened 4 years ago

krader1961 commented 4 years ago

Should the rand and randint commands be moved to the math: namespace? Or, alternatively, should a random: namespace be implemented that includes equivalents of those commands as well as more sophisticated commands? For example, something like random:choice to pick a random element from a sequence such as a list or map? This is a case where I think the Python random module is a better model for Elvish than the Go math/rand package. For example, a list = (random:shuffle $list) could be useful.

This is something that needs a lot of discussion so I'm not going to create a pull-request despite my inclination to create a random: namespace.

krader1961 commented 3 years ago

Revisiting this issue I'm still inclined to introduce a random module and move the two builtins to that module. Specifically: builtin:rand => random:float and builtin:randint => random:int. Then introduce other useful commands such as random:shuffle $list and random:pick $list.

krader1961 commented 2 years ago

Note that commit 46008d1 introduced a -randseed command with this commit comment:

This command is prefixed with - since I'd like to eventually move rand and randint into their own module, so this command will be moved too.

I'm still inclined to introduce a random module and move these functions to that module.