ML Functions
Programming Features - ML Functions
The ML functions provide operations that are more flexible than ML commands or ML variables. In practice, they behave like built-in BASIC functions: some execute an ML routine and then return a computed value. Functions can return either numeric or string results (including string values that cannot be returned through ML variables).
All ML functions begin with an "@" followed by one or two digits (the function number). Functions are either STRING or NUMERIC, as indicated in the table. Some functions accept required and/or optional parameters, which are placed in parentheses after the function number.
There are 22 string-returning functions & 12 numeric-returning functions.
Example:
1000 a$=@5:sr=st:a=val(a$):ifa<>0thenprint@1(a) 1010 ifsr=.then1000
In this example:
- @5 reads a line from disk (like .01) and returns it as a string.
- VAL() is used to test whether the returned line is numeric; if so, @1 prints the number without the leading space added by STR$ for positive values.
- The loop continues until end-of-file (as indicated by ST).
All ML functions (@##) invoke address $4E21 for ML processing.
The table below lists the ML Functions and descriptions.
| Function | Format and Description |
|---|---|
| @0 | Resident Input Buffer Format: @0 : STRING |
| @1 | Number to String Without Leading Space Format: @1( <number> ) : STRING |
| @2 | Forward Substring Search Format: @2( <string1> , <string2> [ , <number> ] ) : NUMERIC
Examples:
The !52 variable stores the most recent find position (0 if the count form was used). |
| @3 | Repeat Character Format: @3( <string> , <number> ) : STRING |
| @4 | Character Input Format: @4 : STRING |
| @5 | Read Disk Record Format: @5 : STRING |
| @6 | Byte or Word Extraction Format: @6( <string1> [ , <string2> ] ) : NUMERIC
Example: GET#8,A$:I=@6(A$)
Example: IF LEN(I$)=2 THEN L=@6(I$)
Example: GET#8,A$,B$:L=@6(A$,B$) |
| @7 | Word to Two-Byte String Format: @7( <number> ) : STRING |
| @8 | Interactive Line Input Format: @8 : STRING |
| @9 | Free Memory Without Garbage Collection Format: @9 : NUMERIC |
| @10 | Strip Control and Graphics Characters Format: @10( <string> [ , <number> ] ) : STRING |
| @11 | Current Time String Format: @11 : STRING |
| @12 | Overlay String at Position Format: @12( <string1> , <string2> , <number> ) : STRING
Special replace mode: if <number>=0, uses the most recent find position from @2 or @25. If that value is 0 (or if @2/@25 was used in count mode), an ILLEGAL QUANTITY error will occur. |
| @13 | Crash Error Message Format: @13 : STRING |
| @14 | Crash Error Line Number Format: @14 : STRING |
| @15 | Date to Absolute Day Number Format: @15( <year> , <month> , <day> ) : NUMERIC |
| @16 | Absolute Day Number to Year (Sets Month/Day) Format: @16( <number> ) : NUMERIC |
| @17 | Absolute Day Number to Day of Week Format: @17( <number> ) : NUMERIC |
| @18 | Absolute Day Number to to Date String Format: @18( <number> ) : STRING |
| @19 | Date String to Absolute Day Number Format: @19( <string> ) : NUMERIC |
| @20 | Current Overlay Filename Format: @20 : STRING |
| @21 | Alphabetic Lowercase Filter Format: @21( <string> ) : STRING |
| @22 | Compress Number for Disk Storage Format: @22( <number> ) : STRING |
| @23 | Expand Compressed Number Format: @23( <string> ) : NUMERIC |
| @24 | Format Relative-File Record Format: @24( <string> , <number> ) : STRING
Null strings or <number><2 may yield undefined results. |
| @25 | Reverse Substring Search Format: @25( <string1> , <string2> [ , <number> ] ) : NUMERIC |
| @26 | Extract Delimited Field Format: @26( <string1> , <string2> , <number> ) : STRING |
| @27 | Calculate Calendar Age Format: @27( <number1> , <number2> ) : NUMERIC |
| @28 | Search One-Dimensional String Array Format: @28( <string> , <array> ) : NUMERIC |
| @29 | Read Fixed-Length Byte String Format: @29(<count>[,<skip>]) Reads and returns a string containing a fixed number of bytes from the logical file specified by !14.
The function does not use !04, !08, or !15, and does not stop at carriage returns or other delimiter characters. If the file ends or another file-status condition occurs before the requested number of bytes is available, the remainder of the returned string is filled with CHR$(0). Check ST when it is necessary to determine whether all bytes came from the file. Do not use a count of zero. Examples:
|
| @30 | Build Boot-Drive Initialization Command Format: @30( <number> ) : STRING |
| @31 | Enhanced Message-Record Read Format: @31 : (Undocumented) |
| @32 | Read Fixed-Length Numeric Value Format: @32(<count>[,<skip>]) Performs the same fixed-length file read as @29, then converts the returned byte string to a numeric value using the same internal conversion performed by @6.
Do not use a count of zero. Example: A=@32(2,2) This discards the first two bytes of a disk-directory record, reads the following two bytes, and returns their numeric value. This is commonly used to obtain the block count from a Commodore disk-directory entry. The same operation could be written as: A=@6(@29(2,2)) |
| @33 | Return Saved Input Color
This command accepts no arguments and returns a one-character string containing the PETSCII foreground-color control byte that was active when the most recent ML line-input operation began. It is used by the message editor to restore the input color after deleting temporary command prompts. Useful for character deletion, cursor movement, backward color-state reconstruction, prompt removal, and redisplay of edited text. |
Next section: Basic Variables Table