I know the feeling.
What makes matters worse is that I keep getting distracted by something more puzzling than my latest project.
Anyway, just to add to your woes here's a demo which narrows down a problem with your pointer functions.
This version works:
FunctionPtr as dword
FunctionPtr = get ptr to function(2) ` this should refer to the second function, i.e. x^2
global s2#
global s3#
result# = test(FunctionPtr, 2.0, 3.0, 10)
print "result = ", result#
print "s2 = ", s2#
print "s3 = ", s3#
print "exact value = ", 9.0-8.0/3.0
wait key
end
function test(f as dword, a as float, b as float, n as integer)
` estimates the definite integral of the function with pointer f
x# = a
xStep# = (b-a)/n
s# = call function ptr(f, a)
f# = call function ptr(f, b)
s# = (s# + f#) * 0.5
n1 = n-1
for i = 1 to n1
inc x#, xStep#
f# = call function ptr(f, x#)
inc s#, f#
next i
s# = s# * xStep#
s2# = s#
endfunction s#
function xSquared(x as float)
result# = x * x
s3# = result#
endfunction result#
This version may fail to evaluate correctly but more often hangs the editor/compiler:
FunctionPtr as dword
FunctionPtr = get ptr to function(2) ` this should refer to the second function, i.e. x^2
global s2#
global s3#
result# = test(FunctionPtr, 2.0, 3.0, 10)
print "result = ", result#
print "s2 = ", s2#
print "s3 = ", s3#
print "exact value = ", 9.0-8.0/3.0
wait key
end
function test(f as dword, a as float, b as float, n as integer)
` estimates the definite integral of the function with pointer f
x# = a
xStep# = (b-a)/n
s# = (call function ptr(f, a) + call function ptr(f, b)) * 0.5 ` this line is a problem
n1 = n-1
for i = 1 to n1
inc x#, xStep#
f# = call function ptr(f, x#)
inc s#, f#
next i
s# = s# * xStep#
s2# = s#
endfunction s#
function xSquared(x as float)
result# = x * x
s3# = result#
endfunction result#
This version fails to compile:
FunctionPtr as dword
FunctionPtr = get ptr to function(2) ` this should refer to the second function, i.e. x^2
global s2#
global s3#
result# = test(FunctionPtr, 2.0, 3.0, 10)
print "result = ", result#
print "s2 = ", s2#
print "s3 = ", s3#
print "exact value = ", 9.0-8.0/3.0
wait key
end
function test(f as dword, a as float, b as float, n as integer)
` estimates the definite integral of the function with pointer f
x# = a
xStep# = (b-a)/n
s# = (call function ptr(f, a) + call function ptr(f, b)) * 0.5 ` this line is a problem
n1 = n-1
for i = 1 to n1
inc x#, xStep#
inc s#, call function ptr(f, x#) ` and so is this
next i
s# = s# * xStep#
s2# = s#
endfunction s#
function xSquared(x as float)
result# = x * x
s3# = result#
endfunction result#
The version which works assigns the return value to a variable. The versions which fail all try to use the return value directly as if it were a float.
Hope this helps.
The "exact" value given is the result you would get using elementary calculus. It should differ slightly from the numerical estimate given by the function "test".
Apart from this bug (which can be worked around) this is a nice addition to the language. I wish I'd been aware of it before today.