transfun icon indicating copy to clipboard operation
transfun copied to clipboard

investigate wrong external bind

Open glathoud opened this issue 7 years ago • 2 comments

Below, why is get_mean_stddev bound to an external function using transfun's current implementation?

var get_mean = tfun.redinit( '0', '+' ).next( '/n' )
,  get_stddev = tfun
    .decl( 'mean_value', get_mean )
    .map( 'v-mean_value' )
    .map( 'v*v' )
    .sum()
    .next( 'Math.sqrt(current/(n-1))' )  // unbiased std dev estimation

// compute both mean and stddev at once
, get_mean_stddev = get_stddev
    .next( '{stddev:current, mean:mean_value}')
;

glathoud avatar Jul 26 '18 17:07 glathoud

...because of .decl( 'mean_value', get_mean ) ...must have been the heat...

glathoud avatar Jul 26 '18 17:07 glathoud

...but actually can be solved in a constructive manner: since #7 we already have inlining of some external functions (see fext, flatorize). We could also inline the code generated by transfun, i.e. appfuns, as long as:

  • they are not already used as appfuns to generate smart code, only as external functions.
  • the code produced only uses let and const, no var (slight change).

When all "checks" are passed, we can simply add ._tf_get_argname_arr and ._tf_get_bodycode as methods to the generated appfun, then examples like the one above will be fully inlined.

glathoud avatar Jul 28 '18 12:07 glathoud