Author Topic: Simulating a function call with the Call Statement  (Read 1392 times)


  • Hero Member
  • *****
  • Posts: 3389
  • A Bézier Extrusion
Simulating a function call with the Call Statement
« on: March 18, 2014, 03:29:29 AM »
Lar reminded me about the Call statement.  Turns out I had not used it.

'Program TestCall.d3m

'A test program that simulates creating a typical function with its own memory space and variables,
'  passing data to it, having it do something then receiving the result  It is using the call
'  statement

message "program 1 (TestCall) about to call program 2, boxvol_w_h"

'some working data for this program
a = 10
b = 5

'prepare data for pseudo function call
precision 15
a$ = a
b$ = b
s$ = a$+ "," + b$

'the so-called arguments for the function are passed using the cmdline statement
'the call is acting like a function call

' for example, boxvol(width, height) could be simulated with call boxvol_w_h.d3m

cmdline s$
call "boxvol_w_h.d3m"
result$ = sys$(0)
message result$
'one could receive back more than one value since it is a string, but it will need to be parsed

'but for now let's check the values for a and b for this program, should still be the same
message a, b



'Program boxvol_w_h.d3m

message "program 2, boxvol ", sys$(0)

fmt$ ="%f,%f"
parse sys$(0), fmt$, a, b

'let's change a and b to make sure these are indeed separate variables from program 1
a = 2*a
b = 2*b

result = a*b

'prepare data for result
precision 15
result$ = result
sys$(0) = result$

« Last Edit: June 10, 2014, 08:23:20 AM by prl »