Statements and Functions
Total Page:16
File Type:pdf, Size:1020Kb
Statements and Functions The following statments and functions are found in ALL versions of the True BASIC Programming Language: ORDINARY STATEMENTS AND STRUCTURES: PROGRAM END LET DO Loop Structure EXIT DO LOOP FOR Loop Structure EXIT FOR NEXT SELECT CASE Structure CASE IF IF Structure ELSEIF ELSE END IF END SELECT CASE ELSE OTHER STATEMENTS: ASK FREE MEMORY DIM PAUSE RANDOMIZE REM STOP FOR LINE-NUMBERED PROGRAMS: GOSUB ON GOSUB GOTO ON GOTO RETURN TO SET VARIOUS OPTIONS: OPTION ANGLE OPTION NOLET OPTION ARITHMETIC OPTION TYPO OPTION BASE OPTION USING OPTION COLLATE True BASIC Functions and Statements — 1 INPUT AND OUTPUT STATEMENTS: DATA INPUT LINE INPUT MAT INPUT MAT LINE INPUT MAT PRINT MAT READ PRINT READ RESTORE ASK MARGIN SET MARGIN ASK ZONEWIDTH SET ZONEWIDTH FILE STATEMENTS: CLOSE #n ERASE #n INPUT #n: LINE INPUT #n: OPEN #n: RESET #n: PRINT #n: FUNCTIONS AND SUBROUTINES: CALL DECLARE DEF (FUNCTION) DEF DEF Structure EXIT DEF END DEF EXTERNAL LIBRARY LOCAL SUB Structure EXIT SUB END SUB FUNCTION FUNCTION Structure EXIT FUNCTION END FUNCTION DECLARE NUMERIC DECLARE STRING DECLARE SUB CHAIN GRAPHICS AND SOUND STATEMENTS: BOX AREA BOX CIRCLE BOX CLEAR BOX DISK BOX ELLIPSE BOX KEEP BOX LINES True BASIC Functions and Statements — 2 BOX SHOW CLEAR DRAW SOUND FLOOD PICTURE Structure EXIT PICTURE END PICTURE PLAY PLOT PLOT AREA PLOT LINES PLOT POINTS PLOT TEXT SET WINDOW SET TEXT JUSTIFY ASK BACK ASK COLOR ASK COLOR MIX ASK CURSOR ASK DIRECTORY ASK MAX COLOR ASK MAX CURSOR ASK MODE ASK NAME ASK PIXELS ASK SCREEN ASK TEXT JUSTIFY ASK WINDOW BOX DISK GET KEY GET MOUSE GET POINT MAT PLOT MAT PLOT AREA MAT PLOT LINES MAT PLOT POINTS OPEN SCREEN SET BACK SET COLOR SET COLOR MIX SET CURSOR SET DIRECTORY SET MODE SET NAME WINDOW MAT Statements: MAT PRINT MAT Assignment MAT INPUT MAT LINE INPUT MAT REDIM MAT READ MAT WRITE MAT PLOT AREA MAT PLOT LINES MAT PLOT POINTS True BASIC Functions and Statements — 3 FILE Statements: ASK #n: ACCESS ASK #n: DATUM ASK #n: ERASABLE ASK #n: FILESIZE ASK #n: FILETYPE ASK #n: MARGIN ASK #n: NAME ASK #n: ORGANIZATION ASK #n: POINTER ASK #n: RECORD ASK #n: RECSIZE ASK #n: RECTYPE ASK #n: SETTER ASK #n: ZONEWIDTH MAT INPUT #n: MAT LINE INPUT #n: MAT PRINT #n: READ #n: SET #n: MARGIN SET #n: POINTER SET #n: RECORD SET #n: RECSIZE SET #n: ZONEWIDTH UNSAVE WRITE #n: MODULE Structures: MODULE Structure PRIVATE PUBLIC SHARE DECLARE PUBLIC END MODULE Exception Handling: CAUSE ERROR CAUSE EXCEPTION CONTINUE HANDLER END HANDLER EXIT HANDLER RETRY WHEN Structure USE END WHEN DEBUGGING STATEMENTS: BREAK DEBUG TRACE BUILT-IN SUBROUTINES: Clipboard ComLib ComOpen Divide True BASIC Functions and Statements — 4 Object PackB Read_Image System Sys_Event TBD UnpackB (a function, not a subroutine) Write_Image BUILT-IN FUNCTIONS: MATHEMATICAL FUNCTIONS Function Result ABS(x) Absolute value ACOS(x) Arccosine ANGLE(x,y) Angle between x-axis and (x,y) ASIN(x) Arcsine ATN(x) Arctangent CEIL(x) Ceiling (-INT(-x)) COS(x) Cosine COSH(x) Hyperbolic cosine COT(x) Cotangent CSC(x) Cosecant DEG(x) Translates radians to degrees EPS Smallest nonzero positive number EXP(x) Exponential function FP(x) Fractional part of x INT(x) Integer part IP(x) Greatest integer <= x LOG(x) Natural logarithm LOG10(x) Common logarithm (base 10) LOG2(x) Logarithm to the base 2 MAX(x,y) Larger of two numbers MAXNUM Largest positive number MIN(x,y) Smaller of two numbers MOD(x,y) Remainder when x is divided by y PI Value of pi RAD(x) Translates degrees to radians REMAINDER(x,y) Remainder of x divided by y RND Random number between 0 and 1 ROUND(x,n) Rounds x to n decimal places SEC(x) Secant SGN(x) Sign of x SIN(x) Sine SINH(x) Hyperbolic sine SQR(x) Square root TAN(x) Tangent TANH(x) Hyperbolic tangent TRUNCATE(x,n) Truncates x to n decimal places DATE AND TIME FUNCTIONS Function Result DATE Year and day of year as a number DATE$ Year, month, and day of month as a string TIME Seconds since midnight TIME$ 24-hour clock time as a string True BASIC Functions and Statements — 5 STRING TO NUMBER FUNCTIONS Function Result CHR$(x) Character represented by ASCII number x ORD(x$) Ordinal position of x$ in ASCII character set NUM(x$) Numeric value of IEEE 8-byte string NUM$(x) IEEE 8-byte equivalent of numeric value STR$(x) Changes number to a string VAL(x$) Changes string containing digits to a number STRING TRANSFORMING FUNCTIONS Function Result LCASE$(x$) Change letters to lowercase UCASE$(x$) Change letters to uppercase LTRIM$(x$) Remove leading blanks RTRIM$(x$) Remove trailing blanks TRIM$(x$) Remove leading & trailing blanks REPEAT$(x$,n) x$ repeated n times STRING SEARCH FUNCTIONS Function Result LEN(x$) Number of characters in x$ POS(x$,y$,n) First occurrence of y$ in x$ after character n POSR(x$,y$) Ditto POS but starting from the end CPOS(x$,y$) First occurrence in x$ of any character in y$ CPOSR(x$,y$) Ditto CPOS but starting from the end NCPOS(x$,y$) First occurrence in x$ of any character not in y$ NCPOSR(x$,y$) Ditto NCPOS but starting from the end ARRAY FUNCTIONS Function Result DET(a) Determinant of the square matrix a DOT(a,b) Dot product of vectors a and b LBOUND(a,n) Lower bound of dimension n for array a UBOUND(a,n) Upper bound of dimension n for array a SIZE(a,n) Number of element in dimension n of array a MAT FUNCTIONS (that can appear only in MAT assignment statements) Function Result CON Array of ones IDN Identity matrix INV(a) Inverse of array a NUL$ Array of empty strings TRN(a) Transpose of array a ZER Array of zeroes SILVER Edition has all the above, plus an additional 1,443 pre-written interface controls and additional subroutines in compiled form. GOLD Edition has all the above, plus an additional 3,117 pre-written interface controls and additional subroutines in both compiled form and most also in source code. True BASIC - http://www.truebasic.com True BASIC Functions and Statements — 6 32-1 True BASIC Functions 32 This chapter is organized alphabetically by function name. Function names that end with a dollar sign ($) are string-valued; that is, they yield values that are strings. The others are numeric-valued. The following functions are covered here: ABS END_POSTSCRIPT MAXSIZE SEC ACOS EPS MIN SGN ADD_POSTSCRIPT EXLINE MOD SIN ANGLE EXLINE$ NCPOS SINH ASIN EXP NCPOSR SIZE ATN EXTEXT$ NUL$ SQR BEGIN_POSTSCRIPT EXTYPE NUM STR$ CHR$ FP NUM$ TAB CEIL IDN ORD TAN CON INT PACKB TANH COS INV PEEK TIME COSH IP PI TIME$ COT LBOUND POKE TRIM$ CPOS LCASE$ POS TRN CPOSR LEN POSR TRUNCATE CSC LOG RAD UBOUND DATE LOG10 REMAINDER UCASE$ DATE$ LOG2 REPEAT$ UNPACKB DEG LTRIM$ RND USING$ DET MAX ROUND VAL DIVIDE MAXLEN RUNTIME ZER DOT MAXNUM RTRIM$ 32-2 PC Pro Version Reference Manual DIVIDE, ADD_POSTSCRIPT, BEGIN_POSTSCRIPT, END_POSTSCRIPT, PACKB, and POKE are subroutines rather than functions; they must be invoked with CALL statements. The MAT functions and constants (CON, IDN, INV, NUL$, TRN, and ZER) can appear only in MAT assignment statements. TAB can appear only in PRINT statements. The picture transformations (SHIFT, SCALE, ROTATE, and 32 SHEAR) can appear only in DRAW statements and are not included here. There are many additional functions available in libraries, and they are described in each library toolkit section. For some functions, certain values of their arguments may be illegal, causing a runtime error or exception. The programmer can use a WHEN structure (see Chapter 25) to “intercept” such errors and take corrective action. If no WHEN structure is present, the program will halt. We give the number of the exception (returned by the EXTYPE function) and the error message (returned by the EXTEXT$ function) for each function that can generate an exception. The evaluation of some functions may require additional memory that is not available. We have not included this exception (5000). Neither have we included exceptions that may arise from the evaluation of the arguments of the function, which are numeric or string expressions. See Chapter 29, for these errors. The accuracy of the trigonometric and transcendental functions is at least 10 decimals; that is, the absolute error should be less than 10^(-10) in absolute value. (The TAN and EXP functions are computed to an accuracy of 10 significant figures; that is, their relative error should be less than 10^(-10) in absolute value.) If your computer has an arithmetic coprocessor, the accuracy will be that provided by the coprocessor. In what follows, we use the following terms, which are defined in Chapters 28 & 29. numex numeric expression rnumex rounded numeric expression strex string expression redim array redimensioning expression arrayarg array argument (array name with optional bowlegs) True BASIC Functions 32-3 ABS Function ABS(numex) Returns the absolute value of the argument. ABS can be defined in terms of other True BASIC statements as follows: DEF ABS(x) 32 IF x<0 then LET ABS = -x ELSE LET ABS = x END IF END DEF ACOS Function ACOS(numex) Returns the value of the arccosine function. If OPTION ANGLE DEGREES is in effect, the result is given in degrees. If OPTION ANGLE RADIANS (default) is in effect, the result is given in radians. For example, ! For DEGREES ACOS(.5) is 60 ! For RADIANS ACOS(.5) is approx. 1.04720... ACOS may be defined in terms of other True BASIC functions as follows: DEF ACOS(x) = PI/2 - ASIN(x) Exception: 3007 ASIN or ACOS argument must be between 1 and -1.