transfun
transfun copied to clipboard
investigate wrong external bind
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}')
;
...because of .decl( 'mean_value', get_mean )
...must have been the heat...
...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
letandconst, novar(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.