📄 basic-man.txt
字号:
inkey$ Return one character from the keyboard if input is available. Returns a zero length string { "" } if no keyboard input is available. Non-blocking. Can be used for keyboard polling. input$( EXPR { , FILENUM } ) Returns EXPR characters from file FILENUM. If f is not present then get input from the console keyboard. mid$( a$, i { , j } ) Returns a substring of a$ starting at the i'th positions and j characters in length. If the second parameter is not specified then the substring is taken from the start position to the end of a$. right$(a$, EXPR ) Returns the right EXPR characters of a$. left$(a$, EXPR ) Returns the left EXPR characters of a$. field$( STRINGVAL, VAL { , STRINGVAL } ) Returns the N-th field of the first string. If the optional string is present then use the first character of that string as the field separator. The default separator is a space. Similar to UNIX 'awk' fields. e.g. field$("1 22 333 4", 3) returns "333" If VAL is -1 then returns a string with a length equal to the number of seperators in the first string. hex$( VAL { , EXPR } ) bin$( VAL { , EXPR } ) Returns the hexadecimal or binary string representation corresponding to VAL. If EXPR is present then the string is padded with zeros to make it that length. lcase$( STRINGVAL ) Returns STRINGVAL in all lower case characters. errorstatus$ Returns the error message for the last error. OPERATORS The following math operators are available: ^ exponentiation * multiplication / division mod remainder + addition - subtraction logical operators: (any non-zero value is true) not logical not bitwise operators: and bitwise and or bitwise or xor bitwise exclusive-or comparison operators: <= less than or equal <> not equal to >= greater than or equal = equal > greater than < less than x$=y$, x$y$, x$<=y$, x$>=y$, x$<>y$ String comparisons; result is 1 if true, 0 if false. Operator precedence (highest to lowest): ( ) functions() ^ -{unary_minus} * / mod + - = < > <= >= <> not and or xor UNIX/linux commands: open "pipe:" + STRINGEXPR for input as # FNUM Opens an input pipe with STRINGEXPR as the input process command string. example: open "pipe:/bin/ls -l" for input as #1 open "socket:" + STRINGEXPR , EXPR for input as # FNUM open "socket:" + STRINGEXPR , EXPR for output as # FNUM Open a socket to the server and port specified by STRINGEXPR and EXPR. The input port must be opened before the output port. #cbas#run_only When used in a Basic program file, upon load sets the Chipmunk Basic interpreter to run-only mode. Interactive mode disabled. Thus the Stop and End commands and the use of Ctrl-C will quit the interpreter. UNIX/linux functions: argv$ Returns the UNIX shell command line arguments. sys( STRINGVAL ) UNIX system call. The string parameter is given to the shell as a command. Returns exit status. getenv$( STRINGVAL ) Returns value for environment name STRINGVAL. fn pid() fn ppid() fn uid() Returns system process and user info. fn sysfork() Forks process. Returns 0 to the child process and the pid of new process to the parent process. fn kill( STRINGVAL ) Deletes the file named by STRINGVAL. Returns 0 if successful. exit( EXPR ) Exits Basic interpreter with status value of EXPR. Macintosh commands: *** NOTE *** Many MacOS specific functions and commands are only documented in the Chipmunk Basic quick reference file. gotoxy VAL, VAL Set the horizontal and vertical location of the text output cursor. (0,0) is the upper left corner. moveto VAL, VAL Sets the (x,y) location of the graphics pen. lineto VAL, VAL Draws a line from the current pen location to location (x,y) in the graphics window. window x, y, char_cols, char_lines Change the text console window position and size. morse STRINGVAL { , VAL, VAL, VAL, VAL } Plays morse code through the speaker. The parameters are: dot-speed-wpm, volume{0..100}, word-speed-wpm, frequency{in Hz or cps} sound VAL, VAL, VAL The parameters are: frequency{in Hz}, seconds_duration, volume{0..100} say STRINGVAL Speaks STRINGVAL if the Speech Manager Extension is resident. Try "say a$,200,46,1" for faster speech. open "SFGetFile" for input as #FNUM open "SFPutFile" for output as #FNUM Puts up a standard file dialog for the file name. files { STRINGVAL } Displays a listing of files in the named or current directory. Macintosh functions: fre Returns the amount of memory left for program use. date$ Returns a string corresponding to the current date. time$ Returns a string corresponding to the current time. pos(VAL) Returns the horizontal position of the text cursor. If VAL is negative returns the vertical position. errorstatus$ Also returns the full path name of the program and files opened by SFGetFile and SFPutFile (Only under System 7 and only if the path name fits in a string variable) Macintosh menu items: Open or O will put up a dialog to allow selection of a program file to load. Basic Program file names must end with a ".bas" suffix. Copy will allow copying picts from the graphics window. . Command-period will stop program execution. RESERVED WORDS AND SYMBOLS + - * / ^ mod and or xor not > < >= <= <> = () sqr log exp sin cos tan atn pi abs sgn int rnd peek val asc len mid$ right$ left$ str$ chr$ lcase$ ucase$ goto if then else endif gosub return for to step next while wend select case rem let dim erase data read restore field$ input print open for output append as close# load save random lof loc get put inkey$ input$ eof files fgetbyte# fseek# fputbyte run stop end exit quit cont renum new clear date$ time$ timer sound morse say doevents home cls gotoxy htab vtab pos graphics sprite pset moveto lineto window scrn mouse varptr peek poke fre push pop isarray sub call usr def fn type class extends string integer single double asin acos sinh cosh tanh log10 floor true false ubound eqv imp static option degrees radians redim msgbox do loop until break method private public local menu dialog memstat() draw play bload bsave min max mat each resume function key is each set width swap CONVENTIONS EXPR an expression that evaluates to a numeric value. STRINGEXPR a string expression. VAR a numeric variable. STRINGVAR a string variable. Name must end with a "$". INTEGERVAR a 16-bit variable. Name must end with a "%". All program lines must begin with a line number. Using spaces (indentation) between the line number and program statements is legal. Line numbers can be between 1 and 2147483647. Programs lines must be no longer than 254 characters in length. Subroutine names starting with "fn" are reserved for the (obsolete) def fn functions. Hexadecimal numbers can be entered by preceding them with a "0x" as in 0x02ae, or by "&h" as in &h0172. Multiple statements may be given on one line, separated by colons: 10 INPUT X : PRINT X : STOP DIAGNOSTICS Some errors can be caught by the user program using the "on error goto" command. If no error trapping routine has been supplied then program execution is terminated and a message is printed with the corresponding line number. CHANGES v3.6.1 - changed precedence of unary minus (-) to below exponentiation (^) to match ANSI/ISO specification. - changed default matrix origin to 1 - added mat print commmand. v3.6.0 - added unix exit status, fn kill(), fn bigendian() v3.5.9b4 - fixed def fn array parameters, added atn(x,y) v3.5.9b3 - fixed bugs with if():, instr(), mid$ & val("..") v3.5.9 - fixed bugs in format$() & intl. string comparisons v3.5.8b7 - fixed bugs in array assignment, the read/data statement, fputbyte(), and ELSEIF nesting - added the MAT INVERT statement v3.5.8 - changed int() to round towards -infinity. v3.5.7b3 - added network socket i/o v3.5.7b2 - fixed unix/linux rnd() function v3.5.7b1 - fixed a problem with array indexes > 65k v3.5.3 - allow integer (i%) variables as for/next loop indices v3.4.7 - lower precedence of NOT operator - disabled ON GOTO range checking v3.4.6 - added MAT matrix statements v3.4.0 - OPEN ELSE added v3.3.4 - changed integer conversion to rounding - changed sub return values to: sub_name = x - added reserved words for: true false v3.3.3 - added acos, tanh, log10 v3.2.8 - added class definitions Many others ... BUGS Many. Perhaps competitive with Central American rain forests. FOR/NEXT loops with integer indices require a variable in the NEXT statement. Integer arrays can only have a dimension of one and will only work in assignment (LET) statements. All arithmetic on integer variables is done using floating point arithmetic. DIM AS DOUBLE and DIM AS INTEGER statements are ignored. Many string functions (except +, MID$, LEN and INSTR) silently truncate their results to 254 characters (e.g. without warning). All string function may silently truncate strings longer than 32766 characters. Any operation on strings longer than 254 characters will cause the program to run slower. Comments starting with ' sometimes can't be used after statements that can end with a string parameter. ( : ' should always work.) Any variables used as a CLASS, or TYPE, globally overide all local variables of the same names. Local TYPE'd variables must be declared globally as TYPE'd variables. Named SUBroutines are slower than GOSUBs. The combined length of a SUBroutine name and any local variables declared STATIC must be less than 29 characters. Can't CONTinue from an error inside a named SUB subroutine. The PRINT USING format string doesn't recognize comma's, underscores and many other common format characters. Macintosh screen editing will only recognise the last line modified before a RETURN or ENTER key. The EDIT command and Mac screen editing are incompatible. There are many undocumented graphics and sprite commands and keywords in the Macintosh port. See the accompanying README and Chipmunk Basic quick-reference file. DISCLAIMER There is no warranty that this document is accurate. SEE ALSO The Chipmunk Basic Home Page: http://www.nicholson.com/rhn/basic AUTHORS David Gillespie wrote basic.p 1.0 and the p2c lib. Ron Nicholson (rhn AT nicholson.com) added file i/o, graphics and did the Unix, Macintosh and PowerMac port. (1990-1997Nov) Portions of this document are Copyright (C) 1989 Dave Gillespie. Copyright (C) 1994,1998,2004 Ronald H. Nicholson, Jr. All rights reserved. "Applesoft" is a trademark of Apple Computer, Inc., etc.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -