hyperformula icon indicating copy to clipboard operation
hyperformula copied to clipboard

Call `runFunction` internally so it's easier to create custom functions

Open wojciechczerniak opened this issue 4 years ago • 1 comments

Description

Currently each function calls runFunction with a callback. It does a lot of useful things and reduces the boilerplate (ie. argument validation) so it's natural that most implementations will want to use it. Also having meta properties for each functions kind of feels that validations is always done by the engine.

https://github.com/handsontable/hyperformula/blob/43071aa2a822ddcea04a7b1016fa3e8dda78e751/src/interpreter/plugin/ModuloPlugin.ts#L22-L30

Would become a simple

public mod(ast: ProcedureAst, formulaAddress: SimpleCellAddress, args: ModArgs): InternalScalarValue { 
  const { dividend, divisor } = args
 
  if (divisor === 0) { 
     return new CellError(ErrorType.DIV_BY_ZERO) 
  }

  return dividend % divisor 
} 

Interpreter already have access to AST, function meta and other properties, no need to create all this boilerplate code.

Other thoughts

  • We may have a flag to make the internal validation optional if someone want so implement everything on their own.
  • We should keep ast and formulaAddress, may be useful

wojciechczerniak avatar Jul 13 '21 13:07 wojciechczerniak

Note related conversation (https://github.com/handsontable/hyperformula/pull/1227) about the introduction and usage of runFunctionWithReferenceArgument

thilgen avatar Apr 18 '23 20:04 thilgen