📄 basic.1
字号:
Returns a substring of a$ starting at the i'thpositions and j characters in length. If the secondparameter is not specified then the substring istaken from the start position to the end of a$..TP.B right$(a$, EXPR )Returns the right EXPR characters of a$..TP.B left$(a$, EXPR )Returns the left EXPR characters of a$..TP.B field$( STRINGVAL, VAL { , STRINGVAL } )Returns the N-th field of the first string. If theoptional string is present then use the first characterof that string as the field separator. The defaultseparator 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 lengthequal to the number of seperators in the first string..TP.B hex$( VAL { , EXPR } ).TP.B bin$( VAL { , EXPR } )Returns the hexadecimal or binary string representationcorresponding to VAL. If EXPR is present then thestring is padded with zeros to make it that length..TP.B lcase$( STRINGVAL )Returns STRINGVAL in all lower case characters..TP.B errorstatus$Returns the error message for the last error..PP.SH OPERATORS.PP.TP.B Math OperatorsThe following math operators are available: ^ exponentiation * multiplication / division mod remainder + addition - subtraction.TP.B Logical OperatorsAny non-zero value is true.Logical Operators: not logical not.TP.B Bitwise OperatorsBitwise Operators: and bitwise and or bitwise or xor bitwise exclusive-or.TP.B Comparison OperatorsArithmetic Comparison Operators: <= less than or equal <> not equal to >= greater than or equal = equal > greater than < less than.TP.B x$=y$, x$y$, x$<=y$, x$>=y$, x$<>y$String comparisons; result is 1 if true, 0 if false..TP.B Operator PrecedenceOperator Precedence (highest to lowest): ( ) functions() ^ - {unary_minus} * / mod + - = < > <= >= <> not and or xor.PP.SH UNIX commands:.PP.TP.B gotoxy VAL, VALSets the horizontal and vertical location of the textoutput cursor using vt100/xterm control characters.(0,0) is the upper left corner..TP.B open STRINGEXPR for input as # FNUMWhere STRINGEXPR start with the string: "pipe:"Opens an input pipe with STRINGEXPR as the inputprocess command string.Example: open "pipe:/bin/ls -l" for input as #1.PP.TP.B open STRINGEXPR , INTEXPR for input as # FNUM.B open STRINGEXPR , INTEXPR for output as # FNUMWhere STRINGEXPR start with the string: "socket:"Opens a socket with STRINGEXPR as the hostname and INTEXPR as theport number. The input needs to be opened before the output.Example: open "socket:foo.net",7 for input as #3 : rem echo port open "socket:foo.net",7 for output as #4 print #4, "hello" input #3, a$ close #4 : close #3.PP.SH UNIX/linux functions:.PP.TP.B #cbas#run_onlyWhen used in a Basic program file, upon load, sets the Chipmunk Basic interpreter to run-only mode,interactive mode disabled. The Stop and Endcommands and the use of Ctrl-C will quit theinterpreter..TP.B sys( STRINGVAL )UNIX system call. The string parameter is given tothe shell as a command. Returns exit status..TP.B fn kill( STRINGVAL )Removes the file with filename STRINGVAL. Returns 0on success..TP.B getenv$( STRINGVAL ) Returns value for environment name STRINGVAL. .TP.B argv$Returns the UNIX shell command line arguments..PP.SH Macintosh commands:.PP*** NOTE ***.PPMany MacOS specific functions and commands are onlydocumented in the Chipmunk Basic quick reference file..TP.B gotoxy VAL, VALSet the horizontal and vertical location of thetext output cursor. (0,0) is the upper left corner..TP.B moveto VAL, VALSets the (x,y) location of the graphics pen..TP.B lineto VAL, VALDraws a line from the current pen location to location(x,y) in the graphics window..TP.B window x, y, char_cols, char_linesChange the text console window position and size..TP.B 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}.TP.B sound VAL, VAL, VAL The parameters are:frequency{in Hz}, seconds_duration, volume{0..100}.TP.B say STRINGVALSpeaks STRINGVAL if the Speech Manager Extension isresident. Try "say a$,200,46,1" for faster speech..TP.B open "SFGetFile" for input as #FNUM.TP.B open "SFPutFile" for output as #FNUMPuts up a standard file dialog for the file name..TP.B files { STRINGVAL }Displays a listing of files in the named or currentdirectory..SH Macintosh functions:.PP.TP.B freReturns the amount of memory left for program use. .TP.B date$Returns a string corresponding to the current date..TP.B time$Returns a string corresponding to the current time..TP.B pos(VAL)Returns the horizontal position of the text cursor.If VAL is negative returns the vertical position..TP.B errorstatus$Also returns the full path name of the program andfiles opened by SFGetFile and SFPutFile. (Only under System 7and also only if the name fits in a string variable).SH Macintosh menu items:.PP.TP.B Open or .B cmd-Owill put up a dialog to allow selectionof a program file to load. Basic Programfile names must end with a ".bas" suffix..TP.B Copywill allow copying picts from the graphicswindow..TP .Command-period will stop program execution..TP.B PrintPrint graphics window if it's the frontmostwindow. Only the graphics window can be printed..PP.SH RESERVED WORDS AND SYMBOLS.PP+ - * / ^ mod and or xor not > < >= <= <> = ()sqr log exp sin cos tan atn piabs sgn int rnd peek val asc lenmid$ right$ left$ str$ chr$ lcase$ ucase$goto if then else endif gosub returnfor to step next while wend select caserem let dim erase data read restore field$input print open for output append as close# load saverandom lof loc get put inkey$ input$ eof files fgetbyte# fseek# fputbyterun stop end exit quit cont renum new cleardate$ time$ timer sound morse say doeventshome cls gotoxy htab vtab pos graphics sprite pset moveto lineto window scrn mousevarptr peek poke fre push pop isarraysub call usr def fntype class extends string integer single doubleasin acos sinh cosh tanh log10 floor true false uboundeqv imp static option degrees radians redimmsgbox do loop until breakmethod private public local menu dialog memstat()draw play bload bsave min max mateach resume functionkey is each set width swap.SH CONVENTIONS.PP.TP.B EXPR an expression that evaluates to a numeric value..TP.B STRINGEXPR a string expression..TP.B VAR a numeric variable..TP.B STRINGVAR a string variable. Name must end with a "$"..TP.B 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 andprogram statements is legal. Line numbers can bebetween 1 and 2147483647. Programs lines must be nolonger 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 witha "0x" as in 0x02ae, or by "&h" as in &h0172.Multiple statements may be given on one line, separated bycolons:10 INPUT X : PRINT X : STOP.PP.SH DIAGNOSTICSSome errors can be caught by the user program using the"on error goto" command. If no error trapping routine has beensupplied then program execution is terminated and a message isprinted with the corresponding line number.Graphics (MacOS) may require that the preferred memoryrequirements be increased using the Finder "Get Info" dialogbox..PP.SH CHANGES v3.6.1 - changed exponentiation/negation precedence - changed default mat origin v3.6.0 - added atn(x,y), exit() status, fn kill file. v3.5.8b5 - changed int() to round toward negative infinity. v3.5.7b3 - added network socket i/o v3.5.7b2 - fixed 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 - lowered 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 definitionsMany others ....SH BUGS.PPMany. Perhaps competitive with Central American rain forests.FOR/NEXT loops with integer indices require a variable in theNEXT statement. Integer arrays can only have a dimension ofone and will only work in assignment (LET) statements. Allarithmetic on integer variables is done using floating pointarithmetic. DIM AS DOUBLE and DIM AS INTEGER statements areignored.Many string functions (except +, MID$, LEN and INSTR) silentlytruncate their results to 254 characters (e.g. withoutwarning). All string function may silently truncate stringslonger than 32766 characters. Any operation on strings longerthan 254 characters will cause the program to run slower.Comments starting with ' sometimes can't be used afterstatements that can end with a string parameter. ( : 'should always work.)Any variables used as a CLASS, or TYPE, globally overide alllocal variables of the same names. Local TYPE'd variablesmust be declared globally as TYPE'd variables. Named SUBroutinesare slower than GOSUBs. The combined length of a SUBroutine nameand any local variables declared STATIC must be less than 29characters.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 linemodified before a RETURN or ENTER key. The EDIT command andMac screen editing are incompatible.There are many undocumented graphics and sprite commandsand keywords in the Macintosh port. See the accompanyingREADME and Chipmunk Basic quick-reference file..SH DISCLAIMER.PPThere is no warranty that this document is accurate..SH SEE ALSOThe Chipmunk Basic Home Page:.TP <http://www.nicholson.com/rhn/basic.html >.SH AUTHORSDavid Gillespie wrote basic.p 1.0 and the p2c lib.Ron Nicholson (rhn@nicholson.com) added file i/o, graphicsand did the Unix, Macintosh and PowerMac port. (1990Aug-2002Jan)David Forrest (drf5n@virginia.edu) converted man page to nroff (1999 March)Portions of this document are Copyright (C) 1989 Dave Gillespie.Portions of this document areCopyright (C)1994,2002 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 + -