Closed garywill closed 1 year ago
How would you even supply "infinite" number of input parameters in the runtime? What are you trying to achieve?
In case you are trying to use arbitrary (not infinity) number of inputs, then use a language that supports data structures (e.g. Octave/Python/Julia), instead of insect.
Then you can define an array R = [r1,r2,r3,.....]. and write a function which will accept the array R as an argument, and return the reciprocal of the sum of reciprocals of all the elements in R.
Right now, there is only a limited set of variadic functions (with arbitrary number of arguments) in Insect: maximum
, minimum
, mean
. Those are builtin functions, but there is currently no way to define variadic functions as a user.
We are currently working on a complete rewrite of Insect, and variadic functions (OR support for lists/vectors) are definitely on the roadmap — but not yet implemented.
Follow up ticket for Numbat: https://github.com/sharkdp/numbat/issues/66
@garywill This sort of thing is now fully supported in Numbat
Check the example out online here: https://numbat.dev/?q=fn+invert%28x%29+%3D+1%2Fx%E2%8F%8Efn+parallel_resistors%28resistances%29+%3D+1+%2F+sum%28map%28invert%2C+resistances%29%29%E2%8F%8Eparallel_resistors%28%5B22+k%E2%84%A6%2C+47+k%E2%84%A6%5D%29%E2%8F%8E
This calculator is amazing! I was looking for some tool that allow us to easily calculate circult impedance. Frustrated until I meet Insect !
This is how we can calculate parallel two resistors:
three resistors:
I'm wondering can we define a function with infinite number of arguments?