home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / language / xschm22 / doc / xscheme.doc
Encoding:
Text File  |  1991-05-20  |  51.4 KB  |  2,841 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.                        XSCHEME: An Object-oriented Scheme
  8.  
  9.                                   Version 0.17
  10.  
  11.                     (not yet updated for version 0.22 (BCB))
  12.  
  13.                                  March 2, 1989
  14.  
  15.  
  16.                                        by
  17.                                David Michael Betz
  18.                                   P.O. Box 144
  19.                              Peterborough, NH 03458
  20.  
  21.                              (603) 924-4145 (home)
  22.  
  23.                    Copyright (c) 1989, by David Michael Betz
  24.                               All Rights Reserved
  25.            Permission is granted for unrestricted non-commercial use
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.         XSCHEME                TABLE OF CONTENTS                  Page 2
  73.  
  74.  
  75.         TABLE OF CONTENTS
  76.  
  77.             TABLE OF CONTENTS..................................2
  78.             INTRODUCTION.......................................3
  79.             A NOTE FROM THE AUTHOR.............................4
  80.             EXPRESSIONS........................................5
  81.             BINDING FORMS.....................................10
  82.             SEQUENCING........................................11
  83.             DELAYED EVALUATION................................12
  84.             ITERATION.........................................13
  85.             DEFINITIONS.......................................14
  86.             LIST FUNCTIONS....................................15
  87.             DESTRUCTIVE LIST FUNCTIONS........................17
  88.             SYMBOL FUNCTIONS..................................18
  89.             VECTOR FUNCTIONS..................................19
  90.             ARRAY FUNCTIONS...................................20
  91.             CONVERSION FUNCTIONS..............................21
  92.             TYPE PREDICATES...................................22
  93.             EQUALITY PREDICATES...............................25
  94.             ARITHMETIC FUNCTIONS..............................26
  95.             NUMERIC COMPARISON FUNCTIONS......................29
  96.             BITWISE LOGICAL FUNCTIONS.........................30
  97.             STRING FUNCTIONS..................................31
  98.             STRING COMPARISON FUNCTIONS.......................32
  99.             CHARACTER COMPARISON FUNCTIONS....................33
  100.             INPUT/OUTPUT FUNCTIONS............................34
  101.             OUTPUT CONTROL FUNCTIONS..........................36
  102.             FILE I/O FUNCTIONS................................37
  103.             CONTROL FEATURES..................................39
  104.             ENVIRONMENT FUNCTIONS.............................40
  105.             UTILITY FUNCTIONS.................................41
  106.             SYSTEM FUNCTIONS..................................42
  107.             OBJECT REPRESENTATIONS............................43
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.         XSCHEME                   INTRODUCTION                    Page 3
  139.  
  140.  
  141.         XScheme is an implementation of the Scheme programming language
  142.         with extensions to support object-oriented programming.
  143.  
  144.         There are currently implementations of XScheme running on the
  145.         IBM-PC and clones under MS-DOS, on the Macintosh, the Atari-ST
  146.         and the Amiga.  It is completely written in the programming
  147.         language 'C' and is easily extended with user written built-in
  148.         functions and classes.  It is available in source form to non-
  149.         commercial users.
  150.  
  151.         This document is a brief description of XScheme.  XScheme
  152.         follows the "Revised^3 Report on the Algorithmic Language
  153.         Scheme".  It assumes some knowledge of Scheme or LISP and some
  154.         understanding of the concepts of object-oriented programming.
  155.  
  156.         I recommend the book "Structure and Interpretation of Computer
  157.         Programs" by Harold Abelson and Gerald Jay Sussman and published
  158.         by The MIT Press and the McGraw-Hill Book Company for learning
  159.         Scheme (and programming in general).  You might also find "The
  160.         Scheme Programming Language" by R. Kent Dybvig and "The Little
  161.         Lisper" by Daniel P. Friedman and Matthias Felleisen to be
  162.         helpful.
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.         XSCHEME              A NOTE FROM THE AUTHOR               Page 4
  205.  
  206.  
  207.         A NOTE FROM THE AUTHOR
  208.  
  209.         If you have any problems with XScheme, feel free to contact me
  210.         for help or advice.  Please remember that since XScheme is
  211.         available in source form in a high level language, many users
  212.         have been making versions available on a variety of machines.
  213.         If you call to report a problem with a specific version, I may
  214.         not be able to help you if that version runs on a machine to
  215.         which I don't have access.  Please have the version number of
  216.         the version that you are running readily accessible before
  217.         calling me.
  218.  
  219.         If you find a bug in XScheme, first try to fix the bug yourself
  220.         using the source code provided.  If you are successful in fixing
  221.         the bug, send the bug report along with the fix to me.  If you
  222.         don't have access to a C compiler or are unable to fix a bug,
  223.         please send the bug report to me and I'll try to fix it.
  224.  
  225.         Any suggestions for improvements will be welcomed.  Feel free to
  226.         extend the language in whatever way suits your needs.  However,
  227.         PLEASE DO NOT RELEASE ENHANCED VERSIONS WITHOUT CHECKING WITH ME
  228.         FIRST!!  I would like to be the clearing house for new features
  229.         added to XScheme.  If you want to add features for your own
  230.         personal use, go ahead.  But, if you want to distribute your
  231.         enhanced version, contact me first.
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.         XSCHEME                   EXPRESSIONS                     Page 5
  271.  
  272.  
  273.         EXPRESSIONS
  274.  
  275.         <variable>
  276.  
  277.             An expression consisting of a variable is a variable
  278.             reference.  The value of the variable reference is the value
  279.             stored in the location to which the variable is bound.  It
  280.             is an error to reference an unbound variable.
  281.  
  282.         (QUOTE <datum>)
  283.         '<datum>
  284.  
  285.             (quote <datum>) evaluates to <datum>.  <Datum> may be any
  286.             external representation of a Scheme object.  This notation
  287.             is used to include literal constants in Scheme code.  (quote
  288.             <datum>) may be abbreviated as '<datum>.  The two notations
  289.             are equivalent in all respects.
  290.  
  291.         <constant>
  292.  
  293.             Numeric constants, string constants, character constants,
  294.             and boolean constants evaluate "to themselves"; they need
  295.             not be quoted.
  296.  
  297.         (<operator> <operand>...)
  298.  
  299.             A procedure call is written by simply enclosing in
  300.             parentheses expressions for the procedure to be called and
  301.             the arguments to be passed to it.  The operator and operand
  302.             expressions are evaluated and the resulting procedure is
  303.             passed the resulting arguments.
  304.  
  305.         (<object> <selector> <operand>...)
  306.  
  307.             A message sending form is written by enclosing in
  308.             parentheses expressions for the receiving object, the
  309.             message selector, and the arguments to be passed to the
  310.             method.  The receiver, selector, and argument expressions
  311.             are evaluated, the message selector is used to select an
  312.             appropriate method to handle the message, and the resulting
  313.             method is passed the resulting arguments.
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.         XSCHEME                   EXPRESSIONS                     Page 6
  337.  
  338.  
  339.         (LAMBDA <formals> <body>)
  340.  
  341.             <Formals> should be a formal argument list as described
  342.             below, and <body>  should be a sequence of one or more
  343.             expressions.  A lambda expression evaluates to a procedure.
  344.             The environment in effect when the lambda expression is
  345.             evaluated is remembered as part of the procedure.  When the
  346.             procedure is later called with some actual arguments, the
  347.             environment in which the lambda expression was evaluated
  348.             will be extended by binding the variables in the formal
  349.             argument list to fresh locations, the corresponding actual
  350.             argument values will be stored in those locations, and the
  351.             expressions in the body of the lambda expression will be
  352.             evaluated sequentially in the extended environment.  The
  353.             result of the last expression in the body will be returned
  354.             as the result of the procedure call.
  355.  
  356.             <Formals> should have the following form:
  357.  
  358.                 (<var>... [#!OPTIONAL <ovar>...] [. <rvar>])
  359.               or
  360.                 (<var>... [#!OPTIONAL <ovar>...] [#!REST <rvar>])
  361.  
  362.               where:
  363.  
  364.                 <var>    is a required argument
  365.                 <ovar>   is an optional argument
  366.                 <rvar>   is a "rest" argument
  367.  
  368.             There are three parts to a <formals> list.  The first lists
  369.             the required arguments of the procedure.  All calls to the
  370.             procedure must supply values for each of the required
  371.             arguments.  The second part lists the optional arguments of
  372.             the procedure.  An optional argument may be supplied in a
  373.             call or omitted.  If it is omitted, a special value is given
  374.             to the argument that satisfies the default-object?
  375.             predicate.  This provides a way to test to see if an
  376.             optional argument was provided in a call or omitted.  The
  377.             last part of the <formals> list gives the "rest" argument.
  378.             This argument will be bound to the rest of the list of
  379.             arguments supplied to a call after the required and optional
  380.             arguments have been removed.
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.         XSCHEME                   EXPRESSIONS                     Page 7
  403.  
  404.  
  405.         (IF <test> <consequent> [<alternate>])
  406.  
  407.             An if expression is evaluated as follows:  first, <test> is
  408.             evaluated.  If it yields a true value, then <consequent> is
  409.             evaluated and its value is returned.  Otherwise, <alternate>
  410.             is evaluated and its value is returned.  If <test> yields a
  411.             false value and no <alternate> is specified, then the result
  412.             of the expression is unspecified.
  413.  
  414.         (ACCESS <variable> <env>)
  415.  
  416.             <Env> is evaluated producing an environment.  The result is
  417.             the value of <variable> in this environment.
  418.  
  419.         (SET! <variable> <expression>)
  420.  
  421.             <Expression> is evaluated, and the resulting value is stored
  422.             in the location to which <variable> is bound.  <Variable>
  423.             must be bound in some region or at the top level. The result
  424.             of the set! expression is unspecified.
  425.  
  426.         (SET! (ACCESS <variable> <env>) <value>)
  427.  
  428.             <Env> is evaluated producing an environment.  <Value> is
  429.             evaluated and the resulting value is stored as the value of
  430.             <variable> in this environment.  The result of the set!
  431.             expression is unspecified.
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.         XSCHEME                   EXPRESSIONS                     Page 8
  469.  
  470.  
  471.         (COND <clause>...)
  472.  
  473.             Each clause should be of the form
  474.  
  475.                 (<test> <expression>...)
  476.  
  477.             where <test> is any expression.  The last <clause> may be an
  478.             "else clause," which has the form
  479.  
  480.                 (ELSE <expression>...)
  481.  
  482.             A cond expression is evaluated by evaluating the <test>
  483.             expressions of successive <clause>s in order until one of
  484.             them evaluates to a true value.  When a <test> evaluates to
  485.             a true value, then the remaining <expression>s in its
  486.             <clause> are evaluated in order, and the result of the last
  487.             <expression> in the <clause> is returned as the result of
  488.             the entire cond expression.  If the selected <clause>
  489.             contains only the <test> and no <expression>s, then the
  490.             value of the <test> is returned as the result.  If all
  491.             <test>s evaluate to false values, and there is no else
  492.             clause, then the result of the conditional expression is
  493.             unspecified; if there is an else clause, then its
  494.             <expression>s are evaluated, and the value of the last one
  495.             is returned.
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.         XSCHEME                   EXPRESSIONS                     Page 9
  535.  
  536.  
  537.         (AND <test>...)
  538.  
  539.             The <test> expressions are evaluated from left to right, and
  540.             the value of the first expression that evaluates to a false
  541.             value is returned.  Any remaining expressions are not
  542.             evaluated.  If all the expressions evaluate to true values,
  543.             the value of the last expression is returned.  If there are
  544.             no expressions then #t is returned.
  545.  
  546.         (OR <test>...)
  547.  
  548.             The <test> expressions are evaluated from left to right, and
  549.             the value of the first expression that evaluates to a true
  550.             value is returned.  Any remaining expressions are not
  551.             evaluated.  If all expressions evaluate to false values, the
  552.             value of the last expression is returned.  If there are no
  553.             expressions then #f is returned.
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.         XSCHEME                  BINDING FORMS                   Page 10
  601.  
  602.  
  603.         BINDING FORMS
  604.  
  605.         (LET [<name>] <bindings> <body>)
  606.  
  607.             <Bindings> should have the form
  608.  
  609.                 ((<variable> <init>)...)
  610.  
  611.             where each <init> is an expression, and <body> should be a
  612.             sequence of one or more expressions.  The <init>s are
  613.             evaluated in the current envirnoment, the <variable>s are
  614.             bound to fresh locations holding the results, the <body> is
  615.             evaluated in the extended environment, and the value of the
  616.             last expression of <body> is returned.  Each binding of a
  617.             <variable> has <body> as its region.
  618.  
  619.             If a name is supplied, a procedure that takes the bound
  620.             variables as its arguments and has the body of the LET as
  621.             its body is bound to that name.
  622.  
  623.         (LET* <bindings> <body>)
  624.  
  625.             Same as LET except that the bindings are done sequentially
  626.             from left to right and the bindings to the left are visible
  627.             while evaluating the initialization expressions for each
  628.             variable.
  629.  
  630.         (LETREC <bindings> <body>)
  631.  
  632.             <Bindings> should have the form
  633.  
  634.                 ((<variable> <init>)...)
  635.  
  636.             and <body> should be a sequence of one or more expressions.
  637.             The <variable>s are bound to fresh locations holding
  638.             undefined values; the <init>s are evaluated in the resulting
  639.             environment; each <variable>  is assigned to the result of
  640.             the corresponding <init>; the <body> is evaluated in the
  641.             resulting environment; and the value of the last expression
  642.             in <body> is returned.  Each binding of a <variable> has the
  643.             entire letrec expression as its region, making it possible
  644.             to define mutually recursive procedures.  One restriction of
  645.             letrec is very important:  it must be possible to evaluate
  646.             each <init> without referring to the value of any
  647.             <variable>.  If this restriction is violated, then the
  648.             effect is undefined, and an error may be signalled during
  649.             evaluation of the <init>s.  The restriction is necessary
  650.             because Scheme passes arguments by value rather than by
  651.             name.  In the most common uses of letrec, all the <init>s
  652.             are lambda expressions and the restriction is satisfied
  653.             automatically.
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.         XSCHEME                    SEQUENCING                    Page 11
  667.  
  668.  
  669.             SEQUENCING
  670.  
  671.             (BEGIN <expression>...)
  672.             (SEQUENCE <expression>...)
  673.  
  674.                 The <expression>s are evaluated sequentially from left
  675.                 to right, and the value of the last <expression> is
  676.                 returned.  This expression type is used to sequence side
  677.                 effects such as input and output.
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.         XSCHEME                DELAYED EVALUATION                Page 12
  733.  
  734.  
  735.             DELAYED EVALUATION
  736.  
  737.             (CONS-STREAM expr1 expr2)
  738.  
  739.                 Create a cons stream whose head is expr1 (which is
  740.                 evaluated immediately) and whose tail is expr2 (whose
  741.                 evaluation is delayed until TAIL is called).  To use
  742.                 CONS-STREAM, enter the following access procedures:
  743.  
  744.                     (define head car)
  745.                     (define (tail stream) (force (cdr stream)))
  746.  
  747.             (DELAY <expression>)
  748.  
  749.                 Evaluating this expression creates a "promise" to
  750.                 evaluate <expression>  at a later time.
  751.  
  752.             (FORCE promise)
  753.  
  754.                 Applying FORCE to a promise generated by DELAY requests
  755.                 that the promise produce the value of the expression
  756.                 passed to DELAY.  The first time a promise is FORCEed,
  757.                 the DELAY expression is evaluated and the value stored.
  758.                 On subsequent calls to FORCE with the same promise, the
  759.                 saved value is returned.
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.         XSCHEME                    ITERATION                     Page 13
  799.  
  800.  
  801.             ITERATION
  802.  
  803.             (WHILE <test> <expression>...)
  804.  
  805.                 While is an iteration construct.  Each iteration begins
  806.                 by evaluating <test>; if the result is false, then the
  807.                 loop terminates and the value of <test> is returned as
  808.                 the value of the while expression.  If <test>  evaluates
  809.                 to a true value, then the <expression>s are evaluated in
  810.                 order for effect and the next iteration begins.
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.         XSCHEME                   DEFINITIONS                    Page 14
  865.  
  866.  
  867.             DEFINITIONS
  868.  
  869.             (DEFINE <variable> <expression>)
  870.  
  871.                 Define a variable and give it an initial value.
  872.  
  873.             (DEFINE (<variable> <formals>) <body>)
  874.  
  875.                 Define a procedure.
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.         XSCHEME                  LIST FUNCTIONS                  Page 15
  931.  
  932.  
  933.             LIST FUNCTIONS
  934.  
  935.             (CONS expr1 expr2)
  936.  
  937.                 Create a new pair whose car is expr1 and whose cdr is
  938.                 expr2.
  939.  
  940.             (CAR pair)
  941.  
  942.                 Extract the car of a pair.
  943.  
  944.             (CDR pair)
  945.  
  946.                 Extract the cdr of a pair.
  947.  
  948.             (CxxR pair)
  949.             (CxxxR pair)
  950.             (CxxxxR pair)
  951.  
  952.                 These functions are short for combinations of CAR and
  953.                 CDR.  Each 'x' is stands for either 'A' or 'D'.  An 'A'
  954.                 stands for the CAR function and a 'D' stands for the CDR
  955.                 function.  For instance, (CADR x) is the same as (CAR
  956.                 (CDR x)).
  957.  
  958.             (LIST expr...)
  959.  
  960.                 Create a list whose elements are the arguments to the
  961.                 function.  This function can take an arbitrary number of
  962.                 arguments.  Passing no arguments results in the empty
  963.                 list.
  964.  
  965.             (APPEND list...)
  966.  
  967.                 Append lists to form a single list.  This function takes
  968.                 an arbitrary number of arguments.  Passing no arguments
  969.                 results in the empty list.
  970.  
  971.             (REVERSE list)
  972.  
  973.                 Create a list whose elements are the same as the
  974.                 argument except in reverse order.
  975.  
  976.             (LAST-PAIR list)
  977.  
  978.                 Return the last pair in a list.
  979.  
  980.             (LENGTH list)
  981.  
  982.                 Compute the length of a list.
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.         XSCHEME                  LIST FUNCTIONS                  Page 16
  997.  
  998.  
  999.             (MEMBER expr list)
  1000.             (MEMV expr list)
  1001.             (MEMQ expr list)
  1002.  
  1003.                 Find an element in a list.  Each of these functions
  1004.                 searches the list looking for an element that matches
  1005.                 expr.  If a matching element is found, the remainder of
  1006.                 the list starting with that element is returned.  If no
  1007.                 matching element is found, the empty list is returned.
  1008.                 The functions differ in the test used to determine if an
  1009.                 element matches expr.  The MEMBER function uses EQUAL?,
  1010.                 the MEMV function uses EQV?  and the MEMQ function uses
  1011.                 EQ?.
  1012.  
  1013.             (ASSOC expr alist)
  1014.             (ASSV expr alist)
  1015.             (ASSQ expr alist)
  1016.  
  1017.                 Find an entry in an association list.  An association
  1018.                 list is a list of pairs.  The car of each pair is the
  1019.                 key and the cdr is the value.  These functions search an
  1020.                 association list for a pair whose key matches expr.  If
  1021.                 a matching pair is found, it is returned.  Otherwise,
  1022.                 the empty list is returned.  The functions differ in the
  1023.                 test used to determine if a key matches expr.  The ASSOC
  1024.                 function uses EQUAL?, the ASSV function uses EQV?  and
  1025.                 the ASSQ function uses EQ?.
  1026.  
  1027.             (LIST-REF list n)
  1028.  
  1029.                 Return the nth element of a list (zero based).
  1030.  
  1031.             (LIST-TAIL list n)
  1032.  
  1033.                 Return the sublist obtained by removing the first n
  1034.                 elements of list.
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.         XSCHEME            DESTRUCTIVE LIST FUNCTIONS            Page 17
  1063.  
  1064.  
  1065.             DESTRUCTIVE LIST FUNCTIONS
  1066.  
  1067.             (SET-CAR! pair expr)
  1068.  
  1069.                 Set the car of a pair to expr.  The value returned by
  1070.                 this procedure is unspecified.
  1071.  
  1072.             (SET-CDR! pair expr)
  1073.  
  1074.                 Set the cdr of a pair to expr.  The value returned by
  1075.                 this procedure is unspecified.
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.         XSCHEME                 SYMBOL FUNCTIONS                 Page 18
  1129.  
  1130.  
  1131.             SYMBOL FUNCTIONS
  1132.  
  1133.             (BOUND? sym)
  1134.  
  1135.                 Returns #t if a global value is bound to the symbol and
  1136.                 #f otherwise.
  1137.  
  1138.             (SYMBOL-VALUE sym)
  1139.  
  1140.                 Get the global value of a symbol.
  1141.  
  1142.             (SET-SYMBOL-VALUE! sym expr)
  1143.  
  1144.                 Set the global value of a symbol.  The value returned by
  1145.                 this procedure is unspecified.
  1146.  
  1147.             (SYMBOL-PLIST sym)
  1148.  
  1149.                 Get the property list associated with a symbol.
  1150.  
  1151.             (SET-SYMBOL-PLIST! sym plist)
  1152.  
  1153.                 Set the property list associate with a symbol.  The
  1154.                 value returned by this procedure is unspecified.
  1155.  
  1156.             (GENSYM [sym|str|num])
  1157.  
  1158.                 Generate a new, uninterned symbol.  The print name of
  1159.                 the symbol will consist of a prefix with a number
  1160.                 appended.  The initial prefix is "G" and the initial
  1161.                 number is 1.  If a symbol is specified as an argument,
  1162.                 the prefix is set to the print name of that symbol.  If
  1163.                 a string is specified, the prefix is set to that string.
  1164.                 If a number is specified, the numeric suffix is set to
  1165.                 that number.  After the symbol is generated, the number
  1166.                 is incremented so subsequent calls to GENSYM will
  1167.                 generate numbers in sequence.
  1168.  
  1169.             (GET sym prop)
  1170.  
  1171.                 Get the value of a property of a symbol.  The prop
  1172.                 argument is a symbol that is the property name.  If a
  1173.                 property with that name exists on the symbols property
  1174.                 list, the value of the property is returned.  Otherwise,
  1175.                 the empty list is returned.
  1176.  
  1177.             (PUT sym prop expr)
  1178.  
  1179.                 Set the value of a property of a symbol.  The prop
  1180.                 argument is a symbol that is the property name.  The
  1181.                 property/value combination is added to the property list
  1182.                 of the symbol.
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.         XSCHEME                 VECTOR FUNCTIONS                 Page 19
  1195.  
  1196.  
  1197.             VECTOR FUNCTIONS
  1198.  
  1199.             (VECTOR expr...)
  1200.  
  1201.                 Create a vector whose elements are the arguments to the
  1202.                 function.  This function can take an arbitrary number of
  1203.                 arguments.  Passing no arguments results in a zero
  1204.                 length vector.
  1205.  
  1206.             (MAKE-VECTOR len)
  1207.  
  1208.                 Make a vector of the specified length.
  1209.  
  1210.             (VECTOR-LENGTH vect)
  1211.  
  1212.                 Get the length of a vector.
  1213.  
  1214.             (VECTOR-REF vect n)
  1215.  
  1216.                 Return the nth element of a vector (zero based).
  1217.  
  1218.             (VECTOR-SET! vect n expr)
  1219.  
  1220.                 Set the nth element of a vector (zero based).
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.         XSCHEME                 ARRAY FUNCTIONS                  Page 20
  1261.  
  1262.  
  1263.             ARRAY FUNCTIONS
  1264.  
  1265.             (MAKE-ARRAY d1 d2...)
  1266.  
  1267.                 Make an array (vector of vectors) with the specified
  1268.                 dimensions.  At least one dimension must be specified.
  1269.  
  1270.             (ARRAY-REF array s1 s2...)
  1271.  
  1272.                 Get an array element.  The sn arguments are integer
  1273.                 subscripts (zero based).
  1274.  
  1275.             (ARRAY-SET! array s1 s2... expr)
  1276.  
  1277.                 Set an array element.  The sn arguments are integer
  1278.                 subscripts (zero based).
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.         XSCHEME               CONVERSION FUNCTIONS               Page 21
  1327.  
  1328.  
  1329.             CONVERSION FUNCTIONS
  1330.  
  1331.             (SYMBOL->STRING sym)
  1332.  
  1333.                 Convert a symbol to a string.  Returns the print name of
  1334.                 the symbol as a string.
  1335.  
  1336.             (STRING->SYMBOL str)
  1337.  
  1338.                 Convert a string to a symbol.  Returns a symbol with the
  1339.                 string as its print name.  This can either be a new
  1340.                 symbol or an existing one with the same print name.
  1341.  
  1342.             (VECTOR->LIST vect)
  1343.  
  1344.                 Convert a vector to a list.  Returns a list of the
  1345.                 elements of the vector.
  1346.  
  1347.             (LIST->VECTOR list)
  1348.  
  1349.                 Convert a list to a vector.  Returns a vector of the
  1350.                 elements of the list.
  1351.  
  1352.             (STRING->LIST str)
  1353.  
  1354.                 Convert a string to a list.  Returns a list of the
  1355.                 characters in the string.
  1356.  
  1357.             (LIST->STRING list)
  1358.  
  1359.                 Convert a list of character to a string.  Returns a
  1360.                 string whose characters are the elements of the list.
  1361.  
  1362.             (CHAR->INTEGER char)
  1363.  
  1364.                 Convert a character to an integer.  Returns the ASCII
  1365.                 code of the character as an integer.
  1366.  
  1367.             (INTEGER->CHAR n)
  1368.  
  1369.                 Convert an integer ASCII code to a character.  Returns
  1370.                 the character whose ASCII code is the integer.
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.         XSCHEME                 TYPE PREDICATES                  Page 22
  1393.  
  1394.  
  1395.             TYPE PREDICATE FUNCTIONS
  1396.  
  1397.             (NOT expr)
  1398.  
  1399.                 Returns #t if the expression is #f and #t otherwise.
  1400.  
  1401.             (NULL? expr)
  1402.  
  1403.                 Returns #t if the expression is the empty list and #f
  1404.                 otherwise.
  1405.  
  1406.             (ATOM? expr)
  1407.  
  1408.                 Returns #f if the expression is a pair and #t otherwise.
  1409.  
  1410.             (LIST? expr)
  1411.  
  1412.                 Returns #t if the expression is either a pair or the
  1413.                 empty list and #f otherwise.
  1414.  
  1415.             (NUMBER? expr)
  1416.  
  1417.                 Returns #t if the expression is a number and #f
  1418.                 otherwise.
  1419.  
  1420.             (BOOLEAN? expr)
  1421.  
  1422.                 Returns #t if the expression is either #t or #f and #f
  1423.                 otherwise.
  1424.  
  1425.             (PAIR? expr)
  1426.  
  1427.                 Returns #t if the expression is a pair and #f otherwise.
  1428.  
  1429.             (SYMBOL? expr)
  1430.  
  1431.                 Returns #t if the expression is a symbol and #f
  1432.                 otherwise.
  1433.  
  1434.             (COMPLEX? expr)
  1435.  
  1436.                 Returns #t if the expression is a complex number and #f
  1437.                 otherwise.
  1438.                 Note:  Complex numbers are not yet supported by XScheme.
  1439.  
  1440.             (REAL? expr)
  1441.  
  1442.                 Returns #t if the expression is a real number and #f
  1443.                 otherwise.
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.         XSCHEME                 TYPE PREDICATES                  Page 23
  1459.  
  1460.  
  1461.             (RATIONAL? expr)
  1462.  
  1463.                 Returns #t if the expression is a rational number and #f
  1464.                 otherwise.
  1465.                 Note:  Rational numbers are not yet supported by
  1466.                 XScheme.
  1467.  
  1468.             (INTEGER? expr)
  1469.  
  1470.                 Returns #t if the expression is an integer and #f
  1471.                 otherwise.
  1472.  
  1473.             (CHAR? expr)
  1474.  
  1475.                 Returns #t if the expression is a character and #f
  1476.                 otherwise.
  1477.  
  1478.             (STRING? expr)
  1479.  
  1480.                 Returns # if the expression is a string and #f
  1481.                 otherwise.
  1482.  
  1483.             (VECTOR? expr)
  1484.  
  1485.                 Returns #t if the expression is a vector and #f
  1486.                 otherwise.
  1487.  
  1488.             (PROCEDURE? expr)
  1489.  
  1490.                 Returns #t if the expression is a procedure (closure)
  1491.                 and #f otherwise.
  1492.  
  1493.             (PORT? expr)
  1494.  
  1495.                 Returns #t if the expression is a port and #f otherwise.
  1496.  
  1497.             (INPUT-PORT? expr)
  1498.  
  1499.                 Returns #t if the expression is an input port and #f
  1500.                 otherwise.
  1501.  
  1502.             (OUTPUT-PORT? expr)
  1503.  
  1504.                 Returns #t if the expression is an output port and #f
  1505.                 otherwise.
  1506.  
  1507.             (OBJECT? expr)
  1508.  
  1509.                 Returns #t if the expression is an object and #f
  1510.                 otherwise.
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.         XSCHEME                 TYPE PREDICATES                  Page 24
  1525.  
  1526.  
  1527.             (EOF-OBJECT? expr)
  1528.  
  1529.                 Returns #t if the expression is the object returned by
  1530.                 READ upon detecting an end of file condition and #f
  1531.                 otherwise.
  1532.  
  1533.             (DEFAULT-OBJECT? expr)
  1534.  
  1535.                 Returns #t if the expression is the object passed as the
  1536.                 default value of an optional parameter to a procedure
  1537.                 when that parameter is omitted from a call and #f
  1538.                 otherwise.
  1539.  
  1540.             (ENVIRONMENT? x)
  1541.  
  1542.                 Returns #t if the expression is an environment and #f
  1543.                 otherwise.
  1544.  
  1545.  
  1546.  
  1547.  
  1548.  
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.         XSCHEME               EQUALITY PREDICATES                Page 25
  1591.  
  1592.  
  1593.             EQUALITY PREDICATES
  1594.  
  1595.             (EQUAL? expr1 expr2)
  1596.  
  1597.                 Recursively compares two objects to determine if their
  1598.                 components are the same and returns #t if they are the
  1599.                 same and #f otherwise.
  1600.  
  1601.             (EQV? expr1 expr2)
  1602.  
  1603.                 Compares two objects to determine if they are the same
  1604.                 object.  Returns #t if they are the same and #f
  1605.                 otherwise.  This function does not compare the elements
  1606.                 of lists, vectors or strings but will compare all types
  1607.                 of numbers.
  1608.  
  1609.             (EQ? expr1 expr2)
  1610.  
  1611.                 Compares two objects to determine if they are the same
  1612.                 object.  Returns #t if they are the same and #f
  1613.                 otherwise.  This function performs a low level address
  1614.                 compare on two objects and may return #f for objects
  1615.                 that appear on the surface to be the same.  This is
  1616.                 because the objects are not stored uniquely in memory.
  1617.                 For instance, numbers may appear to be equal, but EQ?
  1618.                 will return #f when comparing them if they are stored at
  1619.                 different addresses.  The advantage of this function is
  1620.                 that it is faster than the others.  Symbols are
  1621.                 guaranteed to compare correctly, so EQ? can safely be
  1622.                 used to compare them.
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.         XSCHEME               ARITHMETIC FUNCTIONS               Page 26
  1657.  
  1658.  
  1659.             ARITHMETIC FUNCTIONS
  1660.  
  1661.             (ZERO? n)
  1662.  
  1663.                 Returns #t if the number is zero and #f otherwise.
  1664.  
  1665.             (POSITIVE? n)
  1666.  
  1667.                 Returns #t if the number is positive and #f otherwise.
  1668.  
  1669.             (NEGATIVE? n)
  1670.  
  1671.                 Returns #t if the number is negative and #f otherwise.
  1672.  
  1673.             (ODD? n)
  1674.  
  1675.                 Returns #t if the integer is odd and #f otherwise.
  1676.  
  1677.             (EVEN? n)
  1678.  
  1679.                 Returns #t if the integer is even and #f otherwise.
  1680.  
  1681.             (EXACT? n)
  1682.  
  1683.                 Returns #t if the number is exact and #f otherwise.
  1684.                 Note:  This function always returns #f in XScheme since
  1685.                 exact numbers are not yet supported.
  1686.  
  1687.             (INEXACT? n)
  1688.  
  1689.                 Returns #t if the number is inexact and #f otherwise.
  1690.                 Note:  This function always returns #t in XScheme since
  1691.                 exact numbers are not yet supported.
  1692.  
  1693.             (TRUNCATE n)
  1694.  
  1695.                 Truncates a number to an integer and returns the
  1696.                 resulting value.
  1697.  
  1698.             (FLOOR n)
  1699.  
  1700.                 Returns the largest integer not larger than n.
  1701.  
  1702.             (CEILING n)
  1703.  
  1704.                 Returns the smallest integer not smaller than n.
  1705.  
  1706.             (ROUND n)
  1707.  
  1708.                 Returns the closest integer to n, rounding to even when
  1709.                 n is halfway between two integers.
  1710.  
  1711.             (1+ n)
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.         XSCHEME               ARITHMETIC FUNCTIONS               Page 27
  1723.  
  1724.  
  1725.                 Returns the result of adding one to the number.
  1726.  
  1727.             (-1+ n)
  1728.  
  1729.                 Returns the result of subtracting one from the number.
  1730.  
  1731.             (ABS n)
  1732.  
  1733.                 Returns the absolute value of the number.
  1734.  
  1735.             (GCD n1 n2)
  1736.  
  1737.                 Returns the greatest common divisor of the two numbers.
  1738.  
  1739.             (RANDOM n)
  1740.  
  1741.                 Returns a random number between zero and n-1 (n must be
  1742.                 an integer).
  1743.  
  1744.             (+ n1 n2...)
  1745.  
  1746.                 Returns the sum of the numbers.
  1747.  
  1748.             (- n)
  1749.  
  1750.                 Negates the number and returns the resulting value.
  1751.  
  1752.             (- n1 n2...)
  1753.  
  1754.                 Subtracts each remaining number from n1 and returns the
  1755.                 resulting value.
  1756.  
  1757.             (* n1 n2...)
  1758.  
  1759.                 Multiples the numbers and returns the resulting value.
  1760.  
  1761.             (/ n)
  1762.  
  1763.                 Returns 1/n.
  1764.  
  1765.             (/ n1 n2...)
  1766.  
  1767.                 Divides n1 by each of the remaining numbers and returns
  1768.                 the resulting value.
  1769.  
  1770.             (QUOTIENT n1 n2...)
  1771.  
  1772.                 Divides the integer n1 by each of the remaining numbers
  1773.                 and returns the resulting integer quotient.  This
  1774.                 function does integer division.
  1775.  
  1776.             (REMAINDER n1 n2)
  1777.  
  1778.                 Divides the integer n1 by the integer n2 and returns the
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.         XSCHEME               ARITHMETIC FUNCTIONS               Page 28
  1789.  
  1790.  
  1791.                 remainder.
  1792.  
  1793.             (MIN n1 n2...)
  1794.  
  1795.                 Returns the number with the minimum value.
  1796.  
  1797.             (MAX n1 n2...)
  1798.  
  1799.                 Returns the number with the maximum value.
  1800.  
  1801.             (SIN n)
  1802.  
  1803.                 Returns the sine of the number.
  1804.  
  1805.             (COS n)
  1806.  
  1807.                 Returns the cosine of the number.
  1808.  
  1809.             (TAN n)
  1810.  
  1811.                 Returns the tangent of the number.
  1812.  
  1813.             (ASIN n)
  1814.  
  1815.                 Returns the arc-sine of the number.
  1816.  
  1817.             (ACOS n)
  1818.  
  1819.                 Returns the arc-cosine of the number.
  1820.  
  1821.             (ATAN x)
  1822.  
  1823.                 Returns the arc-tangent of x.
  1824.  
  1825.             (ATAN y x)
  1826.  
  1827.                 Returns the arc-tangent of y/x.
  1828.  
  1829.             (EXP n)
  1830.  
  1831.                 Returns e raised to the n.
  1832.  
  1833.             (SQRT n)
  1834.  
  1835.                 Returns the square root of n.
  1836.  
  1837.             (EXPT n1 n2)
  1838.  
  1839.                 Returns n1 raised to the n2 power.
  1840.  
  1841.             (LOG n)
  1842.  
  1843.                 Returns the natural logarithm of n.
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.         XSCHEME           NUMERIC COMPARISON FUNCTIONS           Page 29
  1855.  
  1856.  
  1857.             NUMERIC COMPARISON FUNCTIONS
  1858.  
  1859.             (< n1 n2...)
  1860.             (= n1 n2...)
  1861.             (> n1 n2...)
  1862.             <<= n1 n2...)
  1863.             (>= n1 n2...)
  1864.  
  1865.                 These functions compare numbers and return #t if the
  1866.                 numbers match the predicate and #f otherwise.  For
  1867.                 instance, (< x y z) will return #t if x is less than y
  1868.                 and y is less than z.
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.         XSCHEME            BITWISE LOGICAL FUNCTIONS             Page 30
  1921.  
  1922.  
  1923.             BITWISE LOGICAL FUNCTIONS
  1924.  
  1925.             (LOGAND n1 n2...)
  1926.  
  1927.                 Returns the bitwise AND of the integer arguments.
  1928.  
  1929.             (LOGIOR n1 n2...)
  1930.  
  1931.                 Returns the bitwise inclusive OR of the integer
  1932.                 arguments.
  1933.  
  1934.             (LOGXOR n1 n2...)
  1935.  
  1936.                 Returns the bitwise exclusive OR of the integer
  1937.                 arguments.
  1938.  
  1939.             (LOGNOT n)
  1940.  
  1941.                 Returns the bitwise complement of n.
  1942.  
  1943.  
  1944.  
  1945.  
  1946.  
  1947.  
  1948.  
  1949.  
  1950.  
  1951.  
  1952.  
  1953.  
  1954.  
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986.         XSCHEME                 STRING FUNCTIONS                 Page 31
  1987.  
  1988.  
  1989.             STRING FUNCTIONS
  1990.  
  1991.             (STRING-LENGTH str)
  1992.  
  1993.                 Returns the length of the string.
  1994.  
  1995.             (STRING-NULL? str)
  1996.  
  1997.                 Returns #t if the string has a length of zero and #f
  1998.                 otherwise.
  1999.  
  2000.             (STRING-APPEND str1...)
  2001.  
  2002.                 Returns the result of appending the string arguments.
  2003.                 If no arguments are supplied, it returns the null
  2004.                 string.
  2005.  
  2006.             (STRING-REF str n)
  2007.  
  2008.                 Returns the nth character in a string.
  2009.  
  2010.             (SUBSTRING str start end)
  2011.  
  2012.                 Returns the substring of str starting at start and
  2013.                 ending at end (integers).  The range is inclusive of
  2014.                 start and exclusive of end.
  2015.  
  2016.  
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.         XSCHEME           STRING COMPARISON FUNCTIONS            Page 32
  2053.  
  2054.  
  2055.             STRING COMPARISON FUNCTIONS
  2056.  
  2057.             (STRING<? str1 str2)
  2058.             (STRING=? str1 str2)
  2059.             (STRING>? str1 str2)
  2060.             (STRING<=? str1 str2)
  2061.             (STRING>=? str1 str2)
  2062.  
  2063.                 These functions compare strings and return #t if the
  2064.                 strings match the predicate and #f otherwise.  For
  2065.                 instance, (STRING< x y) will return #t if x is less than
  2066.                 y.  Case is significant.  #A does not match #a.
  2067.  
  2068.             (STRING-CI<? str1 str2)
  2069.             (STRING-CI=? str1 str2)
  2070.             (STRING-CI>? str1 str2)
  2071.             (STRING-CI<=? str1 str2)
  2072.             (STRING-CI>=? str1 str2)
  2073.  
  2074.                 These functions compare strings and return #t if the
  2075.                 strings match the predicate and #f otherwise.  For
  2076.                 instance, (STRING-CI< x y) will return #t if x is less
  2077.                 than y.  Case is not significant.  #A matches #a.
  2078.  
  2079.  
  2080.  
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.  
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118.         XSCHEME          CHARACTER COMPARISON FUNCTIONS          Page 33
  2119.  
  2120.  
  2121.             CHARACTER COMPARISON FUNCTIONS
  2122.  
  2123.             (CHAR<? ch1 ch2)
  2124.             (CHAR=? ch1 ch2)
  2125.             (CHAR>? ch1 ch2)
  2126.             (CHAR<=? ch1 ch2)
  2127.             (CHAR>=? ch1 ch2)
  2128.  
  2129.                 These functions compare characters and return #t if the
  2130.                 characters match the predicate and #f otherwise.  For
  2131.                 instance, (CHAR< x y) will return #t if x is less than
  2132.                 y.  Case is significant.  #A does not match #a.
  2133.  
  2134.             (CHAR-CI<? ch1 ch2)
  2135.             (CHAR-CI=? ch1 ch2)
  2136.             (CHAR-CI>? ch1 ch2)
  2137.             (CHAR-CI<=? ch1 ch2)
  2138.             (CHAR-CI>=? ch1 ch2)
  2139.  
  2140.                 These functions compare characters and return #t if the
  2141.                 characters match the predicate and #f otherwise.  For
  2142.                 instance, (CHAR-CI< x y) will return #t if x is less
  2143.                 than y.  Case is not significant.  #A matchs #a.
  2144.  
  2145.  
  2146.  
  2147.  
  2148.  
  2149.  
  2150.  
  2151.  
  2152.  
  2153.  
  2154.  
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.  
  2161.  
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184.         XSCHEME              INPUT/OUTPUT FUNCTIONS              Page 34
  2185.  
  2186.  
  2187.             INPUT/OUTPUT FUNCTIONS
  2188.  
  2189.             (READ [port])
  2190.  
  2191.                 Reads an expression from the specified port.  If no port
  2192.                 is specified, the current input port is used.  Returns
  2193.                 the expression read or an object that satisfies the
  2194.                 default-object? predicate if it reaches the end of file
  2195.                 on the port.
  2196.  
  2197.             (READ-CHAR [port])
  2198.  
  2199.                 Reads a character from the specified port.  If no port
  2200.                 is specified, the current input port is used.  Returns
  2201.                 the character read or an object that satisfies the
  2202.                 default-object? predicate if it reaches the end of file
  2203.                 on the port.
  2204.  
  2205.             (READ-BYTE [port])
  2206.  
  2207.                 Reads a byte from the specified port.  If no port is
  2208.                 specified, the current input port is used.  Returns the
  2209.                 byte read or an object that satisfies the default-
  2210.                 object? predicate if it reaches the end of file on the
  2211.                 port.
  2212.  
  2213.             (WRITE expr [port])
  2214.             (PRIN1 expr [port])
  2215.  
  2216.                 Writes an expression to the specified port.  If no port
  2217.                 is specified, the current output port is used.  The
  2218.                 expression is written such that the READ function can
  2219.                 read it back.  This means that strings will be enclosed
  2220.                 in quotes and characters will be printed with #
  2221.                 notation.
  2222.  
  2223.             (WRITE-CHAR ch [port])
  2224.  
  2225.                 Writes a character to the specified port.  If no port is
  2226.                 specified, the current output port is used.
  2227.  
  2228.             (WRITE-BYTE ch [port])
  2229.  
  2230.                 Writes a byte to the specified port.  If no port is
  2231.                 specified, the current output port is used.
  2232.  
  2233.             (DISPLAY expr [port])
  2234.             (PRINC expr [port])
  2235.  
  2236.                 Writes an expression to the specified port.  If no port
  2237.                 is specified, the current output port is used.  The
  2238.                 expression is written without any quoting characters.
  2239.                 No quotes will appear around strings and characters are
  2240.                 written without the # notation.
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250.         XSCHEME              INPUT/OUTPUT FUNCTIONS              Page 35
  2251.  
  2252.  
  2253.             (NEWLINE [port])
  2254.  
  2255.                 Starts a new line on the specified port.  If no port is
  2256.                 specified, the current output port is used.
  2257.  
  2258.  
  2259.  
  2260.  
  2261.  
  2262.  
  2263.  
  2264.  
  2265.  
  2266.  
  2267.  
  2268.  
  2269.  
  2270.  
  2271.  
  2272.  
  2273.  
  2274.  
  2275.  
  2276.  
  2277.  
  2278.  
  2279.  
  2280.  
  2281.  
  2282.  
  2283.  
  2284.  
  2285.  
  2286.  
  2287.  
  2288.  
  2289.  
  2290.  
  2291.  
  2292.  
  2293.  
  2294.  
  2295.  
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  
  2315.  
  2316.         XSCHEME             OUTPUT CONTROL FUNCTIONS             Page 36
  2317.  
  2318.  
  2319.             OUTPUT CONTROL FUNCTIONS
  2320.  
  2321.             (PRINT-BREADTH [n])
  2322.  
  2323.                 Controls the maximum number of elements of a list that
  2324.                 will be printed.  If n is an integer, the maximum number
  2325.                 is set to n.  If it is #f, the limit is set to infinity.
  2326.                 This is the default.  If n is omitted from the call, the
  2327.                 current value is returned.
  2328.  
  2329.             (PRINT-DEPTH [n])
  2330.  
  2331.                 Controls the maximum number of levels of a nested list
  2332.                 that will be printed.  If n is an integer, the maximum
  2333.                 number is set to n.  If it is #f, the limit is set to
  2334.                 infinity.  This is the default.  If n is omitted from
  2335.                 the call, the current value is returned.
  2336.  
  2337.  
  2338.  
  2339.  
  2340.  
  2341.  
  2342.  
  2343.  
  2344.  
  2345.  
  2346.  
  2347.  
  2348.  
  2349.  
  2350.  
  2351.  
  2352.  
  2353.  
  2354.  
  2355.  
  2356.  
  2357.  
  2358.  
  2359.  
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.  
  2381.  
  2382.         XSCHEME                FILE I/O FUNCTIONS                Page 37
  2383.  
  2384.  
  2385.             FILE I/O FUNCTIONS
  2386.  
  2387.             All four of the following OPEN functions take an optional
  2388.             argument to indicate that file I/O is to be done in binary
  2389.             mode.  For binary files, this argument should be the symbol
  2390.             BINARY.  For text files, the argument can be left out or the
  2391.             symbol TEXT can be supplied.
  2392.  
  2393.             (OPEN-INPUT-FILE str ['binary])
  2394.  
  2395.                 Opens the file named by the string and returns an input
  2396.                 port.
  2397.  
  2398.             (OPEN-OUTPUT-FILE str ['binary])
  2399.  
  2400.                 Creates the file named by the string and returns an
  2401.                 output port.
  2402.  
  2403.             (OPEN-APPEND-FILE str ['binary])
  2404.  
  2405.                 Opens the file named by the string for appending returns
  2406.                 an output port.
  2407.  
  2408.             (OPEN-UPDATE-FILE str ['binary])
  2409.  
  2410.                 Opens the file named by the string for input and output
  2411.                 and returns an input/output port.
  2412.  
  2413.             (GET-FILE-POSITION port)
  2414.  
  2415.                 Returns the current file position as an offset in bytes
  2416.                 from the beginning of the file.
  2417.  
  2418.             (SET-FILE-POSITION! port offset whence)
  2419.  
  2420.                 Sets the current file position as an offset in bytes
  2421.                 from the beginning of the file (when whence equals 0),
  2422.                 the current file position (when whence equals 1) or the
  2423.                 end of the file (when whence equals 2).  Returns the new
  2424.                 file position as an offset from the start of the file.
  2425.  
  2426.             (CLOSE-PORT port)
  2427.  
  2428.                 Closes any port.
  2429.  
  2430.             (CLOSE-INPUT-PORT port)
  2431.  
  2432.                 Closes an input port.
  2433.  
  2434.             (CLOSE-OUTPUT-PORT port)
  2435.  
  2436.                 Closes an output port.
  2437.  
  2438.  
  2439.  
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.  
  2447.  
  2448.         XSCHEME                FILE I/O FUNCTIONS                Page 38
  2449.  
  2450.  
  2451.             (CALL-WITH-INPUT-FILE str proc)
  2452.  
  2453.                 Open the file whose name is specifed by str and call
  2454.                 proc passing the resulting input port as an argument.
  2455.                 When proc returns, close the file and return the value
  2456.                 returned by proc as the result.
  2457.  
  2458.             (CALL-WITH-OUTPUT-FILE str proc)
  2459.  
  2460.                 Create the file whose name is specifed by str and call
  2461.                 proc passing the resulting output port as an argument.
  2462.                 When proc returns, close the file and return the value
  2463.                 returned by proc as the result.
  2464.  
  2465.             (CURRENT-INPUT-PORT)
  2466.  
  2467.                 Returns the current input port.
  2468.  
  2469.             (CURRENT-OUTPUT-PORT)
  2470.  
  2471.                 Returns the current output port.
  2472.  
  2473.  
  2474.  
  2475.  
  2476.  
  2477.  
  2478.  
  2479.  
  2480.  
  2481.  
  2482.  
  2483.  
  2484.  
  2485.  
  2486.  
  2487.  
  2488.  
  2489.  
  2490.  
  2491.  
  2492.  
  2493.  
  2494.  
  2495.  
  2496.  
  2497.  
  2498.  
  2499.  
  2500.  
  2501.  
  2502.  
  2503.  
  2504.  
  2505.  
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  
  2513.  
  2514.         XSCHEME                 CONTROL FEATURES                 Page 39
  2515.  
  2516.  
  2517.             CONTROL FEATURES
  2518.  
  2519.             (EVAL expr)
  2520.  
  2521.                 Evaluate the expression in the global environment and
  2522.                 return its value.
  2523.  
  2524.             (APPLY proc args)
  2525.  
  2526.                 Apply the procedure to the list of arguments and return
  2527.                 the result.
  2528.  
  2529.             (MAP proc list...)
  2530.  
  2531.                 Apply the procedure to argument lists formed by taking
  2532.                 corresponding elements from each list.  Form a list from
  2533.                 the resulting values and return that list as the result
  2534.                 of the MAP call.
  2535.  
  2536.             (FOR-EACH fun list...)
  2537.  
  2538.                 Apply the procedure to argument lists formed by taking
  2539.                 corresponding elements from each list.  The values
  2540.                 returned by the procedure applications are discarded.
  2541.                 The value returned by FOR-EACH is unspecified.
  2542.  
  2543.             (CALL-WITH-CURRENT-CONTINUATION proc)
  2544.             (CALL/CC proc)
  2545.  
  2546.                 Form an "escape procedure" from the current continuation
  2547.                 and pass it as an argument to proc.  Calling the escape
  2548.                 procedure with a single argument will cause that
  2549.                 argument to be passed to the continuation that was in
  2550.                 effect when the CALL-WITH-CURRENT-CONTINUATION procedure
  2551.                 was called.
  2552.  
  2553.  
  2554.  
  2555.  
  2556.  
  2557.  
  2558.  
  2559.  
  2560.  
  2561.  
  2562.  
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.  
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.  
  2579.  
  2580.         XSCHEME              ENVIRONMENT FUNCTIONS               Page 40
  2581.  
  2582.  
  2583.             ENVIRONMENT FUNCTIONS
  2584.  
  2585.             (THE-ENVIRONMENT)
  2586.  
  2587.                 Returns the current environment.
  2588.  
  2589.             (PROCEDURE-ENVIRONMENT proc)
  2590.  
  2591.                 Returns the environment from a procedure closure.
  2592.  
  2593.             (ENVIRONMENT-BINDINGS env)
  2594.  
  2595.                 Returns an association list corresponding to the top
  2596.                 most frame of the specified environment.
  2597.  
  2598.             (ENVIRONMENT-PARENT env)
  2599.  
  2600.                 Returns the parent environment of the specified
  2601.                 environment.
  2602.  
  2603.  
  2604.  
  2605.  
  2606.  
  2607.  
  2608.  
  2609.  
  2610.  
  2611.  
  2612.  
  2613.  
  2614.  
  2615.  
  2616.  
  2617.  
  2618.  
  2619.  
  2620.  
  2621.  
  2622.  
  2623.  
  2624.  
  2625.  
  2626.  
  2627.  
  2628.  
  2629.  
  2630.  
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.  
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.  
  2645.  
  2646.         XSCHEME                UTILITY FUNCTIONS                 Page 41
  2647.  
  2648.  
  2649.             UTILITY FUNCTIONS
  2650.  
  2651.             (LOAD str)
  2652.  
  2653.                 Read and evaluate each expression from the specified
  2654.                 file.
  2655.  
  2656.             (LOAD-NOISILY str)
  2657.  
  2658.                 Read and evaluate each expression from the specified
  2659.                 file and print the results to the current output port.
  2660.  
  2661.             (TRANSCRIPT-ON str)
  2662.  
  2663.                 Opens a transcript file with the specified name and
  2664.                 begins logging the interactive session to that file.
  2665.  
  2666.             (TRANSCRIPT-OFF)
  2667.  
  2668.                 Closes the current transcript file.
  2669.  
  2670.             (EXIT)
  2671.  
  2672.                 Exits from XScheme back to the operating system.
  2673.  
  2674.             (GC [ni vi])
  2675.  
  2676.                 Invokes the garbage collector and returns information on
  2677.                 memory usage.  If ni and vi are specified, they must be
  2678.                 integers.  Node and vector space are expanded by those
  2679.                 amounts respectively and no garbage collection is
  2680.                 triggered.  GC returns an array of six values: the
  2681.                 number of calls to the garbage collector, the total
  2682.                 number of nodes, the current number of free nodes, the
  2683.                 number of node segments, the number of vector segments
  2684.                 and the total number of bytes allocated to the heap.
  2685.  
  2686.             (RESET)
  2687.  
  2688.                 Returns to the top level read/eval/print loop.
  2689.  
  2690.  
  2691.  
  2692.  
  2693.  
  2694.  
  2695.  
  2696.  
  2697.  
  2698.  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.  
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.  
  2711.  
  2712.         XSCHEME                 SYSTEM FUNCTIONS                 Page 42
  2713.  
  2714.  
  2715.             SYSTEM FUNCTIONS
  2716.  
  2717.             (%CAR pair)
  2718.             (%CDR pair)
  2719.             (%SET-CAR! pair expr)
  2720.             (%SET-CDR! pair expr)
  2721.             (%VECTOR-LENGTH vect)
  2722.             (%VECTOR-REF vect n)
  2723.             (%VECTOR-SET! vect n expr)
  2724.  
  2725.                 These functions do the same as their counterparts
  2726.                 without the leading '%' character.  The difference is
  2727.                 that they don't check the type of their first argument.
  2728.                 This makes it possible to examine data structures that
  2729.                 have the same internal representation as pairs and
  2730.                 vectors.  It is *very* dangerous to modify objects using
  2731.                 these functions and there is no guarantee that future
  2732.                 releases of XScheme will represent objects in the same
  2733.                 way that the current version does.
  2734.  
  2735.  
  2736.  
  2737.  
  2738.  
  2739.  
  2740.  
  2741.  
  2742.  
  2743.  
  2744.  
  2745.  
  2746.  
  2747.  
  2748.  
  2749.  
  2750.  
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.  
  2757.  
  2758.  
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.  
  2767.  
  2768.  
  2769.  
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.  
  2777.  
  2778.         XSCHEME              OBJECT REPRESENTATIONS              Page 43
  2779.  
  2780.  
  2781.                 OBJECT REPRESENTATIONS
  2782.  
  2783.                 This version of XScheme uses the following object
  2784.                 representations:
  2785.  
  2786.                     Closures are represented as pairs.  The car of the
  2787.                     pair is the compiled function and the cdr of the
  2788.                     pair is the saved environment.
  2789.  
  2790.                     Compiled functions are represented as vectors.  The
  2791.                     element at offset 0 is the bytecode string.  The
  2792.                     element at offset 1 is the function name.  The
  2793.                     element at offset 2 is a list of names of the
  2794.                     function arguments.  The elements at offsets above 2
  2795.                     are the literals refered to by the compiled
  2796.                     bytecodes.
  2797.  
  2798.                     Environments are represented as lists of vectors.
  2799.                     Each vector is an environment frame.  The element at
  2800.                     offset 0 is a list of the symbols that are bound in
  2801.                     that frame.  The symbol values start at offset 1.
  2802.  
  2803.                     Objects are represented as vectors.  The element at
  2804.                     offset 0 is the class of the object.  The remaining
  2805.                     elements are the object's instance variable values.
  2806.  
  2807.  
  2808.  
  2809.  
  2810.  
  2811.  
  2812.  
  2813.  
  2814.  
  2815.  
  2816.  
  2817.  
  2818.  
  2819.  
  2820.  
  2821.  
  2822.  
  2823.  
  2824.  
  2825.  
  2826.  
  2827.  
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.  
  2835.  
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.