In this post I explore the use of PROCedures and FUNCtions in Action!
Procedures and Functions
Action! gives the ability to create both procedures and functions. similar to BASIC subroutines, or C functions, or any number of other languages that support structured subroutine mechanisms. A very simple program may not need either type. The difference between a procedure and function is that functions return a value. Each can accept up to five parameters.
Procedures in Action! are created using the construct:
PROC name([parameter,...]) RETURN
Functions in Action! are created using the construct:
type FUNC name([parameter,...]) RETURN (value)
In writing these I learned that every program must contain a procedure. Though I’m not sure why the simple print’s didn’t require it. The programs presented here are in proper Action! form.
A simple program that uses a procedure. This passes two parameters to a procedure called MyCalc which in turn multiples the two together then divides the result by 2, then finally displays the result (which should be 25):
MODULE PROC MyCalc(INT a,b) INT r= r=(a*b)/2 Print("Result=") PrintF("%I",r) RETURN PROC Main() MyCalc(5,10) RETURN
This is a function implementation of the same calculation as the procedure above, but rather than output the result to the screen, it returns the result for assignment to a third variable, which in turn is output to the screen.
MODULE INT FUNC MyCalc(INT a,b) INT r= r=(a*b)/2 RETURN(r) PROC Main() INT c= c=MyCalc(5,10) Print("Result=") PrintIE(c) RETURN
Next I’ll look at a number guessing game to contrast with the BASIC and Assembly versions I wrote about before.
Nice to finally learn some Action! after all these years. I only ever had, and programmed in, PILOT and Atari BASIC for my 400 and 800XL.
Action! is a great language. I’ve recently become a huge fan of cc65, which is very nice for writing on modern computer with nice editor and cross compiling for the Atari.