home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / XSCHEME2.ZIP / xscheme.doc < prev    next >
Text File  |  1991-02-08  |  56KB  |  2,839 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.                        XSCHEME: An Object-oriented Scheme
  8.  
  9.                                   Version 0.25
  10.  
  11.                                 February 8, 1991
  12.  
  13.  
  14.                                        by
  15.                                David Michael Betz
  16.                                   P.O. Box 144
  17.                              Peterborough, NH 03458
  18.  
  19.                              (603) 924-4145 (home)
  20.  
  21.                    Copyright (c) 1991, by David Michael Betz
  22.                               All Rights Reserved
  23.            Permission is granted for unrestricted non-commercial use
  24.  
  25.  
  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.         XSCHEME                TABLE OF CONTENTS                  Page 2
  71.  
  72.  
  73.         TABLE OF CONTENTS
  74.  
  75.             TABLE OF CONTENTS..................................2
  76.             INTRODUCTION.......................................3
  77.             A NOTE FROM THE AUTHOR.............................4
  78.             EXPRESSIONS........................................5
  79.             BINDING FORMS.....................................10
  80.             SEQUENCING........................................11
  81.             DELAYED EVALUATION................................12
  82.             ITERATION.........................................13
  83.             DEFINITIONS.......................................14
  84.             LIST FUNCTIONS....................................15
  85.             DESTRUCTIVE LIST FUNCTIONS........................17
  86.             SYMBOL FUNCTIONS..................................18
  87.             VECTOR FUNCTIONS..................................19
  88.             ARRAY FUNCTIONS...................................20
  89.             CONVERSION FUNCTIONS..............................21
  90.             TYPE PREDICATES...................................22
  91.             EQUALITY PREDICATES...............................25
  92.             ARITHMETIC FUNCTIONS..............................26
  93.             NUMERIC COMPARISON FUNCTIONS......................29
  94.             BITWISE LOGICAL FUNCTIONS.........................30
  95.             STRING FUNCTIONS..................................31
  96.             STRING COMPARISON FUNCTIONS.......................32
  97.             CHARACTER COMPARISON FUNCTIONS....................33
  98.             INPUT/OUTPUT FUNCTIONS............................34
  99.             OUTPUT CONTROL FUNCTIONS..........................36
  100.             FILE I/O FUNCTIONS................................37
  101.             CONTROL FEATURES..................................39
  102.             ENVIRONMENT FUNCTIONS.............................40
  103.             UTILITY FUNCTIONS.................................41
  104.             SYSTEM FUNCTIONS..................................42
  105.             OBJECT REPRESENTATIONS............................43
  106.  
  107.  
  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.         XSCHEME                   INTRODUCTION                    Page 3
  137.  
  138.  
  139.         XScheme is an implementation of the Scheme programming language
  140.         with extensions to support object-oriented programming.
  141.  
  142.         There are currently implementations of XScheme running on the
  143.         IBM-PC and clones under MS-DOS, on the Macintosh, the Atari-ST
  144.         and the Amiga.  It is completely written in the programming
  145.         language 'C' and is easily extended with user written built-in
  146.         functions and classes.  It is available in source form to non-
  147.         commercial users.
  148.  
  149.         This document is a brief description of XScheme.  XScheme
  150.         follows the "Revised^3 Report on the Algorithmic Language
  151.         Scheme".  It assumes some knowledge of Scheme or LISP and some
  152.         understanding of the concepts of object-oriented programming.
  153.  
  154.         I recommend the book "Structure and Interpretation of Computer
  155.         Programs" by Harold Abelson and Gerald Jay Sussman and published
  156.         by The MIT Press and the McGraw-Hill Book Company for learning
  157.         Scheme (and programming in general).  You might also find "The
  158.         Scheme Programming Language" by R. Kent Dybvig and "The Little
  159.         Lisper" by Daniel P. Friedman and Matthias Felleisen to be
  160.         helpful.
  161.  
  162.  
  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.         XSCHEME              A NOTE FROM THE AUTHOR               Page 4
  203.  
  204.  
  205.         A NOTE FROM THE AUTHOR
  206.  
  207.         If you have any problems with XScheme, feel free to contact me
  208.         for help or advice.  Please remember that since XScheme is
  209.         available in source form in a high level language, many users
  210.         have been making versions available on a variety of machines.
  211.         If you call to report a problem with a specific version, I may
  212.         not be able to help you if that version runs on a machine to
  213.         which I don't have access.  Please have the version number of
  214.         the version that you are running readily accessible before
  215.         calling me.
  216.  
  217.         If you find a bug in XScheme, first try to fix the bug yourself
  218.         using the source code provided.  If you are successful in fixing
  219.         the bug, send the bug report along with the fix to me.  If you
  220.         don't have access to a C compiler or are unable to fix a bug,
  221.         please send the bug report to me and I'll try to fix it.
  222.  
  223.         Any suggestions for improvements will be welcomed.  Feel free to
  224.         extend the language in whatever way suits your needs.  However,
  225.         PLEASE DO NOT RELEASE ENHANCED VERSIONS WITHOUT CHECKING WITH ME
  226.         FIRST!!  I would like to be the clearing house for new features
  227.         added to XScheme.  If you want to add features for your own
  228.         personal use, go ahead.  But, if you want to distribute your
  229.         enhanced version, contact me first.
  230.  
  231.  
  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.         XSCHEME                   EXPRESSIONS                     Page 5
  269.  
  270.  
  271.         EXPRESSIONS
  272.  
  273.         <variable>
  274.  
  275.             An expression consisting of a variable is a variable
  276.             reference.  The value of the variable reference is the value
  277.             stored in the location to which the variable is bound.  It
  278.             is an error to reference an unbound variable.
  279.  
  280.         (QUOTE <datum>)
  281.         '<datum>
  282.  
  283.             (quote <datum>) evaluates to <datum>.  <Datum> may be any
  284.             external representation of a Scheme object.  This notation
  285.             is used to include literal constants in Scheme code.  (quote
  286.             <datum>) may be abbreviated as '<datum>.  The two notations
  287.             are equivalent in all respects.
  288.  
  289.         <constant>
  290.  
  291.             Numeric constants, string constants, character constants,
  292.             and boolean constants evaluate "to themselves"; they need
  293.             not be quoted.
  294.  
  295.         (<operator> <operand>...)
  296.  
  297.             A procedure call is written by simply enclosing in
  298.             parentheses expressions for the procedure to be called and
  299.             the arguments to be passed to it.  The operator and operand
  300.             expressions are evaluated and the resulting procedure is
  301.             passed the resulting arguments.
  302.  
  303.         (<object> <selector> <operand>...)
  304.  
  305.             A message sending form is written by enclosing in
  306.             parentheses expressions for the receiving object, the
  307.             message selector, and the arguments to be passed to the
  308.             method.  The receiver, selector, and argument expressions
  309.             are evaluated, the message selector is used to select an
  310.             appropriate method to handle the message, and the resulting
  311.             method is passed the resulting arguments.
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.         XSCHEME                   EXPRESSIONS                     Page 6
  335.  
  336.  
  337.         (LAMBDA <formals> <body>)
  338.  
  339.             <Formals> should be a formal argument list as described
  340.             below, and <body>  should be a sequence of one or more
  341.             expressions.  A lambda expression evaluates to a procedure.
  342.             The environment in effect when the lambda expression is
  343.             evaluated is remembered as part of the procedure.  When the
  344.             procedure is later called with some actual arguments, the
  345.             environment in which the lambda expression was evaluated
  346.             will be extended by binding the variables in the formal
  347.             argument list to fresh locations, the corresponding actual
  348.             argument values will be stored in those locations, and the
  349.             expressions in the body of the lambda expression will be
  350.             evaluated sequentially in the extended environment.  The
  351.             result of the last expression in the body will be returned
  352.             as the result of the procedure call.
  353.  
  354.             <Formals> should have the following form:
  355.  
  356.                 (<var>... [#!OPTIONAL <ovar>...] [. <rvar>])
  357.               or
  358.                 (<var>... [#!OPTIONAL <ovar>...] [#!REST <rvar>])
  359.  
  360.               where:
  361.  
  362.                 <var>    is a required argument
  363.                 <ovar>   is an optional argument
  364.                 <rvar>   is a "rest" argument
  365.  
  366.             There are three parts to a <formals> list.  The first lists
  367.             the required arguments of the procedure.  All calls to the
  368.             procedure must supply values for each of the required
  369.             arguments.  The second part lists the optional arguments of
  370.             the procedure.  An optional argument may be supplied in a
  371.             call or omitted.  If it is omitted, a special value is given
  372.             to the argument that satisfies the default-object?
  373.             predicate.  This provides a way to test to see if an
  374.             optional argument was provided in a call or omitted.  The
  375.             last part of the <formals> list gives the "rest" argument.
  376.             This argument will be bound to the rest of the list of
  377.             arguments supplied to a call after the required and optional
  378.             arguments have been removed.
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.         XSCHEME                   EXPRESSIONS                     Page 7
  401.  
  402.  
  403.         (IF <test> <consequent> [<alternate>])
  404.  
  405.             An if expression is evaluated as follows:  first, <test> is
  406.             evaluated.  If it yields a true value, then <consequent> is
  407.             evaluated and its value is returned.  Otherwise, <alternate>
  408.             is evaluated and its value is returned.  If <test> yields a
  409.             false value and no <alternate> is specified, then the result
  410.             of the expression is unspecified.
  411.  
  412.         (ACCESS <variable> <env>)
  413.  
  414.             <Env> is evaluated producing an environment.  The result is
  415.             the value of <variable> in this environment.
  416.  
  417.         (SET! <variable> <expression>)
  418.  
  419.             <Expression> is evaluated, and the resulting value is stored
  420.             in the location to which <variable> is bound.  <Variable>
  421.             must be bound in some region or at the top level. The result
  422.             of the set! expression is unspecified.
  423.  
  424.         (SET! (ACCESS <variable> <env>) <value>)
  425.  
  426.             <Env> is evaluated producing an environment.  <Value> is
  427.             evaluated and the resulting value is stored as the value of
  428.             <variable> in this environment.  The result of the set!
  429.             expression is unspecified.
  430.  
  431.  
  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.         XSCHEME                   EXPRESSIONS                     Page 8
  467.  
  468.  
  469.         (COND <clause>...)
  470.  
  471.             Each clause should be of the form
  472.  
  473.                 (<test> <expression>...)
  474.  
  475.             where <test> is any expression.  The last <clause> may be an
  476.             "else clause," which has the form
  477.  
  478.                 (ELSE <expression>...)
  479.  
  480.             A cond expression is evaluated by evaluating the <test>
  481.             expressions of successive <clause>s in order until one of
  482.             them evaluates to a true value.  When a <test> evaluates to
  483.             a true value, then the remaining <expression>s in its
  484.             <clause> are evaluated in order, and the result of the last
  485.             <expression> in the <clause> is returned as the result of
  486.             the entire cond expression.  If the selected <clause>
  487.             contains only the <test> and no <expression>s, then the
  488.             value of the <test> is returned as the result.  If all
  489.             <test>s evaluate to false values, and there is no else
  490.             clause, then the result of the conditional expression is
  491.             unspecified; if there is an else clause, then its
  492.             <expression>s are evaluated, and the value of the last one
  493.             is returned.
  494.  
  495.  
  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.         XSCHEME                   EXPRESSIONS                     Page 9
  533.  
  534.  
  535.         (AND <test>...)
  536.  
  537.             The <test> expressions are evaluated from left to right, and
  538.             the value of the first expression that evaluates to a false
  539.             value is returned.  Any remaining expressions are not
  540.             evaluated.  If all the expressions evaluate to true values,
  541.             the value of the last expression is returned.  If there are
  542.             no expressions then #t is returned.
  543.  
  544.         (OR <test>...)
  545.  
  546.             The <test> expressions are evaluated from left to right, and
  547.             the value of the first expression that evaluates to a true
  548.             value is returned.  Any remaining expressions are not
  549.             evaluated.  If all expressions evaluate to false values, the
  550.             value of the last expression is returned.  If there are no
  551.             expressions then #f is returned.
  552.  
  553.  
  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.         XSCHEME                  BINDING FORMS                   Page 10
  599.  
  600.  
  601.         BINDING FORMS
  602.  
  603.         (LET [<name>] <bindings> <body>)
  604.  
  605.             <Bindings> should have the form
  606.  
  607.                 ((<variable> <init>)...)
  608.  
  609.             where each <init> is an expression, and <body> should be a
  610.             sequence of one or more expressions.  The <init>s are
  611.             evaluated in the current envirnoment, the <variable>s are
  612.             bound to fresh locations holding the results, the <body> is
  613.             evaluated in the extended environment, and the value of the
  614.             last expression of <body> is returned.  Each binding of a
  615.             <variable> has <body> as its region.
  616.  
  617.             If a name is supplied, a procedure that takes the bound
  618.             variables as its arguments and has the body of the LET as
  619.             its body is bound to that name.
  620.  
  621.         (LET* <bindings> <body>)
  622.  
  623.             Same as LET except that the bindings are done sequentially
  624.             from left to right and the bindings to the left are visible
  625.             while evaluating the initialization expressions for each
  626.             variable.
  627.  
  628.         (LETREC <bindings> <body>)
  629.  
  630.             <Bindings> should have the form
  631.  
  632.                 ((<variable> <init>)...)
  633.  
  634.             and <body> should be a sequence of one or more expressions.
  635.             The <variable>s are bound to fresh locations holding
  636.             undefined values; the <init>s are evaluated in the resulting
  637.             environment; each <variable>  is assigned to the result of
  638.             the corresponding <init>; the <body> is evaluated in the
  639.             resulting environment; and the value of the last expression
  640.             in <body> is returned.  Each binding of a <variable> has the
  641.             entire letrec expression as its region, making it possible
  642.             to define mutually recursive procedures.  One restriction of
  643.             letrec is very important:  it must be possible to evaluate
  644.             each <init> without referring to the value of any
  645.             <variable>.  If this restriction is violated, then the
  646.             effect is undefined, and an error may be signalled during
  647.             evaluation of the <init>s.  The restriction is necessary
  648.             because Scheme passes arguments by value rather than by
  649.             name.  In the most common uses of letrec, all the <init>s
  650.             are lambda expressions and the restriction is satisfied
  651.             automatically.
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.         XSCHEME                    SEQUENCING                    Page 11
  665.  
  666.  
  667.             SEQUENCING
  668.  
  669.             (BEGIN <expression>...)
  670.             (SEQUENCE <expression>...)
  671.  
  672.                 The <expression>s are evaluated sequentially from left
  673.                 to right, and the value of the last <expression> is
  674.                 returned.  This expression type is used to sequence side
  675.                 effects such as input and output.
  676.  
  677.  
  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.         XSCHEME                DELAYED EVALUATION                Page 12
  731.  
  732.  
  733.             DELAYED EVALUATION
  734.  
  735.             (CONS-STREAM expr1 expr2)
  736.  
  737.                 Create a cons stream whose head is expr1 (which is
  738.                 evaluated immediately) and whose tail is expr2 (whose
  739.                 evaluation is delayed until TAIL is called).  To use
  740.                 CONS-STREAM, enter the following access procedures:
  741.  
  742.                     (define head car)
  743.                     (define (tail stream) (force (cdr stream)))
  744.  
  745.             (DELAY <expression>)
  746.  
  747.                 Evaluating this expression creates a "promise" to
  748.                 evaluate <expression>  at a later time.
  749.  
  750.             (FORCE promise)
  751.  
  752.                 Applying FORCE to a promise generated by DELAY requests
  753.                 that the promise produce the value of the expression
  754.                 passed to DELAY.  The first time a promise is FORCEed,
  755.                 the DELAY expression is evaluated and the value stored.
  756.                 On subsequent calls to FORCE with the same promise, the
  757.                 saved value is returned.
  758.  
  759.  
  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.         XSCHEME                    ITERATION                     Page 13
  797.  
  798.  
  799.             ITERATION
  800.  
  801.             (WHILE <test> <expression>...)
  802.  
  803.                 While is an iteration construct.  Each iteration begins
  804.                 by evaluating <test>; if the result is false, then the
  805.                 loop terminates and the value of <test> is returned as
  806.                 the value of the while expression.  If <test>  evaluates
  807.                 to a true value, then the <expression>s are evaluated in
  808.                 order for effect and the next iteration begins.
  809.  
  810.  
  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.         XSCHEME                   DEFINITIONS                    Page 14
  863.  
  864.  
  865.             DEFINITIONS
  866.  
  867.             (DEFINE <variable> <expression>)
  868.  
  869.                 Define a variable and give it an initial value.
  870.  
  871.             (DEFINE (<variable> <formals>) <body>)
  872.  
  873.                 Define a procedure.
  874.  
  875.  
  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.         XSCHEME                  LIST FUNCTIONS                  Page 15
  929.  
  930.  
  931.             LIST FUNCTIONS
  932.  
  933.             (CONS expr1 expr2)
  934.  
  935.                 Create a new pair whose car is expr1 and whose cdr is
  936.                 expr2.
  937.  
  938.             (CAR pair)
  939.  
  940.                 Extract the car of a pair.
  941.  
  942.             (CDR pair)
  943.  
  944.                 Extract the cdr of a pair.
  945.  
  946.             (CxxR pair)
  947.             (CxxxR pair)
  948.             (CxxxxR pair)
  949.  
  950.                 These functions are short for combinations of CAR and
  951.                 CDR.  Each 'x' is stands for either 'A' or 'D'.  An 'A'
  952.                 stands for the CAR function and a 'D' stands for the CDR
  953.                 function.  For instance, (CADR x) is the same as (CAR
  954.                 (CDR x)).
  955.  
  956.             (LIST expr...)
  957.  
  958.                 Create a list whose elements are the arguments to the
  959.                 function.  This function can take an arbitrary number of
  960.                 arguments.  Passing no arguments results in the empty
  961.                 list.
  962.  
  963.             (LIST* expr...)
  964.  
  965.                 Create a list whose elements are the arguments to the
  966.                 function except that the last argument is used as the
  967.                 tail of the list.  This means that the call (LIST* 1 2
  968.                 3) produce the result (1 2 . 3).
  969.  
  970.             (APPEND list...)
  971.  
  972.                 Append lists to form a single list.  This function takes
  973.                 an arbitrary number of arguments.  Passing no arguments
  974.                 results in the empty list.
  975.  
  976.             (REVERSE list)
  977.  
  978.                 Create a list whose elements are the same as the
  979.                 argument except in reverse order.
  980.  
  981.             (LAST-PAIR list)
  982.  
  983.                 Return the last pair in a list.
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.         XSCHEME                  LIST FUNCTIONS                  Page 16
  995.  
  996.  
  997.             (LENGTH list)
  998.  
  999.                 Compute the length of a list.
  1000.  
  1001.             (MEMBER expr list)
  1002.             (MEMV expr list)
  1003.             (MEMQ expr list)
  1004.  
  1005.                 Find an element in a list.  Each of these functions
  1006.                 searches the list looking for an element that matches
  1007.                 expr.  If a matching element is found, the remainder of
  1008.                 the list starting with that element is returned.  If no
  1009.                 matching element is found, the empty list is returned.
  1010.                 The functions differ in the test used to determine if an
  1011.                 element matches expr.  The MEMBER function uses EQUAL?,
  1012.                 the MEMV function uses EQV?  and the MEMQ function uses
  1013.                 EQ?.
  1014.  
  1015.             (ASSOC expr alist)
  1016.             (ASSV expr alist)
  1017.             (ASSQ expr alist)
  1018.  
  1019.                 Find an entry in an association list.  An association
  1020.                 list is a list of pairs.  The car of each pair is the
  1021.                 key and the cdr is the value.  These functions search an
  1022.                 association list for a pair whose key matches expr.  If
  1023.                 a matching pair is found, it is returned.  Otherwise,
  1024.                 the empty list is returned.  The functions differ in the
  1025.                 test used to determine if a key matches expr.  The ASSOC
  1026.                 function uses EQUAL?, the ASSV function uses EQV?  and
  1027.                 the ASSQ function uses EQ?.
  1028.  
  1029.             (LIST-REF list n)
  1030.  
  1031.                 Return the nth element of a list (zero based).
  1032.  
  1033.             (LIST-TAIL list n)
  1034.  
  1035.                 Return the sublist obtained by removing the first n
  1036.                 elements of list.
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.         XSCHEME            DESTRUCTIVE LIST FUNCTIONS            Page 17
  1061.  
  1062.  
  1063.             DESTRUCTIVE LIST FUNCTIONS
  1064.  
  1065.             (SET-CAR! pair expr)
  1066.  
  1067.                 Set the car of a pair to expr.  The value returned by
  1068.                 this procedure is unspecified.
  1069.  
  1070.             (SET-CDR! pair expr)
  1071.  
  1072.                 Set the cdr of a pair to expr.  The value returned by
  1073.                 this procedure is unspecified.
  1074.  
  1075.  
  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.         XSCHEME                 SYMBOL FUNCTIONS                 Page 18
  1127.  
  1128.  
  1129.             SYMBOL FUNCTIONS
  1130.  
  1131.             (BOUND? sym)
  1132.  
  1133.                 Returns #t if a global value is bound to the symbol and
  1134.                 #f otherwise.
  1135.  
  1136.             (SYMBOL-VALUE sym)
  1137.  
  1138.                 Get the global value of a symbol.
  1139.  
  1140.             (SET-SYMBOL-VALUE! sym expr)
  1141.  
  1142.                 Set the global value of a symbol.  The value returned by
  1143.                 this procedure is unspecified.
  1144.  
  1145.             (SYMBOL-PLIST sym)
  1146.  
  1147.                 Get the property list associated with a symbol.
  1148.  
  1149.             (SET-SYMBOL-PLIST! sym plist)
  1150.  
  1151.                 Set the property list associate with a symbol.  The
  1152.                 value returned by this procedure is unspecified.
  1153.  
  1154.             (GENSYM [sym|str|num])
  1155.  
  1156.                 Generate a new, uninterned symbol.  The print name of
  1157.                 the symbol will consist of a prefix with a number
  1158.                 appended.  The initial prefix is "G" and the initial
  1159.                 number is 1.  If a symbol is specified as an argument,
  1160.                 the prefix is set to the print name of that symbol.  If
  1161.                 a string is specified, the prefix is set to that string.
  1162.                 If a number is specified, the numeric suffix is set to
  1163.                 that number.  After the symbol is generated, the number
  1164.                 is incremented so subsequent calls to GENSYM will
  1165.                 generate numbers in sequence.
  1166.  
  1167.             (GET sym prop)
  1168.  
  1169.                 Get the value of a property of a symbol.  The prop
  1170.                 argument is a symbol that is the property name.  If a
  1171.                 property with that name exists on the symbols property
  1172.                 list, the value of the property is returned.  Otherwise,
  1173.                 the empty list is returned.
  1174.  
  1175.             (PUT sym prop expr)
  1176.  
  1177.                 Set the value of a property of a symbol.  The prop
  1178.                 argument is a symbol that is the property name.  The
  1179.                 property/value combination is added to the property list
  1180.                 of the symbol.
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.         XSCHEME                 VECTOR FUNCTIONS                 Page 19
  1193.  
  1194.  
  1195.             VECTOR FUNCTIONS
  1196.  
  1197.             (VECTOR expr...)
  1198.  
  1199.                 Create a vector whose elements are the arguments to the
  1200.                 function.  This function can take an arbitrary number of
  1201.                 arguments.  Passing no arguments results in a zero
  1202.                 length vector.
  1203.  
  1204.             (MAKE-VECTOR len)
  1205.  
  1206.                 Make a vector of the specified length.
  1207.  
  1208.             (VECTOR-LENGTH vect)
  1209.  
  1210.                 Get the length of a vector.
  1211.  
  1212.             (VECTOR-REF vect n)
  1213.  
  1214.                 Return the nth element of a vector (zero based).
  1215.  
  1216.             (VECTOR-SET! vect n expr)
  1217.  
  1218.                 Set the nth element of a vector (zero based).
  1219.  
  1220.  
  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.         XSCHEME                 ARRAY FUNCTIONS                  Page 20
  1259.  
  1260.  
  1261.             ARRAY FUNCTIONS
  1262.  
  1263.             (MAKE-ARRAY d1 d2...)
  1264.  
  1265.                 Make an array (vector of vectors) with the specified
  1266.                 dimensions.  At least one dimension must be specified.
  1267.  
  1268.             (ARRAY-REF array s1 s2...)
  1269.  
  1270.                 Get an array element.  The sn arguments are integer
  1271.                 subscripts (zero based).
  1272.  
  1273.             (ARRAY-SET! array s1 s2... expr)
  1274.  
  1275.                 Set an array element.  The sn arguments are integer
  1276.                 subscripts (zero based).
  1277.  
  1278.  
  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.         XSCHEME               CONVERSION FUNCTIONS               Page 21
  1325.  
  1326.  
  1327.             CONVERSION FUNCTIONS
  1328.  
  1329.             (SYMBOL->STRING sym)
  1330.  
  1331.                 Convert a symbol to a string.  Returns the print name of
  1332.                 the symbol as a string.
  1333.  
  1334.             (STRING->SYMBOL str)
  1335.  
  1336.                 Convert a string to a symbol.  Returns a symbol with the
  1337.                 string as its print name.  This can either be a new
  1338.                 symbol or an existing one with the same print name.
  1339.  
  1340.             (VECTOR->LIST vect)
  1341.  
  1342.                 Convert a vector to a list.  Returns a list of the
  1343.                 elements of the vector.
  1344.  
  1345.             (LIST->VECTOR list)
  1346.  
  1347.                 Convert a list to a vector.  Returns a vector of the
  1348.                 elements of the list.
  1349.  
  1350.             (STRING->LIST str)
  1351.  
  1352.                 Convert a string to a list.  Returns a list of the
  1353.                 characters in the string.
  1354.  
  1355.             (LIST->STRING list)
  1356.  
  1357.                 Convert a list of character to a string.  Returns a
  1358.                 string whose characters are the elements of the list.
  1359.  
  1360.             (CHAR->INTEGER char)
  1361.  
  1362.                 Convert a character to an integer.  Returns the ASCII
  1363.                 code of the character as an integer.
  1364.  
  1365.             (INTEGER->CHAR n)
  1366.  
  1367.                 Convert an integer ASCII code to a character.  Returns
  1368.                 the character whose ASCII code is the integer.
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.         XSCHEME                 TYPE PREDICATES                  Page 22
  1391.  
  1392.  
  1393.             TYPE PREDICATE FUNCTIONS
  1394.  
  1395.             (NOT expr)
  1396.  
  1397.                 Returns #t if the expression is #f and #t otherwise.
  1398.  
  1399.             (NULL? expr)
  1400.  
  1401.                 Returns #t if the expression is the empty list and #f
  1402.                 otherwise.
  1403.  
  1404.             (ATOM? expr)
  1405.  
  1406.                 Returns #f if the expression is a pair and #t otherwise.
  1407.  
  1408.             (LIST? expr)
  1409.  
  1410.                 Returns #t if the expression is either a pair or the
  1411.                 empty list and #f otherwise.
  1412.  
  1413.             (NUMBER? expr)
  1414.  
  1415.                 Returns #t if the expression is a number and #f
  1416.                 otherwise.
  1417.  
  1418.             (BOOLEAN? expr)
  1419.  
  1420.                 Returns #t if the expression is either #t or #f and #f
  1421.                 otherwise.
  1422.  
  1423.             (PAIR? expr)
  1424.  
  1425.                 Returns #t if the expression is a pair and #f otherwise.
  1426.  
  1427.             (SYMBOL? expr)
  1428.  
  1429.                 Returns #t if the expression is a symbol and #f
  1430.                 otherwise.
  1431.  
  1432.             (COMPLEX? expr)
  1433.  
  1434.                 Returns #t if the expression is a complex number and #f
  1435.                 otherwise.
  1436.                 Note:  Complex numbers are not yet supported by XScheme.
  1437.  
  1438.             (REAL? expr)
  1439.  
  1440.                 Returns #t if the expression is a real number and #f
  1441.                 otherwise.
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.         XSCHEME                 TYPE PREDICATES                  Page 23
  1457.  
  1458.  
  1459.             (RATIONAL? expr)
  1460.  
  1461.                 Returns #t if the expression is a rational number and #f
  1462.                 otherwise.
  1463.                 Note:  Rational numbers are not yet supported by
  1464.                 XScheme.
  1465.  
  1466.             (INTEGER? expr)
  1467.  
  1468.                 Returns #t if the expression is an integer and #f
  1469.                 otherwise.
  1470.  
  1471.             (CHAR? expr)
  1472.  
  1473.                 Returns #t if the expression is a character and #f
  1474.                 otherwise.
  1475.  
  1476.             (STRING? expr)
  1477.  
  1478.                 Returns # if the expression is a string and #f
  1479.                 otherwise.
  1480.  
  1481.             (VECTOR? expr)
  1482.  
  1483.                 Returns #t if the expression is a vector and #f
  1484.                 otherwise.
  1485.  
  1486.             (PROCEDURE? expr)
  1487.  
  1488.                 Returns #t if the expression is a procedure (closure)
  1489.                 and #f otherwise.
  1490.  
  1491.             (PORT? expr)
  1492.  
  1493.                 Returns #t if the expression is a port and #f otherwise.
  1494.  
  1495.             (INPUT-PORT? expr)
  1496.  
  1497.                 Returns #t if the expression is an input port and #f
  1498.                 otherwise.
  1499.  
  1500.             (OUTPUT-PORT? expr)
  1501.  
  1502.                 Returns #t if the expression is an output port and #f
  1503.                 otherwise.
  1504.  
  1505.             (OBJECT? expr)
  1506.  
  1507.                 Returns #t if the expression is an object and #f
  1508.                 otherwise.
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.         XSCHEME                 TYPE PREDICATES                  Page 24
  1523.  
  1524.  
  1525.             (EOF-OBJECT? expr)
  1526.  
  1527.                 Returns #t if the expression is the object returned by
  1528.                 READ upon detecting an end of file condition and #f
  1529.                 otherwise.
  1530.  
  1531.             (DEFAULT-OBJECT? expr)
  1532.  
  1533.                 Returns #t if the expression is the object passed as the
  1534.                 default value of an optional parameter to a procedure
  1535.                 when that parameter is omitted from a call and #f
  1536.                 otherwise.
  1537.  
  1538.             (ENVIRONMENT? x)
  1539.  
  1540.                 Returns #t if the expression is an environment and #f
  1541.                 otherwise.
  1542.  
  1543.  
  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.         XSCHEME               EQUALITY PREDICATES                Page 25
  1589.  
  1590.  
  1591.             EQUALITY PREDICATES
  1592.  
  1593.             (EQUAL? expr1 expr2)
  1594.  
  1595.                 Recursively compares two objects to determine if their
  1596.                 components are the same and returns #t if they are the
  1597.                 same and #f otherwise.
  1598.  
  1599.             (EQV? expr1 expr2)
  1600.  
  1601.                 Compares two objects to determine if they are the same
  1602.                 object.  Returns #t if they are the same and #f
  1603.                 otherwise.  This function does not compare the elements
  1604.                 of lists, vectors or strings but will compare all types
  1605.                 of numbers.
  1606.  
  1607.             (EQ? expr1 expr2)
  1608.  
  1609.                 Compares two objects to determine if they are the same
  1610.                 object.  Returns #t if they are the same and #f
  1611.                 otherwise.  This function performs a low level address
  1612.                 compare on two objects and may return #f for objects
  1613.                 that appear on the surface to be the same.  This is
  1614.                 because the objects are not stored uniquely in memory.
  1615.                 For instance, numbers may appear to be equal, but EQ?
  1616.                 will return #f when comparing them if they are stored at
  1617.                 different addresses.  The advantage of this function is
  1618.                 that it is faster than the others.  Symbols are
  1619.                 guaranteed to compare correctly, so EQ? can safely be
  1620.                 used to compare them.
  1621.  
  1622.  
  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.         XSCHEME               ARITHMETIC FUNCTIONS               Page 26
  1655.  
  1656.  
  1657.             ARITHMETIC FUNCTIONS
  1658.  
  1659.             (ZERO? n)
  1660.  
  1661.                 Returns #t if the number is zero and #f otherwise.
  1662.  
  1663.             (POSITIVE? n)
  1664.  
  1665.                 Returns #t if the number is positive and #f otherwise.
  1666.  
  1667.             (NEGATIVE? n)
  1668.  
  1669.                 Returns #t if the number is negative and #f otherwise.
  1670.  
  1671.             (ODD? n)
  1672.  
  1673.                 Returns #t if the integer is odd and #f otherwise.
  1674.  
  1675.             (EVEN? n)
  1676.  
  1677.                 Returns #t if the integer is even and #f otherwise.
  1678.  
  1679.             (EXACT? n)
  1680.  
  1681.                 Returns #t if the number is exact and #f otherwise.
  1682.                 Note:  This function always returns #f in XScheme since
  1683.                 exact numbers are not yet supported.
  1684.  
  1685.             (INEXACT? n)
  1686.  
  1687.                 Returns #t if the number is inexact and #f otherwise.
  1688.                 Note:  This function always returns #t in XScheme since
  1689.                 exact numbers are not yet supported.
  1690.  
  1691.             (TRUNCATE n)
  1692.  
  1693.                 Truncates a number to an integer and returns the
  1694.                 resulting value.
  1695.  
  1696.             (FLOOR n)
  1697.  
  1698.                 Returns the largest integer not larger than n.
  1699.  
  1700.             (CEILING n)
  1701.  
  1702.                 Returns the smallest integer not smaller than n.
  1703.  
  1704.             (ROUND n)
  1705.  
  1706.                 Returns the closest integer to n, rounding to even when
  1707.                 n is halfway between two integers.
  1708.  
  1709.             (1+ n)
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.         XSCHEME               ARITHMETIC FUNCTIONS               Page 27
  1721.  
  1722.  
  1723.                 Returns the result of adding one to the number.
  1724.  
  1725.             (-1+ n)
  1726.  
  1727.                 Returns the result of subtracting one from the number.
  1728.  
  1729.             (ABS n)
  1730.  
  1731.                 Returns the absolute value of the number.
  1732.  
  1733.             (GCD n1 n2)
  1734.  
  1735.                 Returns the greatest common divisor of the two numbers.
  1736.  
  1737.             (RANDOM n)
  1738.  
  1739.                 Returns a random number between zero and n-1 (n must be
  1740.                 an integer).
  1741.  
  1742.             (+ n1 n2...)
  1743.  
  1744.                 Returns the sum of the numbers.
  1745.  
  1746.             (- n)
  1747.  
  1748.                 Negates the number and returns the resulting value.
  1749.  
  1750.             (- n1 n2...)
  1751.  
  1752.                 Subtracts each remaining number from n1 and returns the
  1753.                 resulting value.
  1754.  
  1755.             (* n1 n2...)
  1756.  
  1757.                 Multiples the numbers and returns the resulting value.
  1758.  
  1759.             (/ n)
  1760.  
  1761.                 Returns 1/n.
  1762.  
  1763.             (/ n1 n2...)
  1764.  
  1765.                 Divides n1 by each of the remaining numbers and returns
  1766.                 the resulting value.
  1767.  
  1768.             (QUOTIENT n1 n2...)
  1769.  
  1770.                 Divides the integer n1 by each of the remaining numbers
  1771.                 and returns the resulting integer quotient.  This
  1772.                 function does integer division.
  1773.  
  1774.             (REMAINDER n1 n2)
  1775.  
  1776.                 Divides the integer n1 by the integer n2 and returns the
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.         XSCHEME               ARITHMETIC FUNCTIONS               Page 28
  1787.  
  1788.  
  1789.                 remainder.
  1790.  
  1791.             (MIN n1 n2...)
  1792.  
  1793.                 Returns the number with the minimum value.
  1794.  
  1795.             (MAX n1 n2...)
  1796.  
  1797.                 Returns the number with the maximum value.
  1798.  
  1799.             (SIN n)
  1800.  
  1801.                 Returns the sine of the number.
  1802.  
  1803.             (COS n)
  1804.  
  1805.                 Returns the cosine of the number.
  1806.  
  1807.             (TAN n)
  1808.  
  1809.                 Returns the tangent of the number.
  1810.  
  1811.             (ASIN n)
  1812.  
  1813.                 Returns the arc-sine of the number.
  1814.  
  1815.             (ACOS n)
  1816.  
  1817.                 Returns the arc-cosine of the number.
  1818.  
  1819.             (ATAN x)
  1820.  
  1821.                 Returns the arc-tangent of x.
  1822.  
  1823.             (ATAN y x)
  1824.  
  1825.                 Returns the arc-tangent of y/x.
  1826.  
  1827.             (EXP n)
  1828.  
  1829.                 Returns e raised to the n.
  1830.  
  1831.             (SQRT n)
  1832.  
  1833.                 Returns the square root of n.
  1834.  
  1835.             (EXPT n1 n2)
  1836.  
  1837.                 Returns n1 raised to the n2 power.
  1838.  
  1839.             (LOG n)
  1840.  
  1841.                 Returns the natural logarithm of n.
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.         XSCHEME           NUMERIC COMPARISON FUNCTIONS           Page 29
  1853.  
  1854.  
  1855.             NUMERIC COMPARISON FUNCTIONS
  1856.  
  1857.             (< n1 n2...)
  1858.             (= n1 n2...)
  1859.             (> n1 n2...)
  1860.             <<= n1 n2...)
  1861.             (>= n1 n2...)
  1862.  
  1863.                 These functions compare numbers and return #t if the
  1864.                 numbers match the predicate and #f otherwise.  For
  1865.                 instance, (< x y z) will return #t if x is less than y
  1866.                 and y is less than z.
  1867.  
  1868.  
  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.         XSCHEME            BITWISE LOGICAL FUNCTIONS             Page 30
  1919.  
  1920.  
  1921.             BITWISE LOGICAL FUNCTIONS
  1922.  
  1923.             (LOGAND n1 n2...)
  1924.  
  1925.                 Returns the bitwise AND of the integer arguments.
  1926.  
  1927.             (LOGIOR n1 n2...)
  1928.  
  1929.                 Returns the bitwise inclusive OR of the integer
  1930.                 arguments.
  1931.  
  1932.             (LOGXOR n1 n2...)
  1933.  
  1934.                 Returns the bitwise exclusive OR of the integer
  1935.                 arguments.
  1936.  
  1937.             (LOGNOT n)
  1938.  
  1939.                 Returns the bitwise complement of n.
  1940.  
  1941.  
  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.         XSCHEME                 STRING FUNCTIONS                 Page 31
  1985.  
  1986.  
  1987.             STRING FUNCTIONS
  1988.  
  1989.             (STRING-LENGTH str)
  1990.  
  1991.                 Returns the length of the string.
  1992.  
  1993.             (STRING-NULL? str)
  1994.  
  1995.                 Returns #t if the string has a length of zero and #f
  1996.                 otherwise.
  1997.  
  1998.             (STRING-APPEND str1...)
  1999.  
  2000.                 Returns the result of appending the string arguments.
  2001.                 If no arguments are supplied, it returns the null
  2002.                 string.
  2003.  
  2004.             (STRING-REF str n)
  2005.  
  2006.                 Returns the nth character in a string.
  2007.  
  2008.             (SUBSTRING str start end)
  2009.  
  2010.                 Returns the substring of str starting at start and
  2011.                 ending at end (integers).  The range is inclusive of
  2012.                 start and exclusive of end.
  2013.  
  2014.  
  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.         XSCHEME           STRING COMPARISON FUNCTIONS            Page 32
  2051.  
  2052.  
  2053.             STRING COMPARISON FUNCTIONS
  2054.  
  2055.             (STRING<? str1 str2)
  2056.             (STRING=? str1 str2)
  2057.             (STRING>? str1 str2)
  2058.             (STRING<=? str1 str2)
  2059.             (STRING>=? str1 str2)
  2060.  
  2061.                 These functions compare strings and return #t if the
  2062.                 strings match the predicate and #f otherwise.  For
  2063.                 instance, (STRING< x y) will return #t if x is less than
  2064.                 y.  Case is significant.  #A does not match #a.
  2065.  
  2066.             (STRING-CI<? str1 str2)
  2067.             (STRING-CI=? str1 str2)
  2068.             (STRING-CI>? str1 str2)
  2069.             (STRING-CI<=? str1 str2)
  2070.             (STRING-CI>=? str1 str2)
  2071.  
  2072.                 These functions compare strings and return #t if the
  2073.                 strings match the predicate and #f otherwise.  For
  2074.                 instance, (STRING-CI< x y) will return #t if x is less
  2075.                 than y.  Case is not significant.  #A matches #a.
  2076.  
  2077.  
  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.         XSCHEME          CHARACTER COMPARISON FUNCTIONS          Page 33
  2117.  
  2118.  
  2119.             CHARACTER COMPARISON FUNCTIONS
  2120.  
  2121.             (CHAR<? ch1 ch2)
  2122.             (CHAR=? ch1 ch2)
  2123.             (CHAR>? ch1 ch2)
  2124.             (CHAR<=? ch1 ch2)
  2125.             (CHAR>=? ch1 ch2)
  2126.  
  2127.                 These functions compare characters and return #t if the
  2128.                 characters match the predicate and #f otherwise.  For
  2129.                 instance, (CHAR< x y) will return #t if x is less than
  2130.                 y.  Case is significant.  #A does not match #a.
  2131.  
  2132.             (CHAR-CI<? ch1 ch2)
  2133.             (CHAR-CI=? ch1 ch2)
  2134.             (CHAR-CI>? ch1 ch2)
  2135.             (CHAR-CI<=? ch1 ch2)
  2136.             (CHAR-CI>=? ch1 ch2)
  2137.  
  2138.                 These functions compare characters and return #t if the
  2139.                 characters match the predicate and #f otherwise.  For
  2140.                 instance, (CHAR-CI< x y) will return #t if x is less
  2141.                 than y.  Case is not significant.  #A matchs #a.
  2142.  
  2143.  
  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.         XSCHEME              INPUT/OUTPUT FUNCTIONS              Page 34
  2183.  
  2184.  
  2185.             INPUT/OUTPUT FUNCTIONS
  2186.  
  2187.             (READ [port])
  2188.  
  2189.                 Reads an expression from the specified port.  If no port
  2190.                 is specified, the current input port is used.  Returns
  2191.                 the expression read or an object that satisfies the
  2192.                 default-object? predicate if it reaches the end of file
  2193.                 on the port.
  2194.  
  2195.             (READ-CHAR [port])
  2196.  
  2197.                 Reads a character from the specified port.  If no port
  2198.                 is specified, the current input port is used.  Returns
  2199.                 the character read or an object that satisfies the
  2200.                 default-object? predicate if it reaches the end of file
  2201.                 on the port.
  2202.  
  2203.             (READ-BYTE [port])
  2204.  
  2205.                 Reads a byte from the specified port.  If no port is
  2206.                 specified, the current input port is used.  Returns the
  2207.                 byte read or an object that satisfies the default-
  2208.                 object? predicate if it reaches the end of file on the
  2209.                 port.
  2210.  
  2211.             (WRITE expr [port])
  2212.             (PRIN1 expr [port])
  2213.  
  2214.                 Writes an expression to the specified port.  If no port
  2215.                 is specified, the current output port is used.  The
  2216.                 expression is written such that the READ function can
  2217.                 read it back.  This means that strings will be enclosed
  2218.                 in quotes and characters will be printed with #
  2219.                 notation.
  2220.  
  2221.             (WRITE-CHAR ch [port])
  2222.  
  2223.                 Writes a character to the specified port.  If no port is
  2224.                 specified, the current output port is used.
  2225.  
  2226.             (WRITE-BYTE ch [port])
  2227.  
  2228.                 Writes a byte to the specified port.  If no port is
  2229.                 specified, the current output port is used.
  2230.  
  2231.             (DISPLAY expr [port])
  2232.             (PRINC expr [port])
  2233.  
  2234.                 Writes an expression to the specified port.  If no port
  2235.                 is specified, the current output port is used.  The
  2236.                 expression is written without any quoting characters.
  2237.                 No quotes will appear around strings and characters are
  2238.                 written without the # notation.
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.         XSCHEME              INPUT/OUTPUT FUNCTIONS              Page 35
  2249.  
  2250.  
  2251.             (NEWLINE [port])
  2252.  
  2253.                 Starts a new line on the specified port.  If no port is
  2254.                 specified, the current output port is used.
  2255.  
  2256.  
  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.         XSCHEME             OUTPUT CONTROL FUNCTIONS             Page 36
  2315.  
  2316.  
  2317.             OUTPUT CONTROL FUNCTIONS
  2318.  
  2319.             (PRINT-BREADTH [n])
  2320.  
  2321.                 Controls the maximum number of elements of a list that
  2322.                 will be printed.  If n is an integer, the maximum number
  2323.                 is set to n.  If it is #f, the limit is set to infinity.
  2324.                 This is the default.  If n is omitted from the call, the
  2325.                 current value is returned.
  2326.  
  2327.             (PRINT-DEPTH [n])
  2328.  
  2329.                 Controls the maximum number of levels of a nested list
  2330.                 that will be printed.  If n is an integer, the maximum
  2331.                 number is set to n.  If it is #f, the limit is set to
  2332.                 infinity.  This is the default.  If n is omitted from
  2333.                 the call, the current value is returned.
  2334.  
  2335.  
  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.         XSCHEME                FILE I/O FUNCTIONS                Page 37
  2381.  
  2382.  
  2383.             FILE I/O FUNCTIONS
  2384.  
  2385.             All four of the following OPEN functions take an optional
  2386.             argument to indicate that file I/O is to be done in binary
  2387.             mode.  For binary files, this argument should be the symbol
  2388.             BINARY.  For text files, the argument can be left out or the
  2389.             symbol TEXT can be supplied.
  2390.  
  2391.             (OPEN-INPUT-FILE str ['binary])
  2392.  
  2393.                 Opens the file named by the string and returns an input
  2394.                 port.
  2395.  
  2396.             (OPEN-OUTPUT-FILE str ['binary])
  2397.  
  2398.                 Creates the file named by the string and returns an
  2399.                 output port.
  2400.  
  2401.             (OPEN-APPEND-FILE str ['binary])
  2402.  
  2403.                 Opens the file named by the string for appending returns
  2404.                 an output port.
  2405.  
  2406.             (OPEN-UPDATE-FILE str ['binary])
  2407.  
  2408.                 Opens the file named by the string for input and output
  2409.                 and returns an input/output port.
  2410.  
  2411.             (GET-FILE-POSITION port)
  2412.  
  2413.                 Returns the current file position as an offset in bytes
  2414.                 from the beginning of the file.
  2415.  
  2416.             (SET-FILE-POSITION! port offset whence)
  2417.  
  2418.                 Sets the current file position as an offset in bytes
  2419.                 from the beginning of the file (when whence equals 0),
  2420.                 the current file position (when whence equals 1) or the
  2421.                 end of the file (when whence equals 2).  Returns the new
  2422.                 file position as an offset from the start of the file.
  2423.  
  2424.             (CLOSE-PORT port)
  2425.  
  2426.                 Closes any port.
  2427.  
  2428.             (CLOSE-INPUT-PORT port)
  2429.  
  2430.                 Closes an input port.
  2431.  
  2432.             (CLOSE-OUTPUT-PORT port)
  2433.  
  2434.                 Closes an output port.
  2435.  
  2436.  
  2437.  
  2438.  
  2439.  
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.         XSCHEME                FILE I/O FUNCTIONS                Page 38
  2447.  
  2448.  
  2449.             (CALL-WITH-INPUT-FILE str proc)
  2450.  
  2451.                 Open the file whose name is specifed by str and call
  2452.                 proc passing the resulting input port as an argument.
  2453.                 When proc returns, close the file and return the value
  2454.                 returned by proc as the result.
  2455.  
  2456.             (CALL-WITH-OUTPUT-FILE str proc)
  2457.  
  2458.                 Create the file whose name is specifed by str and call
  2459.                 proc passing the resulting output port as an argument.
  2460.                 When proc returns, close the file and return the value
  2461.                 returned by proc as the result.
  2462.  
  2463.             (CURRENT-INPUT-PORT)
  2464.  
  2465.                 Returns the current input port.
  2466.  
  2467.             (CURRENT-OUTPUT-PORT)
  2468.  
  2469.                 Returns the current output port.
  2470.  
  2471.  
  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.         XSCHEME                 CONTROL FEATURES                 Page 39
  2513.  
  2514.  
  2515.             CONTROL FEATURES
  2516.  
  2517.             (EVAL expr)
  2518.  
  2519.                 Evaluate the expression in the global environment and
  2520.                 return its value.
  2521.  
  2522.             (APPLY proc args)
  2523.  
  2524.                 Apply the procedure to the list of arguments and return
  2525.                 the result.
  2526.  
  2527.             (MAP proc list...)
  2528.  
  2529.                 Apply the procedure to argument lists formed by taking
  2530.                 corresponding elements from each list.  Form a list from
  2531.                 the resulting values and return that list as the result
  2532.                 of the MAP call.
  2533.  
  2534.             (FOR-EACH fun list...)
  2535.  
  2536.                 Apply the procedure to argument lists formed by taking
  2537.                 corresponding elements from each list.  The values
  2538.                 returned by the procedure applications are discarded.
  2539.                 The value returned by FOR-EACH is unspecified.
  2540.  
  2541.             (CALL-WITH-CURRENT-CONTINUATION proc)
  2542.             (CALL/CC proc)
  2543.  
  2544.                 Form an "escape procedure" from the current continuation
  2545.                 and pass it as an argument to proc.  Calling the escape
  2546.                 procedure with a single argument will cause that
  2547.                 argument to be passed to the continuation that was in
  2548.                 effect when the CALL-WITH-CURRENT-CONTINUATION procedure
  2549.                 was called.
  2550.  
  2551.  
  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.         XSCHEME              ENVIRONMENT FUNCTIONS               Page 40
  2579.  
  2580.  
  2581.             ENVIRONMENT FUNCTIONS
  2582.  
  2583.             (THE-ENVIRONMENT)
  2584.  
  2585.                 Returns the current environment.
  2586.  
  2587.             (PROCEDURE-ENVIRONMENT proc)
  2588.  
  2589.                 Returns the environment from a procedure closure.
  2590.  
  2591.             (ENVIRONMENT-BINDINGS env)
  2592.  
  2593.                 Returns an association list corresponding to the top
  2594.                 most frame of the specified environment.
  2595.  
  2596.             (ENVIRONMENT-PARENT env)
  2597.  
  2598.                 Returns the parent environment of the specified
  2599.                 environment.
  2600.  
  2601.  
  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.         XSCHEME                UTILITY FUNCTIONS                 Page 41
  2645.  
  2646.  
  2647.             UTILITY FUNCTIONS
  2648.  
  2649.             (LOAD str)
  2650.  
  2651.                 Read and evaluate each expression from the specified
  2652.                 file.
  2653.  
  2654.             (LOAD-NOISILY str)
  2655.  
  2656.                 Read and evaluate each expression from the specified
  2657.                 file and print the results to the current output port.
  2658.  
  2659.             (TRANSCRIPT-ON str)
  2660.  
  2661.                 Opens a transcript file with the specified name and
  2662.                 begins logging the interactive session to that file.
  2663.  
  2664.             (TRANSCRIPT-OFF)
  2665.  
  2666.                 Closes the current transcript file.
  2667.  
  2668.             (EXIT)
  2669.  
  2670.                 Exits from XScheme back to the operating system.
  2671.  
  2672.             (GC [ni vi])
  2673.  
  2674.                 Invokes the garbage collector and returns information on
  2675.                 memory usage.  If ni and vi are specified, they must be
  2676.                 integers.  Node and vector space are expanded by those
  2677.                 amounts respectively and no garbage collection is
  2678.                 triggered.  GC returns an array of six values: the
  2679.                 number of calls to the garbage collector, the total
  2680.                 number of nodes, the current number of free nodes, the
  2681.                 number of node segments, the number of vector segments
  2682.                 and the total number of bytes allocated to the heap.
  2683.  
  2684.             (RESET)
  2685.  
  2686.                 Returns to the top level read/eval/print loop.
  2687.  
  2688.  
  2689.  
  2690.  
  2691.  
  2692.  
  2693.  
  2694.  
  2695.  
  2696.  
  2697.  
  2698.  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.  
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.         XSCHEME                 SYSTEM FUNCTIONS                 Page 42
  2711.  
  2712.  
  2713.             SYSTEM FUNCTIONS
  2714.  
  2715.             (%CAR pair)
  2716.             (%CDR pair)
  2717.             (%SET-CAR! pair expr)
  2718.             (%SET-CDR! pair expr)
  2719.             (%VECTOR-LENGTH vect)
  2720.             (%VECTOR-REF vect n)
  2721.             (%VECTOR-SET! vect n expr)
  2722.  
  2723.                 These functions do the same as their counterparts
  2724.                 without the leading '%' character.  The difference is
  2725.                 that they don't check the type of their first argument.
  2726.                 This makes it possible to examine data structures that
  2727.                 have the same internal representation as pairs and
  2728.                 vectors.  It is *very* dangerous to modify objects using
  2729.                 these functions and there is no guarantee that future
  2730.                 releases of XScheme will represent objects in the same
  2731.                 way that the current version does.
  2732.  
  2733.  
  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.         XSCHEME              OBJECT REPRESENTATIONS              Page 43
  2777.  
  2778.  
  2779.                 OBJECT REPRESENTATIONS
  2780.  
  2781.                 This version of XScheme uses the following object
  2782.                 representations:
  2783.  
  2784.                     Closures are represented as pairs.  The car of the
  2785.                     pair is the compiled function and the cdr of the
  2786.                     pair is the saved environment.
  2787.  
  2788.                     Compiled functions are represented as vectors.  The
  2789.                     element at offset 0 is the bytecode string.  The
  2790.                     element at offset 1 is the function name.  The
  2791.                     element at offset 2 is a list of names of the
  2792.                     function arguments.  The elements at offsets above 2
  2793.                     are the literals refered to by the compiled
  2794.                     bytecodes.
  2795.  
  2796.                     Environments are represented as lists of vectors.
  2797.                     Each vector is an environment frame.  The element at
  2798.                     offset 0 is a list of the symbols that are bound in
  2799.                     that frame.  The symbol values start at offset 1.
  2800.  
  2801.                     Objects are represented as vectors.  The element at
  2802.                     offset 0 is the class of the object.  The remaining
  2803.                     elements are the object's instance variable values.
  2804.  
  2805.  
  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.