joy.texi 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. \input texinfo
  2. @c -*-texinfo-*-
  3. @c %**start of header
  4. @setfilename joy.info
  5. @documentencoding UTF-8
  6. @settitle Guile Joy Reference Manual
  7. @c %**end of header
  8. @include version.texi
  9. @copying
  10. Copyright @copyright{} 2016, 2017 Eric Bavier
  11. Permission is granted to copy, distribute and/or modify this document
  12. under the terms of the GNU Free Documentation License, Version 1.3 or
  13. any later version published by the Free Software Foundation; with no
  14. Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
  15. copy of the license is included in the section entitled ``GNU Free
  16. Documentation License''.
  17. @end copying
  18. @dircategory Software development
  19. @direntry
  20. * joy: (joy). Compiler for the Joy language.
  21. @end direntry
  22. @titlepage
  23. @title Joy Reference Manual
  24. @subtitle A compiler for the Joy programming language
  25. @author Eric Bavier
  26. @page
  27. @vskip 0pt plus 1fill
  28. Edition @value{EDITION} @*
  29. @value{UPDATED} @*
  30. @insertcopying
  31. @end titlepage
  32. @contents
  33. @c **********************************************************************
  34. @node Top
  35. @top Joy
  36. This document describes Joy version @value{VERSION}, an implementation
  37. of the Joy programming language.
  38. @menu
  39. * Introduction:: What is Joy?
  40. * Installation:: Installing Joy.
  41. * Invoking joy:: Running the compiler.
  42. * Programming in Joy:: The Joy of programming.
  43. * Interactive Joy:: Programming interactively with Joy.
  44. * API Reference:: Joy batteries included.
  45. * GNU Free Documentation License:: The license of this manual.
  46. @end menu
  47. @c **********************************************************************
  48. @node Introduction
  49. @chapter Introduction
  50. Joy is an implementation of the purely functional, concatenative
  51. programming language originally invented by Manfred Thun. It is
  52. implemented using Guile's multi-language support. This implementation
  53. strays a bit from the reference implementation written in C but is
  54. mostly compatible, except for the notable lack of support for ``sets''.
  55. @node Installation
  56. @chapter Installation
  57. Joy is available for download from its website at
  58. @url{http://nahne.info/joy}. Building Joy from source uses the same
  59. build procedure as that for GNU software. See the files @file{README}
  60. and @file{INSTALL} in the source tree for additional details. It
  61. requires @url{http://gnu.org/software/guile/, GNU Guile}.
  62. After building Joy successfully, it is a good idea to run the test
  63. suite. Reporting any failures is a good way to help improve the
  64. software. To run the test suite, type:
  65. @example
  66. make check
  67. @end example
  68. Test cases can be run in parallel using the @code{-j} option of
  69. GNU@tie{}make.
  70. If any failures occur, please email @email{bavier@@member.fsf.org} and
  71. attach the @file{testsuite.log} file.
  72. @c **********************************************************************
  73. @node Invoking joy
  74. @chapter Invoking joy
  75. @c **********************************************************************
  76. @node Programming in Joy
  77. @chapter Programming in Joy
  78. In Joy, everything is an operator that takes a stack as an argument
  79. and returns a (possibly modified) stack. Operators may be further
  80. classified by the way they manipulate their input stack to produce
  81. their output. E.g. some operators simply push something to the top of
  82. the stack; some remove one or more items; some remove one or more
  83. items and push another; and others, typically called ``combinators'',
  84. cause some stack items to executed in some way.
  85. Joy is called a ``concatenative'' language because in a purely
  86. functional sense, the concatenation of two Joy programs can be
  87. understood as the composition of their equivalent functions.
  88. @c **********************************************************************
  89. @node Interactive Joy
  90. @chapter Interactive Joy
  91. Editing text files then running them with @code{joy} is useful, and
  92. the programs are then committed to a file, but sometimes it can be
  93. helpful during development to be able to experiment quickly with some
  94. code before you know what works yet. Joy supports ``interactive''
  95. development by providing a @acronym{REPL, read-eval-print-loop}. If
  96. @code{joy} is invoked with no arguments, then it enteres a REPL.
  97. @example
  98. > joy
  99. @dots{}
  100. joy-repl@@(guile-user)> 1 2 10
  101. [10 2 1]
  102. joy-repl@@(guile-user)> swap - +
  103. [9]
  104. joy-repl@@(guile-user)> "base" include
  105. [9]
  106. joy-repl@@(guile-user)> 7 [8 *]
  107. [[8 *] 7 9]
  108. joy-repl@@(guile-user)> DEFINE foo == dip +
  109. [[8 *] 7 9]
  110. joy-repl@@(guile-user)> foo
  111. [79]
  112. joy-repl@@(guile-user)> newstack
  113. []
  114. @end example
  115. One may experiment this way before committing a working sequence to
  116. their program. After each expression is evaluated the current stack
  117. is displayed, so the effect that expression had on the stack can be
  118. seen.
  119. The Joy REPL is implemented as a Guile language @xref{Other
  120. Languages,,Support for Other Languages,guile}. This means Joy's REPL
  121. can be accessed through Guile, albeit without the pretty-printing:
  122. @example
  123. > guile
  124. @dots{}
  125. scheme@@(guile-user)> (display "Hello Guile!")(newline)
  126. Hello Guile!
  127. scheme@@(guile-user)> ,L joy-repl
  128. Happy hacking with Joy (REPL)! To switch back type `,L scheme'.
  129. joy-repl@@(guile-user)> 2 3 dup +
  130. $1 = (6 2)
  131. joy-repl@@(guile-user)> ,L scheme
  132. Happy hacking with Scheme! To switch back type `,L joy-repl'.
  133. scheme@@(guile-user)> (length $1)
  134. $2 = 3
  135. scheme@@(guile-user)> (car $1)
  136. $3 = 6
  137. @end example
  138. The Joy language itself can also be used in Guile. But because every
  139. Joy expression is an operator (i.e. a Guile procedure) that takes a
  140. stack as input and produces another stack as output, one must apply
  141. manually, from Scheme, every expression/operator entered in the Joy
  142. language to a stack argument. Despite the overhead, this might still
  143. be useful in some circumstances.
  144. @example
  145. > guile
  146. @dots{}
  147. scheme@@(guile-user)> ,L joy
  148. Happy hacking with Joy! To switch back type `,L scheme'.
  149. joy@@(guile-user)> dup + +
  150. $1 = #<procedure 86ba230 S>
  151. joy@@(guile-user)> ,L scheme
  152. Happy hacking with Scheme! To switch back type `,L joy'.
  153. scheme@@(guile-user)> (apply $1 '(6 10))
  154. $2 = (22)
  155. scheme@@(guile-user)> (apply $1 '(5 3))
  156. $3 = (13)
  157. scheme@@(guile-user)> (apply $1 '(1 10 19))
  158. $4 = (11 19)
  159. @end example
  160. @c **********************************************************************
  161. @node API Reference
  162. @chapter API Reference
  163. We discuss here the various Joy operators@footnote{The term
  164. ``operator'' is used consistently here to refer to any term that
  165. affects the stack when executed. Indeed, one may consider every Joy
  166. term to be an operator, even literals, e.g.@: @code{2}, because it
  167. affects the stack by pushing itself onto the top of the stack. We do
  168. not distinguish in our discussion ``combinators'' from ``operators''
  169. as the literature does.} provided for general use. Operator
  170. signatures are denoted by the result they have on the top of stack,
  171. where the rightmost element is the top element. Any element of the
  172. stack not included in an operator signature is untouched.
  173. Do not be confused by the ordering of the operator name and the
  174. operator signature in the following. Remember that Joy uses postfix
  175. notation, so in practice an operator defined like
  176. @deffn {Example Operator} frob [B] [A] @result{} [C]
  177. This operator frobs @code{A} and @code{B} into @code{C}.
  178. @end deffn
  179. @noindent
  180. would be used in a joy program like
  181. @example
  182. [B] [A] frob
  183. @result{} [C]
  184. @end example
  185. @menu
  186. * Primitives:: Essential operators.
  187. * Standard Library:: Generally useful operators.
  188. * Lisp Aliases::
  189. * Forth Aliases::
  190. @end menu
  191. @node Primitives
  192. @section Primitives
  193. This section summarizes the primitive operators that will be used
  194. almost everywhere. These primitives are written directly in Guile for
  195. performance, and all other operators are written in terms of them.
  196. @deffn {Joy Operator} dup A @result{} A A
  197. This operator places a copy of the top element onto the stack.
  198. @end deffn
  199. @deffn {Joy Operator} pop A @result{}
  200. This operator removes the top element of the stack.
  201. @end deffn
  202. @deffn {Joy Operator} swap B A @result{} A B
  203. This operator swaps the position of the top two elements.
  204. @end deffn
  205. @deffn {Joy Operator} cons B [A @dots{}] @result{} [B A @dots{}]
  206. This operator inserts @var{B} into the front of a quotation.
  207. @end deffn
  208. @deffn {Joy Operator} uncons [B A @dots{}] @result{} B [A @dots{}]
  209. This operator removes @var{B} from the front of a quotation and places
  210. it, followed by the rest of the quotation, back on the stack.
  211. @end deffn
  212. @deffn {Joy Operator} choice C B A @result{} D
  213. This operator leaves @var{D} on the top of the stack, where @var{D} is
  214. @var{B} if @var{C} is @var{true}, otherwise @var{A}.
  215. @end deffn
  216. @deffn {Joy Operator} stack @result{} [S]
  217. This operator pushes the entire current stack as a quotation.
  218. @end deffn
  219. @deffn {Joy Operator} unstack @dots{} [S0 S1 @dots{} SN] @result{} S0 S1 @dots{} SN
  220. This operator replaces the entire stack with the contents of the
  221. quotation at the top.
  222. @end deffn
  223. @deffn {Joy Operator} infra [S] [A] @result{} [S']
  224. This operator executes the quotation @var{[A]}, using the list
  225. @var{[S]} as the stack, then takes the resulting stack and pushes it
  226. as a list onto the original stack.
  227. @example
  228. 1 2 [3 4 5] [+] infra
  229. @result{} [1 2 [3 9]]
  230. @end example
  231. @end deffn
  232. @deffn {Joy Operator} + B A @result{} C
  233. Removes the two topmost integers and pushes their sum. The current
  234. implementation does not fully support floating point numbers.
  235. @end deffn
  236. @deffn {Joy Operator} - B A @result{} C
  237. Removes the two topmost integers @var{A} and @var{B} and pushes
  238. @math{@var{B} - @var{A}}.
  239. @end deffn
  240. @deffn {Joy Operator} < B A @result{} C
  241. Removes the two topmost integers @var{A} and @var{B} and pushes
  242. @code{true} if @math{@var{B} < @var{A}}, otherwise @code{false}.
  243. @end deffn
  244. @deffn {Joy Operator} > B A @result{} C
  245. Removes the two topmost integers @var{A} and @var{B} and pushes
  246. @code{true} if @math{@var{B} > @var{A}}, otherwise @code{false}.
  247. @end deffn
  248. @deffn {Joy Operator} = B A @result{} C
  249. Removes the two topmost integers @var{A} and @var{B} and pushes
  250. @code{true} if @math{@var{B} == @var{A}}, otherwise @code{false}.
  251. @end deffn
  252. @deffn {Joy Operator} logical A @result{} B
  253. Removes the topmost stack element and if it is either @code{true} or
  254. @code{false} pushes @code{true}, otherwise @code{false}.
  255. @end deffn
  256. @deffn {Joy Operator} char A @result{} B
  257. Removes the topmost stack element and pushes @code{true} if it is a
  258. character, otherwise @code{false}.
  259. @end deffn
  260. @deffn {Joy Operator} integer A @result{} B
  261. Removes the topmost stack element and pushes @code{true} if it is an
  262. integer, otherwise @code{false}.
  263. @end deffn
  264. @deffn {Joy Operator} string A @result{} B
  265. Removes the topmost stack element and pushes @code{true} if it is a
  266. string, otherwise @code{false}.
  267. @end deffn
  268. @deffn {Joy Operator} list A @result{} B
  269. Removes the topmost stack element and pushes @code{true} if it is a
  270. list/quotation, otherwise @code{false}.
  271. @end deffn
  272. @deffn {Joy Operator} putch A @result{}
  273. This operator expects a character as the topmost stack element. It
  274. removes it and writes it to standard out.
  275. @end deffn
  276. @deffn {Joy Operator} putchars A @result{}
  277. This operator expects a string (of characters) as the topmost stack
  278. element. It removes it and write it to standard out.
  279. @end deffn
  280. @deffn {Joy Operator} write A @result{}
  281. @deffnx {Joy Operator} . A @result{}
  282. This operator removes the topmost stack element and writes it to
  283. stdout followed by a newline.
  284. @example
  285. 1 'a [1 2] "foo" . . . .
  286. @print{} "foo"
  287. @print{} [1 2]
  288. @print{} 'a
  289. @print{} 1
  290. @result{} []
  291. @end example
  292. @end deffn
  293. @deffn {Joy Operator} def [name] [term] @result{}
  294. This operator binds in the global scope a variable @var{name} to the
  295. value @var{term}. It is equivalent to using @code{DEFINE}. Indeed,
  296. @code{DEFINE} is implemented as syntactic sugar for @code{def}.
  297. @example
  298. DEFINE foo == 2 + ; @equiv{} [foo] [2 +] def
  299. @end example
  300. @end deffn
  301. @deffn {Joy Operator} include filename @result{}
  302. This operator expects a string as the topmost stack element. A file
  303. with that name is searched for in the standard Joy installation
  304. directories as well as any directories given with the -I command-line
  305. option. If the filename ends in ``.joy'' it may be left off. If
  306. found, this file will be compiled and executed. Typically files
  307. included with this operator contain only operator definitions.
  308. @end deffn
  309. @deffn {Joy Operator} exit A @result{} @math{\perp}
  310. This operator expects an integer as the topmost stack element.
  311. Immediately stops execution and exits with the integer status at the
  312. top of the stack.
  313. @example
  314. [1 2 >] ["success" putchars] [1 exit] ifte .
  315. @result{} @math{\perp}
  316. @end example
  317. @end deffn
  318. @node Standard Library
  319. @section Standard Library
  320. @subsection Literals
  321. @deffn {Joy Operator} true @result{} true
  322. Pushes the logical @code{true} on top of the stack.
  323. @end deffn
  324. @deffn {Joy Operator} false @result{} false
  325. Pushes the logical @code{false} on top of the stack.
  326. @end deffn
  327. @subsection Stack Manipulation
  328. @deffn {Joy Operator} newstack @dots{} @result{}
  329. Remove all stack elements, leaving an empty stack.
  330. @end deffn
  331. @deffn {Joy Operator} popd B A @result{} A
  332. Remove the penultimate stack element.
  333. @end deffn
  334. @deffn {Joy Operator} dupd B A @result{} B B A
  335. Push a copy of the penultimate stack element under the topmost
  336. element.
  337. @end deffn
  338. @deffn {Joy Operator} swapd C B A @result{} B C A
  339. Swap the second and third stack elements.
  340. @end deffn
  341. @deffn {Joy Operator} dup2 B A @result{} B A B A
  342. Push copies of the top two stack elements.
  343. @end deffn
  344. @deffn {Joy Operator} pop2 B A @result{}
  345. @deffnx {Joy Operator} poppop B A @result{}
  346. Discard the top two stack elements.
  347. @end deffn
  348. @deffn {Joy Operator} dig1 B A @result{} A B
  349. @deffnx {Joy Operator} dig2 C B A @result{} B A C
  350. @deffnx {Joy Operator} dig3 D C B A @result{} C B A D
  351. @deffnx {Joy Operator} dig4 E D C B A @result{} D C B A E
  352. Reaches under @var{n} elements and ``digs'' up the next element to the
  353. top of the stack.
  354. @end deffn
  355. @deffn {Joy Operator} bury1 B A @result{} A B
  356. @deffnx {Joy Operator} bury2 C B A @result{} A C B
  357. @deffnx {Joy Operator} bury3 D C B A @result{} A D C B
  358. @deffnx {Joy Operator} bury4 E D C B A @result{} A E D C B
  359. Takes the topmost stack element and ``buries'' it under @var{n} elements.
  360. @end deffn
  361. @deffn {Joy Operator} flip2 B A @result{} A B
  362. @deffnx {Joy Operator} flip3 C B A @result{} A B C
  363. @deffnx {Joy Operator} flip4 D C B A @result{} A B C D
  364. Flips the order of the top @var{n} elements.
  365. @end deffn
  366. @deffn {Joy Operator} rollup C B A @result{} A C B
  367. Equivalent to @code{bury2}.
  368. @end deffn
  369. @deffn {Joy Operator} rolldown C B A @result{} B A C
  370. Equivalent to @code{dig2}.
  371. @end deffn
  372. @deffn {Joy Operator} rotate C B A @result{} A B C
  373. Equivalent to @code{flip3}.
  374. @end deffn
  375. @subsection List/Quotation Manipulation
  376. @deffn {Joy Operator} first [A0 @dots{}] @result{} A0
  377. Replaces the quotation at the top of the stack with its first element.
  378. @end deffn
  379. @deffn {Joy Operator} second [A0 A1 @dots{}] @result{} A1
  380. Replaces the quotation at the top of the stack with its second
  381. element.
  382. @end deffn
  383. @deffn {Joy Operator} third [A0 A1 A2 @dots{}] @result{} A2
  384. Replaces the quotation at the top of the stack with its third element.
  385. @end deffn
  386. @deffn {Joy Operator} rest [A0 A1 @dots{}] @result{} [A1 @dots{}]
  387. Replaces the quotation on the top of the stack with a copy of itself
  388. without its first element.
  389. @end deffn
  390. @subsection Quotation Evaluation
  391. These operators will cause the evaluation of one or more quotations.
  392. Using them, one can achieve something similar to anonymous function
  393. definitions. The effect most of these operators has on the stack
  394. depends on the contents of the quotation executed.
  395. @deffn {Joy Operator} i [A] @result{} @dots{}
  396. @deffnx {Joy Operator} dip0 [A] @result{} @dots{}
  397. Dequotes and executes the quotation at the top of the stack.
  398. @end deffn
  399. @deffn {Joy Operator} dip B [A] @result{} @dots{} B
  400. @deffnx {Joy Operator} dip1 B [A] @result{} @dots{} B
  401. Dequotes and executes the topmost quotation after temporarily removing
  402. @var{B} from the stack, then replaces @var{B} at the top of the stack.
  403. @end deffn
  404. @deffn {Joy Operator} dipd C B [A] @result{} @dots{} C B
  405. @deffnx {Joy Operator} dip2 C B [A] @result{} @dots{} C B
  406. Dequotes and executes the topmost quotation after temporarily removing
  407. @var{B} and @var{C} from the stack, then replaces them.
  408. @end deffn
  409. @deffn {Joy Operator} dip3 D C B [A] @result{} @dots{} D C B
  410. @deffnx {Joy Operator} dip4 E D C B [A] @result{} @dots{} E D C B
  411. Dequotes and executes the topmost quotation after temporarily removing
  412. the @var{n} stack elements below, then replaces them.
  413. @end deffn
  414. @deffn {Joy Operator} nullary [A] @result{} R
  415. Removes the topmost quotation, saves the state of the stack, then
  416. dequotes and executes the quotation, which leaves @var{R} on top of the
  417. stack. The saved stack is restored and @var{R} is pushed. That is,
  418. executing the quotation consumes no other stack elements.
  419. @end deffn
  420. @deffn {Joy Operator} unary B [A] @result{} R
  421. Removes the topmost quotation, saves the state of the stack, then
  422. dequotes and executes the quotation, which leaves @var{R} on the top
  423. of the stack. @var{R} is then pushed after restoring the saved stack
  424. and discarding the topmost element. That is, executing the quotation
  425. consumes exactly one stack element.
  426. @end deffn
  427. @deffn {Joy Operator} i2 D C [B] [A] @result{} @dots{}
  428. Executes @var{[B]} with @var{D} on top of the stack, then executes
  429. @var{[A]} with @var{C} on top of the result.
  430. @example
  431. 1 2 3 [+] [*] i2 .
  432. @result{} [9]
  433. @end example
  434. @end deffn
  435. @subsection General Operators
  436. @deffn {Joy Operator} branch C [B] [A] @result{} @dots{}
  437. If C is @code{true} this operator executes @var{[B]}, otherwise
  438. @var{[A]}.
  439. @end deffn
  440. @deffn {Joy Operator} ifte [I] [T] [E] @result{} @dots{}
  441. This operator saves the state of the stack then executes quoted
  442. predicate @var{[I]}. If the top of the stack is @code{true}, it then
  443. restores the stack and executes @var{[T]}, otherwise it restores the
  444. stack and executes @var{[E]}. In other words, the predicate @var{[I]}
  445. may manipulate the stack in any way, and it will be restored prior to
  446. executing @var{[T]} or @var{[E]}.
  447. @example
  448. 2 ['a 'b 'c]
  449. [size <] [pop 1 +] [['d] concat] ifte .
  450. @result{} [3]
  451. @end example
  452. @end deffn
  453. @deffn {Joy Operator} step [L] [A] @result{} @dots{}
  454. For each element in the list @var{[L]}, place it on top of the stack,
  455. then execute quotation @var{[A]}.
  456. @end deffn
  457. @subsection Recursion Operators
  458. Recursion may be achieved in Joy in the typical way by defining an
  459. operator that refers to itself in its body. It is, however, sometimes
  460. useful to define anonymous recursive operators. The following
  461. operators assist in doing this.
  462. @deffn {Joy Operator} tailrec [I] [T] [E] @result{} @dots{}
  463. Much like the @code{ifte} operator, this operator executes either
  464. @var{[T]} or @var{[E]} depending on the result of executing @var{[I]}
  465. but if @var{[E]} is executed this operator recurses.
  466. @example
  467. 0 [10 =] [] [dup 1 +] tailrec .
  468. @result{} [0 1 2 3 4 5 6 7 8 9 10]
  469. @end example
  470. @end deffn
  471. @deffn {Joy Operator} linrec [I] [T] [E1] [E2] @result{} @dots{}
  472. Like @code{tailrec} but upon completion of the recursive execution,
  473. executes @var{[E2]}.
  474. @example
  475. 1 [10 =] [] [dup 1 +] [*] linrec .
  476. @result{} [3628800]
  477. @end example
  478. @example
  479. [1 2 3] [null] [] [uncons] [cons] linrec .
  480. @result{} [[1 2 3]]
  481. @end example
  482. @example
  483. ['a 'b 'c 'd] [null] [pop 0] [rest 1 swap] [+] linrec .
  484. @result{} [4]
  485. @end example
  486. @end deffn
  487. @node Lisp Aliases
  488. @section Lisp Aliases
  489. Several operator aliases are provided for those familiar with
  490. programming in Lisp-like languages.
  491. @deffn {Joy Operator} car [A0 @dots{}] @result{} A0
  492. This is an alias for @code{first}.
  493. @end deffn
  494. @deffn {Joy Operator} cadr [A0 A1 @dots{}] @result{} A1
  495. This is an alias for @code{second}.
  496. @end deffn
  497. @deffn {Joy Operator} caddr [A0 A1 A2 @dots{}] @result{} A2
  498. This is an alias for @code{third}.
  499. @end deffn
  500. @deffn {Joy Operator} cdr [A0 A1 @dots{}] @result{} [A1 @dots{}]
  501. This is an alias for @code{rest}.
  502. @end deffn
  503. @deffn {Joy Operator} cddr [A0 A1 A2 @dots{}] @result{} [A2 @dots{}]
  504. This is equivalent to @code{rest rest}.
  505. @end deffn
  506. @deffn {Joy Operator} 1+ Z @result{} Z'
  507. This operator is equivalent to @code{succ}.
  508. @end deffn
  509. @deffn {Joy Operator} 1- Z @result{} Z'
  510. This operator is equivalent to @code{pred}.
  511. @end deffn
  512. @node Forth Aliases
  513. @section Forth Aliases
  514. Several operators are provided for those familiar with programming in
  515. the FORTH language. They may be accessed with:
  516. @example
  517. "forth" include .
  518. @end example
  519. @deffn {Joy Operator} drop A @result{}
  520. This is an alias for @code{pop}.
  521. @end deffn
  522. @deffn {Joy Operator} over B A @result{} B A B
  523. Push a copy of the second stack item.
  524. @end deffn
  525. @deffn {Joy Operator} nip B A @result{} A
  526. Remove the second item on the stack. Equivalent to @code{swap pop},
  527. and an alias for @code{popd}.
  528. @end deffn
  529. @deffn {Joy Operator} tuck B A @result{} A B A
  530. Insert a copy of the top stack item underneath the current second
  531. item. Equivalent to @code{swap over} or @code{dup bury2}.
  532. @end deffn
  533. @deffn {Joy Operator} rot C B A @result{} B A C
  534. An alias for @code{dig2} and @code{rolldown}. Not to be confused with
  535. @code{rotate}.
  536. @end deffn
  537. @deffn {Joy Operator} -rot C B A @result{} A C B
  538. An alias for @code{bury2}.
  539. @end deffn
  540. @deffn {Joy Operator} pick Xn @dots{} X0 n @result{} Xn @dots{} X0 Xn
  541. Retrieves a copy of the @var{n}@sup{th} stack item and places it on
  542. top of the stack. @code{0 pick} is equivalent to @code{dup}, @code{1
  543. pick} to @code{over}, etc.
  544. @end deffn
  545. @deffn {Joy Operator} /mod Z @result{} R Q
  546. This is an alias for @code{divmod}.
  547. @end deffn
  548. @deffn {Joy Operator} within X Y Z @result{} t/f
  549. Pushes @code{true} onto the stack if the integer inequality @math{Y
  550. \le X \lt Z} holds, otherwise @code{false}.
  551. @end deffn
  552. @deffn {Joy Operator} within? X Y Z @result{} t/f
  553. Pushes @code{true} onto the stack if the integer inequality @math{Y
  554. \le X \le Z} holds, otherwise @code{false}.
  555. @end deffn
  556. @deffn {Joy Operator} cr A @result{} A
  557. Causes a newline to be printed to stdout. Equivalent to
  558. @code{newline}.
  559. @end deffn
  560. @deffn {Joy Operator} bl @result{} '\032
  561. Places a ``space'' character onto the stack.
  562. @end deffn
  563. @deffn {Joy Operator} emit A @result{}
  564. Print the character on top of the stack to stdout. Equivalent to
  565. @code{putch}.
  566. @end deffn
  567. @c *********************************************************************
  568. @node GNU Free Documentation License
  569. @appendix GNU Free Documentation License
  570. @include fdl-1.3.texi
  571. @bye
  572. @c Local Variables:
  573. @c ispell-local-dictionary: "american";
  574. @c End: