RosettaCodeData/Task/First-class-functions-Use-numbers-analogously/BBC-BASIC/first-class-functions-use-numbers-analogously-1.basic
2023-07-01 13:44:08 -04:00

28 lines
822 B
Text

REM Create some numeric variables:
x = 2 : xi = 1/2
y = 4 : yi = 0.25
z = x + y : zi = 1 / (x + y)
REM Create the collections (here structures are used):
DIM c{x, y, z}
DIM ci{x, y, z}
c.x = x : c.y = y : c.z = z
ci.x = xi : ci.y = yi : ci.z = zi
REM Create some multiplier functions:
multx = FNmultiplier(c.x, ci.x)
multy = FNmultiplier(c.y, ci.y)
multz = FNmultiplier(c.z, ci.z)
REM Test applying the compositions:
x = 1.234567 : PRINT x " ", FN(multx)(x)
x = 2.345678 : PRINT x " ", FN(multy)(x)
x = 3.456789 : PRINT x " ", FN(multz)(x)
END
DEF FNmultiplier(n1,n2)
LOCAL f$, p%
f$ = "(m)=" + STR$n1 + "*" + STR$n2 + "*m"
DIM p% LEN(f$) + 4
$(p%+4) = f$ : !p% = p%+4
= p%