h3rald / min

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

Library additions @num #108

Closed drkameleon closed 3 years ago

drkameleon commented 3 years ago

A few additions to the Num library (+ unit tests, + documentation):

Good morning! :)

h3rald commented 3 years ago

Good morning! 🌞

Yep, that can go straight in! Thaaaaaaanks! 🙏😊

drkameleon commented 3 years ago

I've had a question... since I was going through the Min library and wasn't sure if you'd want something like that, how and where it would go.

What about a range function?

((1 10) range (1 2 3 4 5 6 7 8 9 10) ==) assert

Do you think something like that would be nice? And, if so:

a) where would you put it? (which module I mean) b) do you think it would have to take a "step" argument by default? E.g. ((1 10 2) range (1 3 5 7 9) ==) assert c) do you think its limits should be inclusive (<10 vs <=10)?

Quite a few questions that's why I didn't dare to implement it - yet. :)

h3rald commented 3 years ago

Oh yes please! It's so annoying when that's missing in languages lol...

As for the questions:

a) I would put it in num, I think. Also, give me a good reason why not to put the binary operators you added in num as well 😜 I was thinking about it and I am not sure if it makes sense to put them in their own module, unless something else could be added to it... what do you think? Not that it makes a huge difference anyway!

b) Well, you have a quotation parameter there! That's pretty much the only chance you have to use optional parameters in min 😉. Seeing that it's a fairly simple operator, you could add a check that if the quotation has a third parameter you can use it as a step, otherwise it's 1 by default 😊

c) yes... they are inclusive in Nim and Ruby as well I think.

drkameleon commented 3 years ago

a) I would put it in num, I think. Also, give me a good reason why not to put the binary operators you added in num as well 😜 I was thinking about it and I am not sure if it makes sense to put them in their own module, unless something else could be added to it... what do you think? Not that it makes a huge difference anyway!

Makes perfect sense. That's what I was thinking.

Regarding the new bitwise operators, to be honest I decided to put them in a different module a) in order to separate a bit the logic, b) in case you don't think it should be included in the same release as the Num module (chances are most people will need +, but very few would need to bit-and numbers). In any case, feel free to do whatever you think is more convenient.

b) Well, you have a quotation parameter there! That's pretty much the only chance you have to use optional parameters in min 😉. Seeing that it's a fairly simple operator, you could add a check that if the quotation has a third parameter you can use it as a step, otherwise it's 1 by default 😊

Perfect point. (I'm still getting the hang of Min :))

c) yes... they are inclusive in Nim and Ruby as well I think.

Despite all the Dijkstra hype, that's what I've been thinking as well. That aside, non-inclusive ranges confuse me... too much.