hotscript icon indicating copy to clipboard operation
hotscript copied to clipboard

Numbers

Open ecyrbe opened this issue 2 years ago • 6 comments

The tuple trick to do number operations is really limited.

I have a complete implementation here with no limitations but ts memory and compute power : https://github.com/ecyrbe/ts-calc

But it would be really out of scope, maybe ?

Sharing anyway just in case.

ecyrbe avatar Feb 12 '23 22:02 ecyrbe

Could these libraries cooperate? Single responsibilities and all :)

Nathan-Franck avatar Feb 13 '23 05:02 Nathan-Franck

Your library looks amazing. I think what's in scope or out of scope for HOTScript is very much up for debate, but I'd love to improve the Number module with something that's less limited.

Manipulating numbers to keep track of indices, or add lengths togethers, or pick the largest / smallest between two number are super common use cases when writing loops, so if you want to contribute to the number module to add:

  • N.Add
  • N.Multiply
  • N.Substract
  • N.GreaterThan
  • N.GreaterThanOrEqual
  • N.LessThan
  • N.LessThanOrEqual

I think that would make an awesome addition 😀

gvergnaud avatar Feb 13 '23 08:02 gvergnaud

Ideally all of these should be "semi-pipeable" (or curried?), e.g. they could be used like this:

// all arguments can come from piped inputs
type T = Call<Tuples.Reduce<Numbers.Add, 0>, [1, 2, 3]> 
//      ^? 6

// one explicit arg, one from piped inputs
type T = Call<Tuples.Map<Numbers.Add<2>>, [1, 2, 3]> 
//      ^? [3, 4, 5]

// two explicit args
type T = Eval<Numbers.Add<2, 3>> 
//      ^? 5

Add already works like this so I'm pretty confident this is doable: https://github.com/gvergnaud/PipeScript/blob/4e0e8de1b17adfa5fce751ee637b444f06e19443/test/HOTScript.test.ts#L363-L384

gvergnaud avatar Feb 13 '23 08:02 gvergnaud

Would you mind if we create a sub directory for internals (all Impl stuff) ? because importing Number operations in HOTScript.ts will likely make it really hard to check :

src/
 | - internal/
          |- number/
          |- object/
           ...
 |- HOTScript.ts

ecyrbe avatar Feb 13 '23 09:02 ecyrbe

Yeah I definitely think we should do that. Will update the structure of the main branch

gvergnaud avatar Feb 13 '23 09:02 gvergnaud

@ecyrbe done, with this structure it should be little easier to have several contributors!

gvergnaud avatar Feb 13 '23 10:02 gvergnaud