FutureBasic syntax supports
procedural, modular styles of programming using
function calls and
local variables.
Program flow & structural blocks User-defined functions (a.k.a. LOCAL FNs in FutureBasic) are much like C or
Pascal functions. • They can also be totally insulated from the main program (LOCAL MODE statement); • they allow
recursion; • they can be called dynamically at runtime (DEF FN USING statement); • called automatically by FutureBasic built-in event vectors (ON EVENT FN statement); • used as cooperative threaded functions (THREADBEGIN statement). Specific structures (ENTERPROC/EXITPROC) are used for callback procedures when calling the
Macintosh Toolbox. The language provides the programmer with a complete set of vectors for event-driven applications, such as ON MENU, ON MOUSE, ON DIALOG, ON APPLEEVENT, ON EDIT, ON TIMER, etc. Other structured keywords include conditional blocks such as: • LONG IF .... XELSE ... END IF • DO .... UNTIL • WHILE ... WEND • SELECT ... CASE... CASE ELSE ... END SELECT • FOR ... NEXT Legacy BASIC language commands such as:
GOTO and
GOSUB/RETURN with line numbers and labels - while discouraged - are supported for educational purposes. An example of a simple program to input a number and display "Hello World" is given below //Example FutureBasic program dim i,num,a$ //These are our variables window 1 //open standard window input "Number of loops "; a$ //BASIC input from user num=val(a$) //convert text to number long if num>0 //Structured IF for i = 1 to num //BASIC loop print "hello world" //output text next i //end of loop xelse //Otherwise print "Not today" //no number entered end if do //Wait until Apple-Q HandleEvents until ( gFBQuit ) //so that we can see results
Data types FutureBasic supports complex data types include single and double precision
floating points, double length integers, arrays, strings and records (similar to struct in C). Of note is the DYNAMIC array structures (size of
memory footprint grows only when used) including DYNAMIC string arrays called INDEX$ and "container" variables which can perform string-like operations on data streams up to 2Gb in size.
C and Pascal borrowed coding styles Commenting in the code is substantial allowing REMark statements, and C style statements. Sections of code can be bookmarked for easy reference. Other alternate syntax borrowed from C allows the use of operators such as ++ -- == != += -= || &&. Characters in Pascal strings are accessible much like items of an array: (length byte); (first character in string ). While the FutureBasic language still supports old style variable typing with suffix identifiers, it provides a modern alternative with the as clause: ; , ; etc.
Bridges to other languages •
AppleScript scripts can be assembled with FutureBasic statements then executed on the fly by a running application. Example: : route _toAppleScript print "return the path to me as string" route _toScreen long if usr ApplescriptRun( message$ ) = _noErr print message$ end if • FutureBasic allows the triggering of UNIX commands. Example: : // print a calendar for 2009 open "UNIX", 1, "cal 2009" dim a$ do line input #1, a$ print a$ until eof(1) close 1 • FB allows inline C code. Example: : BeginCFunction // Simple C function to add two integers long simple_add( long a, long b ) { long sum; sum = a + b; return (sum); } endC // Define C function so FB can see it toolbox fn simple_add ( long a, long b ) = long // Create little program to add 2 + 2 with the C function window 1 print fn simple_add ( 2, 2 ) do HandleEvents until ( gFBQuit ) ==Limitations==