Advertisement
Guest User

Untitled

a guest
May 19th, 2023
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.54 KB | None | 0 0
  1. .ds ^ \f3\^\s+4\v'.3m'^\v'-.3m'\s-4\^\fP
  2. .TH BS 1 "CB\-UNIX 2.1"
  3. .SH NAME
  4. bs \- a compiler/interpreter for modest-sized programs
  5. .SH SYNOPSIS
  6. .B bs
  7. [ file [ arg ... ] ]
  8. .SH DESCRIPTION
  9. .I Bs\^
  10. is a remote descendant of Basic and Snobol4
  11. with a little C language thrown in.
  12. .I Bs\^
  13. is designed for programming tasks where program development time
  14. is as important as the resulting speed of execution.
  15. Formalities of data declaration and file/process manipulation
  16. are minimized.
  17. Line-at-a-time debugging, the
  18. .I trace\^
  19. and
  20. .I dump\^pile\^
  21. and
  22. .I execute\^
  23. below).
  24. The result of an immediate expression statement is printed.
  25. .PP
  26. .I Bs\^
  27. programs are made up of input lines.
  28. If the last character on a line is a \f3\e\fP, the line is continued.
  29. .I Bs\^
  30. accepts lines of the following form:
  31. .PP
  32. .RS
  33. statement
  34. .br
  35. label statement
  36. .RE
  37. .PP
  38. A label is a
  39. .I name\^
  40. (see below)
  41. followed by a colon.
  42. A label and a variable can have the same name.
  43. .PP
  44. A
  45. .I bs\^
  46. statement is either an
  47. expression
  48. or a keyword followed by zero or more expressions.
  49. Some keywords
  50. .RI ( clear ,
  51. .IR compile ,
  52. .IR ! ,
  53. .IR execute ,
  54. and
  55. .IR run )
  56. are always executed as they are compiled.
  57. .PP
  58. .B "Statement Syntax:"
  59. .HP 3
  60. expression
  61. .br
  62. The expression is executed for its side
  63. effects (value, assignment or function call).
  64. The details of expressions follow the description of
  65. statement types below.
  66. .HP 3
  67. .B break
  68. .br
  69. .I Break\^
  70. exits from the inner-most
  71. .I for/while\^
  72. loop.
  73. .HP 3
  74. .B clear
  75. .br
  76. Clears the symbol table and compiled statements.
  77. .I Clear\^
  78. is executed immediately.
  79. .HP 3
  80. .B compile
  81. [ expression ]
  82. .br
  83. Succeeding statements are compiled
  84. (overrides the immediate execution default).
  85. The optional expression is evaluated and used as a file
  86. name for further input.
  87. A
  88. .I clear\^
  89. is associated with this latter case.
  90. .I Compile\^
  91. is executed immediately.
  92. .HP 3
  93. .BR include " expression"
  94. .br
  95. The expression should evaluate to a file name.
  96. The file must contain
  97. .I bs\^
  98. source statements.
  99. .I Include\^
  100. statements may not be nested.
  101. .HP 3
  102. .B continue
  103. .br
  104. .I Continue\^
  105. transfers to the loop-continuation
  106. of the current
  107. .I for/while\^
  108. loop.
  109. .HP 3
  110. .B dump
  111. .br
  112. The
  113. name and current value of every
  114. non-local
  115. variable is printed.
  116. After an error or interrupt, the number of the last
  117. statement and (possibly) the user-function trace are displayed.
  118. .HP 3
  119. .B exit
  120. [ expression ]
  121. .br
  122. Return to system level.
  123. The
  124. expression
  125. is returned as process status.
  126. .HP 3
  127. .B execute
  128. .br
  129. Change to immediate execution mode
  130. (an interrupt has a similar effect).
  131. This statement does not cause stored statements to execute (see
  132. .I run\^
  133. below).
  134. .ne 8
  135. .HP 3
  136. .B for
  137. name
  138. .B =
  139. expression expression statement
  140. .br
  141. .ns
  142. .HP 3
  143. .B for
  144. name
  145. .B =
  146. expression expression
  147. .br
  148. \&.\|.\|.
  149. .br
  150. .ns
  151. .HP 3
  152. .B next
  153. .HP 3
  154. .B for
  155. expression
  156. .B ,
  157. expression
  158. .B ,
  159. expression statement
  160. .br
  161. .br
  162. .ns
  163. .HP 3
  164. .B for
  165. expression
  166. .B ,
  167. expression
  168. .B ,
  169. expression
  170. .br
  171. \&.\|.\|.
  172. .br
  173. .ns
  174. .HP 3
  175. .B next
  176. .br
  177. The
  178. .I for\^
  179. statement
  180. repetitively executes a
  181. statement (first form)
  182. or a group of statements (second form)
  183. under control of a named variable.
  184. The variable takes on the value of
  185. the first expression,
  186. then is incremented by one on each loop,
  187. not to exceed the value of
  188. the second expression.
  189. The third and fourth forms require three expressions
  190. separated by commas.
  191. The first of these is the initialization, the second
  192. is the test (true to continue), and the third is the
  193. loop-continuation action (normally an increment).
  194. .HP 3
  195. .B fun
  196. f(\|[\|a,
  197. \&.\|.\|. ]\|) [\|v,
  198. \&.\|.\|. ]
  199. .br
  200. \&.\|.\|.
  201. .br
  202. .br
  203. .ns
  204. .HP 3
  205. .B nuf
  206. .br
  207. .I Fun\^
  208. defines the function name, arguments, and local variables
  209. for a user-written function.
  210. Up to ten arguments and local variables are allowed.
  211. Such names cannot be arrays, nor can they be I/O associated.
  212. Function definitions may not be nested.
  213. .HP 3
  214. .B freturn
  215. .br
  216. A way to signal the failure of a user-written function.
  217. See the interrogation operator (\f3?\fP) below.
  218. If interrogation is not present,
  219. .I freturn\^
  220. merely returns zero.
  221. When interrogation
  222. .I is\^
  223. active,
  224. .I freturn\^
  225. transfers to that expression
  226. (possibly by-passing intermediate function returns).
  227. .HP 3
  228. .B goto
  229. name
  230. .br
  231. Control is passed to the internally stored statement
  232. with the matching label.
  233. .HP 3
  234. .B if
  235. expression statement
  236. .br
  237. .ns
  238. .HP 3
  239. .B if
  240. expression
  241. .br
  242. \&.\|.\|.
  243. .br
  244. .ns
  245. .HP 3
  246. [
  247. .B else
  248. .br
  249. \&.\|.\|.
  250. ]
  251. .br
  252. .ns
  253. .HP 3
  254. .B f\&i
  255. .br
  256. The statement (first form)
  257. or group of statements (second form)
  258. is executed if the expression evaluates
  259. to non-zero.
  260. The strings
  261. .B 0
  262. and "" (null) evaluate as zero.
  263. In the second form,
  264. an optional
  265. .I else\^
  266. allows for a group of statements to be
  267. executed when the first group is not.
  268. The only statement permitted on the same line with an
  269. .I else\^
  270. is an
  271. .IR if ;
  272. only other
  273. .IR f\&i "'s can be on the same line with a"
  274. .IR f\&i .
  275. .HP 3
  276. .B return
  277. [expression]
  278. .br
  279. The expression is evaluated and the result is passed
  280. back as the value of a function call.
  281. If no expression is given, zero is returned.
  282. .HP 3
  283. .B onintr
  284. label
  285. .br
  286. .ns
  287. .HP 3
  288. .B onintr
  289. .br
  290. The
  291. .I onintr\^
  292. command
  293. provides program control of interrupts.
  294. In the first form,
  295. control will pass to the label given,
  296. just as if a
  297. .I goto\^
  298. had been executed at the time
  299. .I onintr\^
  300. was executed.
  301. The effect of the statement is cleared after each interrupt.
  302. In the second form,
  303. an interrupt will cause
  304. .I bs\^
  305. to terminate.
  306. .HP 3
  307. .B run
  308. .br
  309. The random number generator is reset.
  310. Control is passed to the first internal
  311. statement.
  312. If the
  313. .I run\^
  314. statement is contained in a file, it should be the
  315. last statement.
  316. .HP 3
  317. .B stop
  318. .br
  319. Execution of internal statements is stopped.
  320. .I Bs\^
  321. reverts to immediate mode.
  322. .HP 3
  323. .B trace
  324. [ expression ]
  325. .br
  326. The
  327. .I trace\^
  328. statement controls function tracing.
  329. If the expression is null (or evaluates to zero), tracing is turned off.
  330. Otherwise,
  331. a record of user-function calls/returns will be printed.
  332. Each
  333. .I return\^
  334. decrements the
  335. .I trace\^
  336. expression value.
  337. .HP 3
  338. .B while
  339. expression statement
  340. .br
  341. .br
  342. .ns
  343. .HP 3
  344. .B while
  345. expression
  346. .br
  347. \&.\|.\|.
  348. .br
  349. .br
  350. .ns
  351. .HP 3
  352. .B next
  353. .br
  354. .I While\^
  355. is similar to
  356. .I for\^
  357. except that only the conditional expression
  358. for loop-continuation is given.
  359. .HP 3
  360. .B !
  361. shell command
  362. .br
  363. An immediate escape to the Shell.
  364. .HP 3
  365. .B #
  366. \&.\|.\|.
  367. .br
  368. This statement is ignored.
  369. It is used to interject commentary in a program.
  370. .PP
  371. .B "Expression Syntax:"
  372. .HP 3
  373. name
  374. .br
  375. A name is used to specify a variable.
  376. Names are composed of a letter
  377. (upper or lower case)
  378. optionally
  379. followed by letters and digits.
  380. Only the first six characters of a name are significant.
  381. Except for names declared in
  382. .I fun\^
  383. statements,
  384. all names are global to the program.
  385. Names can take on numeric
  386. (double float) values, string values,
  387. or can be associated with input/output
  388. (see the built-in function
  389. .IR open (\|)
  390. below).
  391. .HP 3
  392. name
  393. .B (
  394. [expression [
  395. .B ,
  396. expression] .\|.\|. ]
  397. .B )
  398. .br
  399. Functions
  400. can be called by a name followed by the arguments
  401. in parentheses separated by commas.
  402. Except for built-in functions (listed below),
  403. the name must
  404. be defined with a
  405. .I fun\^
  406. statement.
  407. Arguments to functions are passed by value.
  408. .HP 3
  409. name
  410. .B [
  411. expression
  412. [
  413. .B ,
  414. expression
  415. ] .\|.\|.
  416. .B ]
  417. .br
  418. Each expression is truncated to an integer
  419. and used as a specifier for the name.
  420. The resulting array reference is syntactically identical to a name.
  421. .B a[1,2]
  422. is the same as
  423. .BR a[1][2] .
  424. The truncated expressions are restricted to
  425. values between 0 and 32767.
  426. .HP 3
  427. number
  428. .br
  429. A number is used to represent a constant value.
  430. A number is written in Fortran style,
  431. and contains digits, an optional decimal point,
  432. and possibly a scale factor consisting
  433. of an
  434. .B e
  435. followed by a possibly signed exponent.
  436. .HP 3
  437. string
  438. .br
  439. Character strings are delimited by \f3"\fP characters.
  440. The \f3\e\fP escape character allows the double quote (\^\f3\e"\fP),
  441. new-line (\^\f3\en\fP), carriage return (\^\f3\er\fP), backspace (\^\f3\eb\fP), and tab (\^\f3\et\fP)
  442. characters
  443. to appear in a string.
  444. Otherwise, \f3\e\fP stands for itself.
  445. .HP 3
  446. .B (
  447. expression
  448. .B )
  449. .br
  450. Parentheses are used to alter the normal order of evaluation.
  451. .HP 3
  452. .B (
  453. .RB expression ,
  454. expression
  455. .RB [ ,
  456. expression .\|.\|. ]
  457. .B ") ["
  458. expression
  459. .B ]
  460. .br
  461. The bracketed expression is used as a subscript to select a
  462. comma-separated expression from the parenthesized list.
  463. List elements are numbered from the left, starting at zero.
  464. The expression:
  465. .IP "" 10
  466. ( False, True )[ a == b ]
  467. .IP "" 3
  468. has the value
  469. .I True
  470. if the comparison is true.
  471. .HP 3
  472. .B ?
  473. expression
  474. .br
  475. The interrogation operator
  476. tests for the success of the expression rather than its value.
  477. At the moment, it is useful for testing
  478. end-of-file
  479. (see examples in the
  480. .I "Programming Tips\^"
  481. section below),
  482. the result of the
  483. .I eval\^
  484. built-in function,
  485. and for checking the return from user-written functions
  486. (see
  487. .IR freturn ).
  488. An interrogation ``trap'' (end-of-file,
  489. etc.)
  490. causes an immediate transfer to the most recent
  491. interrogation, possibly skipping assignment statements or intervening
  492. function levels.
  493. .HP 3
  494. .BR \- " expression"
  495. .br
  496. The result is the negation of the expression.
  497. .HP 3
  498. .BR ++ " name"
  499. .br
  500. Increments the value of the variable (or array reference).
  501. The result is the new value.
  502. .HP 3
  503. .BR \-\- " name"
  504. .br
  505. Decrements the value of the variable. The result is the new value.
  506. .HP 3
  507. .B !
  508. expression
  509. .br
  510. The logical negation of the expression.
  511. Watch out for the shell escape command.
  512. .HP 3
  513. expression
  514. .I operator\^
  515. expression
  516. .br
  517. Common functions of two arguments are abbreviated
  518. by the two arguments separated by an operator denoting the function.
  519. Except for the assignment,
  520. concatenation, and relational operators, both operands are converted to numeric form
  521. before the function is applied.
  522. .PP
  523. .B "Binary Operators"
  524. (in increasing precedence):
  525. .HP 3
  526. .B =
  527. .br
  528. .B =
  529. is the assignment operator.
  530. The left operand must be a name or an array element.
  531. The result is the right operand.
  532. Assignment binds right to left,
  533. all other operators bind left to right.
  534. .HP 3
  535. .B \(ul
  536. .br
  537. .B \(ul
  538. (underscore)
  539. is the concatenation operator.
  540. .HP 3
  541. .B &\ \(bv
  542. .br
  543. .B &
  544. (logical and)
  545. has result zero if either of its arguments are zero.
  546. It has result one if both of its arguments are non-zero. \(bv
  547. (logical or)
  548. has result zero if both of its arguments are zero.
  549. It has result one if either of its arguments is non-zero.
  550. Both operators treat a null string as a zero.
  551. .HP 3
  552. .B <\ <=\ >\ >=\ ==\ !=
  553. .br
  554. The relational operators
  555. (\f3<\fP less than, \f3<=\fP less than or equal,
  556. \f3>\fP greater than,
  557. \f3>=\fP greater than or equal,
  558. \f3==\fP equal to,
  559. \f3!=\fP not equal to)
  560. return one if their arguments are in the specified
  561. relation.
  562. They return zero otherwise.
  563. Relational operators at the same level extend as follows:
  564. .I a>b>c\^
  565. is the same as
  566. .IR "a>b & b>c" .
  567. A string comparison is made if both operands are strings.
  568. .HP 3
  569. .B +\ \-
  570. .br
  571. Add and subtract.
  572. .HP 3
  573. .B \(**\ /\ %
  574. .br
  575. Multiply, divide, and remainder.
  576. .HP 3
  577. .ne 5
  578. \*^
  579. .br
  580. Exponentiation.
  581. .ne 6
  582. .PP
  583. .B "Built-in Functions:"
  584. .PP
  585. .ce
  586. .I "Dealing with arguments\^"
  587. .HP 3
  588. .B arg(i)
  589. .br
  590. is the value of the
  591. .IR i -th
  592. actual parameter on the current level
  593. of function call.
  594. At level zero,
  595. .I arg\^
  596. returns the
  597. .IR i -th
  598. command-line argument
  599. .RI ( arg (0)
  600. returns
  601. .BR bs ).
  602. .HP 3
  603. .B narg(\|)
  604. .br
  605. returns the number of arguments passed.
  606. At level zero, the command argument count is returned.
  607. .PP
  608. .ce
  609. .I "Mathematical\^"
  610. .HP 3
  611. .B abs(x)
  612. .br
  613. is the absolute value of
  614. .IR x .
  615. .HP 3
  616. .B atan(x)
  617. .br
  618. is the arctangent of
  619. .IR x .
  620. Its value
  621. is between \-\(*p/2 and \(*p/2.
  622. .HP 3
  623. .B ceil(x)
  624. .br
  625. returns
  626. the smallest integer not less than
  627. .IR x .
  628. .HP 3
  629. .B cos(x)
  630. .br
  631. is the cosine of
  632. .I x\^
  633. (radians).
  634. .HP 3
  635. .B exp(x)
  636. .br
  637. is the exponential function of
  638. .IR x .
  639. .HP 3
  640. .B floor(x)
  641. .br
  642. returns
  643. the largest integer not greater than
  644. .IR x .
  645. .HP 3
  646. .B log(x)
  647. .br
  648. is the natural logarithm of
  649. .IR x .
  650. .HP 3
  651. .B rand(\|)
  652. .br
  653. is a uniformly distributed random
  654. number between zero and one.
  655. .HP 3
  656. .B sin(x)
  657. .br
  658. is the sine of
  659. .I x\^
  660. (radians).
  661. .HP 3
  662. .B sqrt(x)
  663. .br
  664. is the square root of
  665. .IR x .
  666. .PP
  667. .ce
  668. .I "String operations\^"
  669. .HP 3
  670. .B size(s)
  671. .br
  672. the size (length in bytes) of
  673. .I s\^
  674. is returned.
  675. .HP 3
  676. .B "format(f, a)"
  677. .br
  678. returns the formatted value of
  679. .IR a .
  680. .I F\^
  681. is assumed to be a format specification in the style of
  682. .IR printf (3S).
  683. Only the
  684. .BR %\|.\|.\|.\|f ,
  685. .BR %\|.\|.\|.\|e ,
  686. and
  687. .B %\|.\|.\|.\|s
  688. types are safe.
  689. .HP 3
  690. .B "index(x, y)"
  691. .br
  692. returns the number of the first position in
  693. .I x\^
  694. that any of the characters from
  695. .I y\^
  696. matches.
  697. No match yields zero.
  698. .HP 3
  699. .B "trans(s, f, t)"
  700. .br
  701. Translates characters of the source
  702. .I s\^
  703. from
  704. matching characters in
  705. .I f\^
  706. to a character in the same position in
  707. .IR t .
  708. Source characters that do not appear in
  709. .I f\^
  710. are copied to the result.
  711. If the string
  712. .I f\^
  713. is longer than
  714. .IR t ,
  715. source characters that match in the excess portion of
  716. .I f\^
  717. do not appear in the result.
  718. .HP 3
  719. .B "substr(s, start, width)"
  720. .br
  721. returns the sub-string of
  722. .I s\^
  723. defined by the
  724. .IR start ing
  725. position and
  726. .IR width .
  727. .HP 3
  728. .B "match(string, pattern)"
  729. .br
  730. .ns
  731. .HP 3
  732. .B mstring(n)
  733. .br
  734. The
  735. .I pattern\^
  736. is similar to the regular expression syntax of the
  737. .IR ed (1)
  738. command.
  739. The characters \f3.\fP, \f3[\fP, \f3]\fP, \*^ (inside
  740. brackets), \f3\(**\fP and \f3$\fP are special.
  741. The
  742. .I mstring\^
  743. function returns the \f2n\^\fP-th (1 <= \f2n\^\fP <= 10) substring of the subject
  744. that occurred between pairs of the pattern symbols \f3\e(\fP and \f3\e)\fP
  745. for the most recent call to
  746. .IR match .
  747. To succeed, patterns must match the beginning of the string
  748. (as if all patterns began with \*^).
  749. The function
  750. returns the number of characters matched.
  751. For example:
  752. .IP "" 10
  753. match("a123ab123", ".\(**\e([a\-z]\e)") == 6
  754. .br
  755. mstring(1) == "b"
  756. .PP
  757. .ce
  758. .I "File handling\^"
  759. .HP 3
  760. .B "open(name, file, function)"
  761. .br
  762. .br
  763. .ns
  764. .HP 3
  765. .B close(name)
  766. .br
  767. The
  768. .I name\^
  769. argument must be a
  770. .I bs\^
  771. variable name (passed as a string).
  772. For the
  773. .IR open ,
  774. the
  775. .I file\^
  776. argument
  777. may be
  778. .BR 1) " a 0 (zero), 1, or 2 representing standard input, output,"
  779. or error output, respectively,
  780. .BR 2) " a string representing a file name,"
  781. or
  782. .BR 3) ""
  783. a string beginning with an \f3!\fP representing a command to be executed
  784. (via
  785. .IR "sh \-c" ).
  786. The
  787. .I function\^
  788. argument
  789. must be either
  790. .B r
  791. (read),
  792. .B w
  793. (write),
  794. .B W
  795. (write without new-line),
  796. or
  797. .B a
  798. (append).
  799. After a
  800. .IR close ,
  801. the
  802. .I name\^
  803. reverts to being an ordinary variable.
  804. The initial associations are:
  805. .IP "" 10
  806. open("get", 0, "r")
  807. .br
  808. open("put", 1, "w")
  809. .br
  810. open("puterr", 2, "w")
  811. .IP "" 3
  812. Examples are given in the following section.
  813. .HP 3
  814. .B "access(s, m)"
  815. .br
  816. executes
  817. .IR access (2).
  818. .HP 3
  819. .B ftype(s)
  820. .br
  821. returns a single character file type indication:
  822. .B f
  823. for regular file,
  824. .B d
  825. for directory,
  826. .B b
  827. for block special,
  828. or
  829. .B c
  830. for character special.
  831. .PP
  832. .ce
  833. .I "Odds and ends\^"
  834. .HP 3
  835. .B eval(s)
  836. .br
  837. The string argument is evaluated as a
  838. .I bs\^
  839. expression.
  840. The function is handy for converting numeric strings to
  841. numeric internal form.
  842. .I Eval\^
  843. can also be used as a crude form of indirection, as in:
  844. .IP "" 10
  845. name = "xyz"
  846. .br
  847. eval("++"\(ul name)
  848. .IP "" 3
  849. which increments the variable
  850. .IR xyz .
  851. In addition,
  852. .I eval\^
  853. preceded by the interrogation operator permits
  854. the user to control
  855. .I bs\^
  856. error conditions.
  857. For example:
  858. .IP "" 10
  859. ?eval("open(\e"\s-1X\s+1\e", \e"\s-1XXX\s+1\e", \e"r\e")")
  860. .IP "" 3
  861. returns the value zero if there is no file named ``\s-1XXX\s+1''
  862. (instead of halting the user's program).
  863. The following executes a
  864. .I goto\^
  865. to the label
  866. .I L\^
  867. (if it exists):
  868. .IP "" 10
  869. label="L"
  870. .br
  871. if !(?eval("goto "\(ul label)) puterr = "no label"
  872. .HP 3
  873. .B "plot(request, args)"
  874. .br
  875. The
  876. .I plot\^
  877. function produces output on devices
  878. recognized by
  879. .IR tplot (1G).
  880. The
  881. .I requests\^
  882. are as follows:
  883. .PP
  884. .RS 7
  885. .I "Call Function\^"
  886. .IP "plot(0, term)" 28
  887. causes
  888. further
  889. .I plot\^
  890. output to be piped into
  891. .IR tplot (1G)
  892. with an argument of
  893. .BI \-T term.
  894. .IP plot(1) 28
  895. ``erases'' the plotter.
  896. .IP "plot(2, string)" 28
  897. labels the current point with
  898. .IR string .
  899. .IP "plot(3, x1, y1, x2, y2)" 28
  900. draws the line between
  901. .RI ( x1 , y1 )
  902. and
  903. .RI ( x2 , y2 ).
  904. .IP "plot(4, x, y, r)" 28
  905. draws a circle with center
  906. .RI ( x , y )
  907. and radius
  908. .IR r .
  909. .IP "plot(5, x1, y1, x2, y2, x3, y3)" 28
  910. draws an arc (counterclockwise)
  911. with center
  912. .RI ( x1 , y1 )
  913. and endpoints
  914. .RI ( x2 , y2 )
  915. and
  916. .RI ( x3 , y3 ).
  917. .IP "plot(6)" 28
  918. is not implemented.
  919. .IP "plot(7, x, y)" 28
  920. makes the current point
  921. .RI ( x , y ).
  922. .IP "plot(8, x, y)" 28
  923. draws a line from the current point to
  924. .RI ( x , y ).
  925. .IP "plot(9, x, y)" 28
  926. draws a point at
  927. .RI ( x , y ).
  928. .IP "plot(10, string)" 28
  929. sets the line mode to
  930. .IR string .
  931. .IP "plot(11, x1, y1, x2, y2)" 28
  932. makes
  933. .RI ( x1 , y1 )
  934. the lower right corner of the plotting area and
  935. .RI ( x2 , y2 )
  936. the upper left corner of the plotting area.
  937. .IP "plot(12, x1, y1, x2, y2)" 28
  938. causes subsequent x (y)
  939. coordinates to be multiplied by
  940. .I x1\^
  941. .RI ( y1 )
  942. and then added to
  943. .I x2\^
  944. .RI ( y2 )
  945. before they are plotted.
  946. The initial scaling is
  947. .BR "plot(12, 1.0, 1.0, 0.0, 0.0)" .
  948. .RE
  949. .IP "" 3
  950. Some requests do not apply to all plotters.
  951. All requests except zero and twelve
  952. are implemented by piping characters to
  953. .IR plot (1G).
  954. See
  955. .IR plot (5)
  956. for more details.
  957. .HP 3
  958. .B last(\|)
  959. .br
  960. in immediate mode,
  961. .I last\^
  962. returns the most recently computed value.
  963. .SH "PROGRAMMING TIPS"
  964. Using
  965. .I bs\^
  966. as a calculator:
  967. .nf
  968. .PP
  969. .RS
  970. $ bs
  971. # distance (inches) light travels in a nanosecond
  972. 186000 \(** 5280 \(** 12 / 1e9
  973. \f311.78496\fP
  974. \&.\|.\|.
  975. .sp 1v
  976. # Compound interest (6% for 5 years on $1,000)
  977. int = .06 / 4
  978. bal = 1000
  979. for i = 1 5\(**4 bal = bal + bal\(**int
  980. bal \- 1000
  981. \f3346.855007\fP
  982. \&.\|.\|.
  983. exit
  984. .RE
  985. .fi
  986. .PP
  987. The outline of a typical
  988. .I bs\^
  989. program:
  990. .nf
  991. .PP
  992. .RS
  993. # Initialize things:
  994. var1 = 1
  995. open("read", "infile", "r")
  996. \&.\|.\|.
  997. # Compute:
  998. while ?(str = read)
  999. \&.\|.\|.
  1000. next
  1001. # Clean up:
  1002. close("read")
  1003. \&.\|.\|.
  1004. # Last statement executed (exit or stop):
  1005. exit
  1006. # Last input line:
  1007. run
  1008. .RE
  1009. .fi
  1010. .PP
  1011. .PP
  1012. Input/Output examples:
  1013. .nf
  1014. .PP
  1015. .RS
  1016. # Copy "oldfile" to "newfile".
  1017. open("read", "oldfile", "r")
  1018. open("write", "newfile", "w")
  1019. \&.\|.\|.
  1020. while ?(write = read)
  1021. \&.\|.\|.
  1022. # Close "read" and "write":
  1023. close("read")
  1024. close("write")
  1025. .sp 1v
  1026. # Pipe between commands.
  1027. open("ls", "!ls \(**", "r")
  1028. open("pr", "!pr \-2 \-h \(fmList\(fm", "w")
  1029. while ?(pr = ls) .\|.\|.
  1030. \&.\|.\|.
  1031. # Be sure to close (wait for) these:
  1032. close("ls")
  1033. close("pr")
  1034. .RE
  1035. .fi
  1036. .SH SEE ALSO
  1037. ed(1), plot(1G), sh(1), access(2), printf(3S), stdio(3S),
  1038. Section\ 3 of this volume for further description of the
  1039. mathematical functions
  1040. (pow(3M) is used for exponentiation),
  1041. plot(5).
  1042. .I Bs\^
  1043. uses the Standard Input/Output package.
  1044. .SH BUGS
  1045. There are built-in design limits.
  1046. .I Bs\^
  1047. source programs are restricted to fewer than 250 lines
  1048. and fewer than 250 variables (the
  1049. .I name\^
  1050. of an array counts as a variable, as does each dimension
  1051. and each referenced element).
  1052. .PP
  1053. All names
  1054. (labels,
  1055. variables,
  1056. functions,
  1057. statement keywords)
  1058. are internally truncated to six characters.
  1059.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement