03-rlisp.lpt 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. PSL Manual 7 February 1983 RLISP
  2. section 3.0 page 3.1
  3. CHAPTER 3 CHAPTER 3 CHAPTER 3
  4. RLISP SYNTAX RLISP SYNTAX RLISP SYNTAX
  5. 3.1. Motivation for RLISP Interface to PSL . . . . . . . 3.1
  6. 3.2. An Introduction to RLISP . . . . . . . . . . . 3.2
  7. 3.2.1. LISP equivalents of some RLISP constructs . . . 3.2
  8. 3.3. An Overview of RLISP and LISP Syntax Correspondence . . 3.3
  9. 3.3.1. Function Call Syntax in RLISP and LISP . . . . 3.4
  10. ... 3.3.2. RLISP Infix Operators and Associated LISP Functions....3.4
  11. 3.3.3. Differences between Parse and Read. . . . . . 3.6
  12. 3.3.4. Procedure Definition . . . . . . . . . . 3.6
  13. 3.3.5. Compound Statement Grouping . . . . . . . . 3.7
  14. 3.3.6. Blocks with Local Variables . . . . . . . . 3.7
  15. 3.3.7. The If Then Else Statement . . . . . . . . 3.8
  16. 3.4. Looping Statements . . . . . . . . . . . . . 3.8
  17. 3.4.1. While Loop. . . . . . . . . . . . . . 3.8
  18. 3.4.2. Repeat Loop . . . . . . . . . . . . . 3.8
  19. 3.4.3. For Each Loop. . . . . . . . . . . . . 3.9
  20. 3.4.4. For Loop . . . . . . . . . . . . . . 3.9
  21. 3.4.5. Loop Examples. . . . . . . . . . . . . 3.9
  22. 3.5. Switch Syntax . . . . . . . . . . . . . . . 3.10
  23. 3.6. RLISP I/O Syntax . . . . . . . . . . . . . . 3.10
  24. 3.7. Transcript of a Short Session with RLISP . . . . . . 3.11
  25. 3.1. Motivation for RLISP Interface to PSL 3.1. Motivation for RLISP Interface to PSL 3.1. Motivation for RLISP Interface to PSL
  26. Most of the PSL users at Utah prefer to write LISP code using an
  27. ALGOL-like (or PASCAL-like) preprocessor language, RLISP, because of its
  28. similarity to the heavily used PASCAL and C languages. RLISP was developed
  29. as part of the REDUCE Computer Algebra project [Hearn 73], and is the
  30. ALGOL-like user language as well as the implementation language. RLISP
  31. provides a number of syntactic niceties which we find convenient, such as
  32. If-Then-Else If-Then-Else vector subscripts, case statement, If-Then-Else, etc. We usually do not
  33. distinguish LISP from RLISP, and can mechanically translate from one to the
  34. other in either direction using a parser and pretty-printer written in PSL.
  35. That is, RLISP is a convenience, but it is not necessary to use RLISP
  36. syntax rather than LISP. A complete BNF-like definition of RLISP and its
  37. translation to LISP using the MINI system is given in Section 22.4. Also
  38. discussed in Chapter 22 is an extensible table driven parser which is used
  39. for the current RLISP parser. There we give explicit tables which define
  40. RLISP syntax.
  41. In this chapter we provide enough of an introduction to make the examples
  42. and sources readable, and to assist the user in writing RLISP code. RLISP 7 February 1983 PSL Manual
  43. page 3.2 section 3.2
  44. 3.2. An Introduction to RLISP 3.2. An Introduction to RLISP 3.2. An Introduction to RLISP
  45. An RLISP program consists of a set of functional commands which are
  46. evaluated sequentially. RLISP expressions are built up from declarations,
  47. statements and expressions. Such entities are composed of sequences of
  48. numbers, variables, operators, strings, reserved words and delimiters (such
  49. as commas and parentheses), which in turn are sequences of characters. The
  50. evaluation proceeds by a parser first converting the ALGOL-like RLISP
  51. source language into LISP S-expressions, and evaluating and printing the
  52. Parse-Eval-Print Parse-Eval-Print result. The basic cycle is thus Parse-Eval-Print, although the specific
  53. functions, and additional processing, are under the control of a variety of
  54. switches, described in appropriate sections.
  55. 3.2.1. LISP equivalents of some RLISP constructs 3.2.1. LISP equivalents of some RLISP constructs 3.2.1. LISP equivalents of some RLISP constructs
  56. The following gives a few examples of RLISP statements and functions and
  57. their corresponding LISP forms. To see the exact LISP equivalent of RLISP
  58. code, set the switch !*PECHO to T [On PECHO; in RLISP, (On PECHO) in LISP].
  59. Assignment statements in RLISP and LISP:
  60. X := 1; (setq x 1)
  61. A procedure to take a factorial, in RLISP:
  62. LISP PROCEDURE FACTORIAL N;
  63. IF N <= 1 THEN 1
  64. ELSE N * FACTORIAL (N-1);
  65. in LISP:
  66. (de factorial (n)
  67. (cond
  68. ((leq n 1) 1)
  69. (T
  70. (times n (factorial (difference n 1))))))
  71. Take the Factorial of 5 in RLISP and in LISP:
  72. FACTORIAL 5; (factorial 5)
  73. Build a list X as a series of "Cons"es in RLISP:
  74. X := 'A . 'B . 'C . NIL;
  75. in LISP:
  76. (setq x (cons 'a (cons 'b (cons 'c nil)))) PSL Manual 7 February 1983 RLISP
  77. section 3.3 page 3.3
  78. 3.3. An Overview of RLISP and LISP Syntax Correspondence 3.3. An Overview of RLISP and LISP Syntax Correspondence 3.3. An Overview of RLISP and LISP Syntax Correspondence
  79. The RLISP parser converts RLISP expressions, typed in at the terminal or
  80. read from a file, into directly executable LISP expressions. For
  81. convenience in the following examples, the "==>" arrow is used to indicate
  82. the LISP actually produced from the input RLISP. To see the LISP
  83. equivalents of RLISP code on the machine, set the switch !*PECHO to T [On
  84. Pecho; in RLISP, (On Pecho) in LISP]. As far as possible, upper and lower
  85. cases are used as follows:
  86. a. Upper case tokens and punctuation represent items which must
  87. appear as is in the source RLISP or output LISP.
  88. b. Lower case tokens represent other legal RLISP constructs or
  89. corresponding LISP translations. We typically use "e" for
  90. ____ expression, "s" for statement, and "v" for variable; "-list" is
  91. tacked on for lists of these objects.
  92. For example, the following rule describes the syntax of assignment in
  93. RLISP:
  94. VAR := number;
  95. ==> (SETQ VAR number)
  96. Another example:
  97. __________ ______ _ ______ _ IF expression THEN action_1 ELSE action_2
  98. __________ ______ _ ______ _ ==> (COND ((expression action_1) (T action_2)))
  99. In RLISP, a function is recognized as an "ftype" (one of the tokens EXPR,
  100. FEXPR, etc. or none) followed by the keyword PROCEDURE, followed by an "id"
  101. (the name of the function), followed by a "v-list" (the formal parameter
  102. names) enclosed in parentheses. A semicolon terminates the title line.
  103. The body of the function is a <statement> followed by a semicolon. In LISP
  104. syntax, a function is defined using one of the "Dx" functions, i.e. one of
  105. De Df Dm Dn De Df Dm Dn De, Df, Dm, or Dn, depending on "ftype". For example:
  106. EXPR PROCEDURE NULL(X);
  107. EQ(X, NIL);
  108. ==> (DE NULL (X) (EQ X NIL))
  109. 3.3.1. Function Call Syntax in RLISP and LISP 3.3.1. Function Call Syntax in RLISP and LISP 3.3.1. Function Call Syntax in RLISP and LISP
  110. A function call with N arguments (called an N-ary function) is most
  111. commonly represented as "FN(X1, X2, ... Xn)" in RLISP and as
  112. "(FN X1 X2 ... Xn)" in LISP. Commas are required to separate the arguments
  113. in RLISP but not in LISP. A zero argument function call is "FN()" in RLISP
  114. and "(FN)" in LISP. An unary function call is "FN(a)" or "FN a" in RLISP
  115. and "(FN a)" in LISP; i.e. the parentheses may be omitted around the single RLISP 7 February 1983 PSL Manual
  116. page 3.4 section 3.3
  117. argument of any unary function in RLISP.
  118. 3.3.2. RLISP Infix Operators and Associated LISP Functions 3.3.2. RLISP Infix Operators and Associated LISP Functions 3.3.2. RLISP Infix Operators and Associated LISP Functions
  119. Many important PSL binary functions, particularly those for arithmetic
  120. operations, have associated infix operators, consisting of one or two
  121. special characters. The conversion of an RLISP expression "A op B" to its
  122. corresponding LISP form is easy: "(fn A B)", in which "fn" is the
  123. associated function. The function name fn may also be used as an ordinary
  124. RLISP function call, "fn(A, B)".
  125. Refer to Chapter 22 for details on how the association of "op" and "fn"
  126. is installed.
  127. Parentheses may be used to specify the order of combination.
  128. "((A op_a B) op_b C)" in RLISP becomes "(fn_b (fn_a A B) C)" in LISP.
  129. If two or more different operators appear in a sequence, such as
  130. "A op_a B op_b C", grouping (similar to the insertion of parentheses) is
  131. done based on relative precedence of the operators, with the highest
  132. precedence operator getting the first argument pair: "(A op_a B) op_b C"
  133. if Precedence(op_a) >= Precedence(op_b); "A op_a (B op_b C)" if
  134. Precedence(op_a) < Precedence(op_b).
  135. If two or more of the same operator appear in a sequence, such as
  136. "A op B op C", grouping is normally to the left (Left Associative; i.e.
  137. "(fn (fn A B) C)"), unless the operator is explicitly Right Associative
  138. Cons SetQ Cons SetQ (such as . for Cons and := for SetQ; i.e. "(fn A (fn B C))").
  139. The operators + and * are N-ary; i.e. "A nop B nop C nop B" parses into
  140. "(nfn A B C D)" rather than into "(nfn (nfn (nfn A B) C) D)".
  141. The current binary operator-function correspondence is as follows: PSL Manual 7 February 1983 RLISP
  142. section 3.3 page 3.5
  143. ________ ________ __________ Operator Function Precedence
  144. Cons Cons . Cons 23 Right Associative
  145. Expt Expt ** Expt 23
  146. Quotient Quotient / Quotient 19
  147. Times Times * Times 19 N-ary
  148. Difference Difference - Difference 17
  149. Plus Plus + Plus 17 N-ary
  150. Eq Eq Eq Eq Eq Eq 15
  151. Equal Equal = Equal 15
  152. Geq Geq >= Geq 15
  153. GreaterP GreaterP > GreaterP 15
  154. Leq Leq <= Leq 15
  155. LessP LessP < LessP 15
  156. Member Member Member Member Member Member 15
  157. Memq MemQ Memq MemQ Memq MemQ 15
  158. Neq Neq Neq Neq Neq Neq 15
  159. And And And And And And 11 N-ary
  160. Or Or Or Or Or Or 9 N-ary
  161. SetQ SetQ := SetQ 7 Right Associative
  162. Note: There are other INFIX operators, mostly used as key-words within
  163. Then Else If Do Then Else If Do other syntactic constructs (such as Then or Else in the If-..., or Do in
  164. While While the While-..., etc.). They have lower precedences than those given above.
  165. These key-words include: the parentheses "()", the brackets "[]", the colon
  166. ":", the comma ",", the semi-colon ";", the dollar sign "$", and the ids:
  167. Collect Conc Do Else End Of Procedure Product Step Such Sum Collect Conc Do Else End Of Procedure Product Step Such Sum Collect, Conc, Do, Else, End, Of, Procedure, Product, Step, Such, Sum,
  168. Then To Until Then To Until Then, To, and Until.
  169. As pointed out above, an unary function FN can be used with or without
  170. parentheses: FN(a); or FN a;. In the latter case, FN is assumed to behave
  171. as a prefix operator with highest precedence (99) so that "FOO 1 ** 2"
  172. parses as "FOO(1) ** 2;". The operators +, -, and / can also be used as
  173. Plus Minus Recip Plus Minus Recip unary prefix operators, mapping to Plus, Minus and Recip, respectively,
  174. with precedence 26. Certain other unary operators (RLISP key-words) have
  175. low precedences or explicit special purpose parsing functions. These
  176. include: BEGIN, CASE, CONT, EXIT, FOR, FOREACH, GO, GOTO, IF, IN, LAMBDA,
  177. NOOP, NOT, OFF, ON, OUT, PAUSE, QUIT, RECLAIM, REPEAT, RETRY, RETURN,
  178. SCALAR, SHOWTIME, SHUT, WHILE and WRITE. RLISP 7 February 1983 PSL Manual
  179. page 3.6 section 3.3
  180. 3.3.3. Differences between Parse and Read 3.3.3. Differences between Parse and Read 3.3.3. Differences between Parse and Read
  181. A single character can be interpreted in different ways depending on
  182. context and on whether it is used in a LISP or in an RLISP expression.
  183. Such differences are not immediately apparent to a novice user of RLISP,
  184. but an example is given below.
  185. The RLISP infix operator "." may appear in an RLISP expression and is
  186. Parse Cons Parse Cons converted by the Parse function to the LISP function Cons, as in the
  187. expression x := 'y . 'z;. A dot may also occur in a quoted expression in
  188. Read Read RLISP mode, in which case it is interpreted by Read as part of the notation
  189. Read Read for pairs, as in (SETQ X '(Y . Z)). Note that Read called from LISP or
  190. from RLISP uses slightly different scan tables (see Chapter 12). In order
  191. Cons Cons Cons Cons to use the function Cons in LISP one must use the word Cons in a prefix
  192. position.
  193. 3.3.4. Procedure Definition 3.3.4. Procedure Definition 3.3.4. Procedure Definition
  194. Procedure definitions in PSL (both RLISP and LISP) are not nested as in
  195. ALGOL; all appear at the same top level as in C. The basic function for
  196. PutD PutD defining procedures is PutD (see Chapter 10). Special syntactic forms are
  197. provided in both RLISP and LISP:
  198. mode ftype PROCEDURE name(v_1,...,v_n); body;
  199. ==> (Dx name (v_1 ... v_N) body)
  200. Examples:
  201. PROCEDURE ADD1 N;
  202. N+1;
  203. ==> (DE ADD1 (N) (PLUS N 1))
  204. MACRO PROCEDURE FOO X;
  205. LIST('FUM, CDR X, CDR X);
  206. ==> (DM FOO (X) (LIST 'FUM (CDR X) (CDR X))
  207. The value returned by the procedure is the value of the body; no
  208. assignment to the function name (as in ALGOL or PASCAL) is needed.
  209. In the general definition given above "mode" is usually optional; it can
  210. be LISP or SYMBOLIC (which mean the same thing) or SYSLISP [only of
  211. ____ _____ ____ _____ ____ _____ expr fexpr expr fexpr importance if SYSLISP and LISP are inter-mixed]. "Ftype" is expr, fexpr,
  212. _____ _____ ______ _____ _____ ______ _____ _____ ______ macro nexpr smacro macro nexpr smacro macro, nexpr, or smacro (or can be omitted, in which case it defaults to
  213. ____ ____ ____ expr expr expr). Name(v_1,...,v_N) is any legal form of call, including infix. Dx
  214. ____ _____ _____ _____ ____ _____ _____ _____ ____ _____ _____ _____ De expr Df fexpr Dm macro Dn nexpr Ds De expr Df fexpr Dm macro Dn nexpr Ds is De for expr, Df for fexpr, Dm for macro, Dn for nexpr, and Ds for
  215. ______ ______ ______ smacro smacro smacro.
  216. ______ _____ ______ _____ ______ _____ smacro macro smacro macro The smacro is a simple substitution macro. PSL Manual 7 February 1983 RLISP
  217. section 3.3 page 3.7
  218. SMACRO PROCEDURE ELEMENT X; % Defines ELEMENT(x) to substitute
  219. CAR CDR (X); % as Car Cdr x;
  220. ==> (DS ELEMENT (X) (CAR (CDR X)))
  221. In code which calls ELEMENT after it was defined, ELEMENT(foo); behaves
  222. exactly like CAR CDR foo;.
  223. 3.3.5. Compound Statement Grouping 3.3.5. Compound Statement Grouping 3.3.5. Compound Statement Grouping
  224. A group of RLISP expressions may be used in any position in which a
  225. single expression is expected by enclosing the group of expressions in
  226. double angle brackets, << and >>, and separating them by the ; delimiter.
  227. The RLISP <<A; B; C; ... Z>> becomes (PROGN A B C ... Z) in LISP. The
  228. value of the group is the value of the last expression, Z.
  229. Example:
  230. X:=<<PRINT X; X+1>>; % prints old X then increments X
  231. ==> (SETQ X (PROGN (PRINT X) (PLUS X 1)))
  232. 3.3.6. Blocks with Local Variables 3.3.6. Blocks with Local Variables 3.3.6. Blocks with Local Variables
  233. A more powerful construct, sometimes used for the same purpose as the
  234. Begin-End Prog Begin-End Prog << >> group, is the Begin-End block in RLISP or Prog in LISP. This
  235. construct also permits the allocation of 0 or more local variables,
  236. initialized to NIL. The normal value of a block is NIL, but it may be
  237. Return Return exited at a number of points, using the Return statement, and each can
  238. GoTo GoTo return a different value. The block also permits labels and a GoTo
  239. construct.
  240. Example:
  241. BEGIN SCALAR X,Y; % SCALAR declares locals X and Y
  242. X:='(1 2 3);
  243. L1: IF NULL X THEN RETURN Y;
  244. Y:=CAR X;
  245. X:=CDR X;
  246. GOTO L1;
  247. END;
  248. ==> (PROG (X Y)
  249. (SETQ X '(1 2 3))
  250. L1 (COND ((NULL X) (RETURN Y)))
  251. (SETQ Y (CAR X))
  252. (SETQ X (CDR X))
  253. (GO L1)) RLISP 7 February 1983 PSL Manual
  254. page 3.8 section 3.3
  255. 3.3.7. The If Then Else Statement 3.3.7. The If Then Else Statement 3.3.7. The If Then Else Statement
  256. If Cond If Cond RLISP provides an If statement, which maps into the LISP Cond statement.
  257. See Chapter 9 for full details. For example:
  258. IF e THEN s;
  259. ==> (COND (e s))
  260. IF e THEN s1 ELSE s2;
  261. ==> (COND (e s1) (T s2))
  262. IF e1 THEN s1
  263. ELSE IF e2 THEN s2
  264. ELSE s3;
  265. ==> (COND (e1 s1)
  266. (e2 s2)
  267. (T s3))
  268. 3.4. Looping Statements 3.4. Looping Statements 3.4. Looping Statements
  269. While Repeat For For Each While Repeat For For Each RLISP provides While, Repeat, For and For Each loops. These are
  270. discussed in greater detail in Chapter 9. Some examples follow:
  271. 3.4.1. While Loop 3.4.1. While Loop 3.4.1. While Loop
  272. WHILE e DO s; % As long as e NEQ NIL, do s
  273. ==> (WHILE e s)
  274. 3.4.2. Repeat Loop 3.4.2. Repeat Loop 3.4.2. Repeat Loop
  275. REPEAT s UNTIL e; % repeat doing s until "e" is not NIL
  276. ==> (REPEAT s e)
  277. 3.4.3. For Each Loop 3.4.3. For Each Loop 3.4.3. For Each Loop
  278. For Each For Each The For Each loops provide various mapping options, processing elements
  279. of a list in some way and sometimes constructing a new list.
  280. FOR EACH x IN y DO s; % y is a list, x traverses list bound to eac
  281. % element in turn.
  282. ==> (FOREACH x IN y DO s)
  283. FOR EACH x ON y DO s; % y is a list, x traverses list Bound to suc
  284. % Cdr's of y.
  285. ==> (FOREACH x ON y DO s)
  286. Other options can return modified lists, etc. See chapter 9. PSL Manual 7 February 1983 RLISP
  287. section 3.4 page 3.9
  288. 3.4.4. For Loop 3.4.4. For Loop 3.4.4. For Loop
  289. For For The For loop permits an iterative form with a compacted control variable.
  290. Other options can compute sums and products.
  291. FOR i := a:b DO s; % step i successively from a to b in
  292. % steps of 1.
  293. ==> (FOR (FROM I a b 1) DO s)
  294. FOR i := a STEP b UNTIL c DO s; % More general stepping
  295. ==> (FOR (FROM I a c b) DO s)
  296. 3.4.5. Loop Examples 3.4.5. Loop Examples 3.4.5. Loop Examples
  297. LISP PROCEDURE count lst; % Count elements in lst
  298. BEGIN SCALAR k;
  299. k:=0;
  300. WHILE PAIRP lst DO <<k:=k+1; lst:=CDR lst>>;
  301. RETURN k;
  302. END;
  303. ==> (DE COUNT (LST)
  304. (PROG (K)
  305. (SETQ K 0)
  306. (WHILE (PAIRP LST)
  307. (PROGN
  308. (SETQ K (PLUS K 1))
  309. (SETQ LST (CDR LST))))
  310. (RETURN K)))
  311. or
  312. LISP PROCEDURE CountNil lst; % Count NIL elements in lst
  313. BEGIN SCALAR k;
  314. k:=0;
  315. FOR EACH x IN lst DO If Null x then k:=k+1;
  316. RETURN k;
  317. END;
  318. ==> (DE COUNTNIL (LST)
  319. (PROG (K)
  320. (SETQ K 0)
  321. (FOREACH X IN LST DO (COND
  322. ((NULL X) (SETQ K (PLUS K 1)))))
  323. (RETURN K))) RLISP 7 February 1983 PSL Manual
  324. page 3.10 section 3.5
  325. 3.5. Switch Syntax 3.5. Switch Syntax 3.5. Switch Syntax
  326. Two declarations are offered to the user for turning on or off a variety
  327. of switches in the system. Switches are global variables that have only
  328. the values T or NIL. By convention, the switch name is XXXX, but the
  329. associated global variable is !*XXXX. The RLISP commands ON and OFF take a
  330. list of switch names as argument and turn them on and off respectively
  331. (i.e. set the corresponding !* variable to T or NIL).
  332. Example:
  333. ON ECHO, FEE, FUM; % Sets !*ECHO, !*FEE, !*FUM to T;
  334. ==> (ON ECHO FEE FUM)
  335. OFF INT,SYSLISP; % Sets !*INT and !*SYSLISP to NIL
  336. ==> (OFF INT SYSLISP)
  337. [??? Mention SIMPFG property ???] [??? Mention SIMPFG property ???] [??? Mention SIMPFG property ???]
  338. See Section 6.7 for a complete set of switches and global variables.
  339. 3.6. RLISP I/O Syntax 3.6. RLISP I/O Syntax 3.6. RLISP I/O Syntax
  340. RLISP provides special commands to OPEN and SELECT files for input or for
  341. output and to CLOSE files. File names must be enclosed in "....". Files
  342. In In with the extension ".sl" or ".lsp" are read by In in LISP mode rather than
  343. RLISP mode.
  344. IN "<griss.stuff>fff.red","ggg.lsp"; % First reads fff.red
  345. % Then reads ggg.lsp
  346. OUT "keep-it.output"; % Diverts output to "keep-it.ou
  347. OUT "fum"; % now to fum, keeping the other
  348. SHUT "fum"; % to close fum and flush the bu
  349. File names can use the full system conventions. See Chapter 12 for more
  350. detail on I/O.
  351. 3.7. Transcript of a Short Session with RLISP 3.7. Transcript of a Short Session with RLISP 3.7. Transcript of a Short Session with RLISP
  352. The following is a transcript of RLISP running on the DEC-20. PSL Manual 7 February 1983 RLISP
  353. section 3.7 page 3.11
  354. @psl:rlisp
  355. PSL 3.1 Rlisp, 27-Oct-82
  356. [1] % Notice the numbered prompt.
  357. [1] % Comments begin with "%" and do not change the prompt number.
  358. [1] Z := '(1 2 3); % Make an assignment for Z.
  359. (1 2 3)
  360. [2] Cdr Z; % Notice the change in the prompt nu
  361. (2 3)
  362. [3] Lisp Procedure Count L; % "Count" counts the number of eleme
  363. [3] If Null L Then 0 % in a list L.
  364. [3] Else 1 + Count Cdr L;
  365. COUNT
  366. [4] Count Z; % Try out "Count" on Z.
  367. 3
  368. [5] Tr Count; % Trace the recursive execution of "Count".
  369. (COUNT)
  370. [6] % A call on "Count" now shows the value of
  371. [6] % "Count" and of its argument each time it
  372. [6] Count Z; % is called.
  373. COUNT being entered
  374. L: (1 2 3)
  375. COUNT (level 2) being entered
  376. L: (2 3)
  377. COUNT (level 3) being entered
  378. L: (3)
  379. COUNT (level 4) being entered
  380. L: NIL
  381. COUNT (level 4) = 0
  382. COUNT (level 3) = 1
  383. COUNT (level 2) = 2
  384. COUNT = 3
  385. 3
  386. [7] Lisp Procedure Factorial X;
  387. [7] If X <= 1 Then 1
  388. [7] Else X * Factorial (X-1);
  389. FACTORIAL
  390. [8] Tr Factorial;
  391. (FACTORIAL)
  392. [9] Factorial 4; % Trace execution of "Factorial".
  393. FACTORIAL being entered
  394. X: 4
  395. FACTORIAL (level 2) being entered
  396. X: 3
  397. FACTORIAL (level 3) being entered
  398. X: 2
  399. FACTORIAL (level 4) being entered
  400. X: 1
  401. FACTORIAL (level 4) = 1
  402. FACTORIAL (level 3) = 2
  403. FACTORIAL (level 2) = 6
  404. FACTORIAL = 24
  405. 24 RLISP 7 February 1983 PSL Manual
  406. page 3.12 section 3.7
  407. [10] UnTr Count,Factorial;
  408. NIL
  409. [11] Count 'A;
  410. ***** An attempt was made to do CDR on `A', which is not a pair
  411. Break loop
  412. 1 lisp break> ?
  413. BREAK():{Error,return-value}
  414. ----------------------------
  415. This is a Read-Eval-Print loop, similar to the top level loop, excep
  416. that the following IDs at the top level cause functions to be called
  417. rather than being evaluated:
  418. ? Print this message, listing active Break IDs
  419. T Print stack backtrace
  420. Q Exit break loop back to ErrorSet
  421. C Return last value to the ContinuableError call
  422. R Reevaluate ErrorForm!* and return
  423. M Display ErrorForm!* as the "message"
  424. E Invoke a simple structure editor on ErrorForm!*
  425. (For more information do Help Editor.)
  426. I Show a trace of any interpreted functions
  427. See the manual for details on the Backtrace, and how ErrorForm!* is
  428. set. The Break Loop attempts to use the same TopLoopRead!* etc, as
  429. the calling top loop, just expanding the PromptString!*.
  430. NIL
  431. 2 lisp break> % Get a Trace-Back of the
  432. 2 lisp break> I % interpreted functions.
  433. Backtrace, including interpreter functions, from top of stack:
  434. LIST2 CDR COUNT PLUS2 PLUS COND COUNT
  435. NIL
  436. 3 lisp break> Q % To exit the Break Loop.
  437. [12] % Load in a file, showing the file
  438. [12] In "small-file.red"; % and its execution.
  439. X := 'A . 'B . NIL;(A B) % Construct a list with "." for Cons.
  440. Count X;2 % Call "Count" on X.
  441. Reverse X;(B A) % Call "Reverse" on X.
  442. NIL
  443. [13] % This leaves RLISP and enters
  444. [13] End; % LISP mode.
  445. Entering LISP...
  446. PSL, 27-Oct-82
  447. 6 lisp> (SETQ X 3) % A LISP assignment statement.
  448. 3
  449. 7 lisp> (FACTORIAL 3) % Call "Factorial" on 3.
  450. 6
  451. 8 lisp> (BEGINRLISP) % This function returns us to RLISP.
  452. Entering RLISP...
  453. [14] Quit; % To exit call "Quit".
  454. @continue PSL Manual 7 February 1983 RLISP
  455. section 3.7 page 3.13
  456. "Continued"
  457. [15] X; % Notice the prompt number.
  458. 3
  459. [16] ^C % One can also quit with <Ctrl-C>.
  460. @start % Alternative immediate re-entry.
  461. [17] Quit;
  462. @