Task

Create a function, compose,   whose two arguments   f   and   g,   are both functions with one argument.



The result of compose is to be a function of one argument, (lets call the argument   x),   which works like applying function    f    to the result of applying function    g    to    x.



Example

 compose(f, g) (x) = f(g(x))



Reference: Function composition

Hint: In some languages, implementing compose correctly requires creating a closure.




      REM Create some functions for testing:
      DEF FNsqr(a) = SQR(a)
      DEF FNabs(a) = ABS(a)
 
      REM Create the function composition:
      SqrAbs = FNcompose(FNsqr(), FNabs())
 
      REM Test calling the composition:
      x = -2 : PRINT ; x, FN(SqrAbs)(x)
      END
 
      DEF FNcompose(RETURN f%, RETURN g%)
      LOCAL f$, p% : DIM p% 7 : p%!0 = f% : p%!4 = g%
      f$ = "(x)=" + CHR$&A4 + "(&" + STR$~p% + ")(" + \
      \             CHR$&A4 + "(&" + STR$~(p%+4) + ")(x))"
      DIM p% LEN(f$) + 4 : $(p%+4) = f$ : !p% = p%+4
      = p%