home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MISC / IFP.ZIP / IFP.TXT < prev   
Encoding:
Text File  |  1987-02-09  |  28.5 KB  |  892 lines

  1.                           IFP Reference                         1
  2.  
  3. 1.  Built-in Functions 
  4.      
  5.      This section is a reference guide to the built-in  functions
  6.  
  7. in IFP. The following sets (types) are used in the definitions of
  8.  
  9. functions:
  10.  
  11.  
  12.          A    atoms
  13.          B    boolean values
  14.          O    objects
  15.          R    real numbers
  16.          Z    integers
  17.          S    strings
  18.          T*   sequences with element type T
  19.          T+   non-empty sequences with element type T
  20.          Tn   sequences of length n with element type T
  21.  
  22.  
  23. A function returns ``?'' if the argument is not  in  its  domain.
  24.  
  25. The notation xn denotes the nth element of a sequence X.
  26.  
  27.  
  28.      For example, the domain of the addition function is [X,Y] in
  29.  
  30. [R,R].   That  is  addition  takes  a pair of real numbers as its
  31.  
  32. argument.  We could also write this as [X,Y] in R2, since a  pair
  33.  
  34. is a sequence of length two.
  35. 
  36.                           IFP Reference                         2
  37.  
  38. 1.1.  Structural Functions (/sys)
  39.  
  40.  
  41.      Structural functions are assemble,  reorganize,  and  select
  42.  
  43. data.  The primitive structural functions are listed below:
  44.  
  45.  
  46. ______________________________________________________________________
  47. |Name______Domain_________________Definition_________________________|
  48. |                                                                    |
  49. |apndl     [X,Y] in [O,On]        <X, y1 , y2 , ...yn>               |
  50. |                                                                    |
  51. |apndr     [X,Y] in [Om,O]        <x1, x2, ... xm, Y>                |
  52. |                                                                    |
  53. |cat       X in O**               catenate sequences                 |
  54. |                                                                    |
  55. |distl     [X,Y] in [O,On]        <<X,y1> <X,y2> ... <X,yn>>         |
  56. |                                                                    |
  57. |distr     [X,Y] in [Om,O]        <<x1,Y> <x2,Y> ... <xm,Y>>         |
  58. |                                                                    |
  59. |dropl     [X,K] in [On, 0≤Z≤n]   drop K elements from left end of X |
  60. |                                                                    |
  61. |dropr     [X,K] in [On, 0≤Z≤n]   drop K elements from right end of X|
  62. |                                                                    |
  63. |iota      n in Z≥0               <1,2,...n>                         |
  64. |                                                                    |
  65. |length    X in On                number of elements in X            |
  66. |                                                                    |
  67. |pick      [X,K] in [On, 0<Z≤n]   Kth element of X                   |
  68. |                                                                    |
  69. |repeat    [X,K] in [O,0≤Z]       sequence <X,X...X> of length K     |
  70. |                                                                    |
  71. |reverse   X in On                reversal of X                      |
  72. |                                                                    |
  73. |takel     [X,K] in [On, 0≤Z≤n]   take K elements from left end of X |
  74. |                                                                    |
  75. |taker     [X,K] in [On, 0≤Z≤n]   take K elements from right end of X|
  76. |                                                                    |
  77. |tl        X in O+                (tail) drop first element of X     |
  78. |                                                                    |
  79. |tlr       X in O+                (right tail) drop last element of X|
  80. |                                                                    |
  81. |trans     X is matrix            transpose X                        |
  82. |____________________________________________________________________|
  83.  
  84. 
  85.                           IFP Reference                         3
  86.  
  87. 1.2.  Arithmetic (/math/arith)
  88.  
  89.  
  90.      Most IFP arithmetic functions are found here.   Below  is  a
  91.  
  92. table  of  the existing functions.  Some function's domain may be
  93.  
  94. further restricted due to range limitations.
  95.  
  96.  
  97.       ____________________________________________________
  98.      |_Name_____Domain_____________Definition____________|
  99.      |                                                   |
  100.      | +        [X,Y] in [R,R]     X+Y                   |
  101.      |                                                   |
  102.      | -        ...                X-Y                   |
  103.      |                                                   |
  104.      | *        ...                XxY                   |
  105.      |                                                   |
  106.      | %        [X,Y] in [R,R╪0]   X/Y                   |
  107.      |                                                   |
  108.      | add1     X in R             X+1                   |
  109.      |                                                   |
  110.      | arcsin   X in R, -1≤X≤1     arcsine X             |
  111.      |                                                   |
  112.      | arccos   X in R, -1≤X≤1     arccosine X           |
  113.      |                                                   |
  114.      | arctan   X in R             arctangent  X         |
  115.      |                                                   |
  116.      | cos      X in R             cosine X              |
  117.      |                                                   |
  118.      | div      [X,Y] in [R,R╪0]   floor (X/Y)           |
  119.      |                                                   |
  120.      | exp      X in R             e to the Xth power    |
  121.      |                                                   |
  122.      | ln       X in R>0           natural logarithm of X|
  123.      |                                                   |
  124.      | max      [X,Y] in [R,R]     maximum of X and Y    |
  125.      |                                                   |
  126.      | min      [X,Y] in [R,R]     minimum of X and Y    |
  127.      |                                                   |
  128.      | minus    X in R             -X                    |
  129.      |                                                   |
  130.      | mod      [X,Y] in [R,R]     X modulo Y            |
  131.      |                                                   |
  132.      | power    [X,Y] in [R≥0,R]   X to Yth power        |
  133.      |                                                   |
  134.      | sin      X in R             sine X                |
  135.      |                                                   |
  136.      | sqrt     X in R>0           square root of X      |
  137.      |                                                   |
  138.      | sub1     X in R             X-1                   |
  139.      |                                                   |
  140.      | sum      X in R*            summation of X        |
  141.      |                                                   |
  142.      | tan      X in R             tangent of X          |
  143.      |___________________________________________________|
  144. 
  145.                           IFP Reference                         4
  146.  
  147. 1.3.  Logic (/math/logic)
  148.  
  149.      Most IFP primitive functions returning  boolean  values  are
  150.  
  151. found here.  Below is a table of the existing functions:
  152.  
  153. ______________________________________________________________________
  154. |Name______Domain___________________Definition_______________________|
  155. |                                                                    |
  156. |=         [X,Y] in [O,O]           X=Y                              |
  157. |                                                                    |
  158. |~=        ...                      X╪Y                              |
  159. |                                                                    |
  160. |<         [X,Y] in [R,R] u [S,S]   X<Y                              |
  161. |                                                                    |
  162. |<=        ...                      X≤Y                              |
  163. |                                                                    |
  164. |>=        ...                      X≥Y                              |
  165. |                                                                    |
  166. |>         ...                      X>Y                              |
  167. |                                                                    |
  168. |~         X in B                   not X                            |
  169. |                                                                    |
  170. |and       [X,Y] in [B,B]           X AND Y                          |
  171. |                                                                    |
  172. |all       X in B*                  all elements of X are true       |
  173. |                                                                    |
  174. |any       X in B*                  at least one element of X is true|
  175. |                                                                    |
  176. |atom      X in O                   X is an atom                     |
  177. |                                                                    |
  178. |boolean   X in O                   X is boolean                     |
  179. |                                                                    |
  180. |false     X in O                   X is #f                          |
  181. |                                                                    |
  182. |imply     [X,Y] in [B,B]           ~X OR Y                          |
  183. |                                                                    |
  184. |longer    [X,Y] in [Om,On]         m>n                              |
  185. |                                                                    |
  186. |member    [X,Y] in [O*,O]          Y is an element of X             |
  187. |                                                                    |
  188. |numeric   X in O                   X is a number                    |
  189. |                                                                    |
  190. |null      X in O*                  X = <>                           |
  191. |                                                                    |
  192. |odd       X in Z                   X is odd                         |
  193. |                                                                    |
  194. |or        [X,Y] in [B,B]           X OR Y                           |
  195. |                                                                    |
  196. |pair      X in O                   X is a pair                      |
  197. |                                                                    |
  198. |shorter   [X,Y] in [Om, On]        m<n                              |
  199. |                                                                    |
  200. |xor       [X,Y] in [B,B]           X╪Y                              |
  201. |____________________________________________________________________|
  202.  
  203.  
  204. String inequalities are defined from the lexigraphical  (diction-
  205.  
  206. ary) ordering.
  207. 
  208.                           IFP Reference                         5
  209.  
  210. 1.4.  String Functions (/sys)
  211.  
  212.  
  213.      The string functions are:
  214.  
  215.  
  216.   ____________________________________________________________
  217.  |_Name______Domain____Definition____________________________|
  218.  |                                                           |
  219.  | explode   X in S    sequence of characters in X           |
  220.  |                                                           |
  221.  | implode   X in S*   string made by catenating strings in X|
  222.  |                                                           |
  223.  | patom     X in A    string representation of X            |
  224.  |___________________________________________________________|
  225.  
  226.  
  227.  
  228. 1.5.  Miscellaneous Functions (/sys)
  229.  
  230.  
  231.      The miscellaneous functions are listed below.  Each function
  232.  
  233. description is preceded by a title line of the form:
  234.  
  235. function                     domain                    definition
  236.  
  237.  
  238. _________________________________________________________________
  239.  
  240.  
  241. apply                    [X,F] in [O,S*]             apply F to X
  242.  
  243.  
  244.     F is a sequence of strings representing a path to  a  de-
  245.     fined function.  The result is the function referenced by
  246.     F applied to X.  Example:
  247.  
  248.                 <<3 4> <math arith "+">> : apply -> 7
  249.  
  250.  
  251.  
  252. _________________________________________________________________
  253.  
  254.  
  255. assoc                  [X,Y] in [(O+)*,O]      associative lookup
  256.  
  257.  
  258.     X is an association sequence,  which  is  a  sequence  of
  259.     non-empty subsequences.  The first element of each subse-
  260.     quence is the key of the subsequence.  The result of  as-
  261.     soc  is the first subsequence of X with a key equal to Y.
  262.     If no matching key is found, f is returned.  The key  may
  263.     be any type of object.  Examples:
  264.  
  265.              <<<a b c> <w x y z> <i j>> w> -> <w x y z>
  266.              <<<a b c> <w x y z> <i j>> U> -> f
  267.  
  268. _________________________________________________________________
  269. 
  270.                           IFP Reference                         6
  271.  
  272. def                         X in S+                    definition
  273.  
  274.  
  275.     The definition function returns the object representation
  276.     of  its  argument.  The representation of a function is a
  277.     sequence of strings  denoting  its  absolute  path.   The
  278.     representation of a PFO is a sequence.  The first element
  279.     of the sequence is a path to the PFO.  The remaining ele-
  280.     ments  of  the  sequence are parameters of the functional
  281.     form.  Suppose, for example, we define the inner  product
  282.     function:
  283.  
  284.            DEF Inner AS trans | EACH * END | INSERT + END
  285.  
  286.     and  ``Inner''  is  defined   with   a   module   with   path
  287.     ``/math/linear''.   Then  ``<math  linear Inner> : def'' will
  288.     result in:
  289.  
  290.                  <
  291.                       <sys compose>
  292.                       <sys trans>
  293.                       <<sys each> <math arith *>>
  294.                       <<sys insertr> <math arith +>>
  295.                  >
  296.  
  297.     Currently, the representations of PFO are:
  298.  
  299.     #c                       <<sys constant> #c>
  300.     #?                       <<sys constant>>
  301.     n                        <<sys selectl> n>
  302.     nr                       <<sys selectr> n>
  303.     f1 | f2 | ... fn         <<sys compose>, f1 , f2 , ... fn>
  304.     [f1 , f2 , ... fn ]      <<sys construct>, f1 , f2 , ... fn>
  305.     ^c                       <<sys fetch> c>
  306.     EACH f END               <<sys each> f>
  307.     FILTER p END             <<sys filter> p>
  308.     INSERT f END             <<sys insertr> f>
  309.     IF p THEN g ELSE h END   <<sys if> p g h>
  310.     WHILE p DO f END         <<sys while> p f>
  311.  
  312.     ELSIF clauses are always expanded into equivalent nested  IF-
  313.     THEN-ELSE  constructions.   Note the special case for #?, the
  314.     representation <<sys constant> ?> would be useless due to the
  315.     bottom-preserving property.
  316.  
  317.  
  318. _________________________________________________________________
  319.  
  320.  
  321. id                           X in O                      identity
  322.  
  323.  
  324.     The identity function returns its argument.  It is useful
  325.     as  a  place  holder in PFO.  For example, the ``square''
  326.     function can be written as:
  327.  
  328.  
  329.             DEF Square AS [id,id] | *;
  330. 
  331.                           IFP Reference                         7
  332.  
  333. 2.  Program Forming Operations
  334.  
  335.      Program forming operations combine functions and objects  to
  336.  
  337. create new functions.
  338.  
  339.  
  340. 2.1.  Constant
  341.  
  342.      Constant  functions  always  return  the  same  result  when
  343.  
  344. applied  to any value which is not ``?''.  Constant functions are
  345.  
  346. written as:
  347.  
  348.  
  349.         #c
  350.  
  351. where c is the constant value to be returned. A constant function
  352.  
  353. applied to ``?'' results in ``?''.  Note that the function ``#?''
  354.  
  355. always returns `?'.  Examples:
  356.  
  357.  
  358.                923 : #<cat in hat> -> <cat in hat>
  359.                <a b c d e f> : #427 -> 427
  360.                ? : #<q w er t y> -> ?
  361.                5 : #? -> ?
  362.  
  363.  
  364. 2.2.  Selection
  365.  
  366.  
  367.      Selector functions return the nth element of a sequence  and
  368.  
  369. are  written  as n, where n is a positive integer.  Note the dis-
  370.  
  371. tinction between #5, which returns the  value  5,  and  5,  which
  372.  
  373. returns  the  fifth  element  of  its  argument. There are also a
  374.  
  375. corresponding set of select-from-right functions, written as  nr.
  376.  
  377. These  select  the  nth  element of a sequence, counting from the
  378.  
  379. right. All selectors return ``?'' if the argument has no nth ele-
  380.  
  381. ment  or  is not a sequence.  Below are some examples of applying
  382.  
  383. selector functions:
  384.  
  385.               <a b c d e> : 1 -> a
  386.               <a b c d e> : 2 -> b
  387.               <apple banana cherry> : 1r -> cherry
  388.               <apple banana cherry> : 4 -> ?
  389.               hello : 1 -> ?
  390. 
  391.                           IFP Reference                         8
  392.  
  393. 2.3.  Composition
  394.  
  395.  
  396.      The function composition of two functions is written as:
  397.  
  398.  
  399.                               f | g
  400.  
  401. Applying the result function is the same as applying f  and  then
  402.  
  403. g.  E.g.: Function composition is defined by the equality:
  404.  
  405.                     x : (f | g) ≡ (x : f) : g
  406.  
  407. Since function composition is  associative,  the  composition  of
  408.  
  409. more than two functions does not require parentheses.  The compo-
  410.  
  411. sition of f1,f2,...fn is written:
  412.  
  413.                          f1 | f2 | ...fn
  414.  
  415. Composition syntax is identical to UNIX's  pipe  notation  for  a
  416.  
  417. reason:  function  composition  is  isomorphic  to a pipe between
  418.  
  419. processes without side effects.
  420.  
  421.  
  422. 2.4.  Construction
  423.  
  424.  
  425.      The construction of functions is written as  bracketed  list
  426.  
  427. of  the functions.  For example, the construction of functions fi
  428.  
  429. is written:
  430.  
  431.                           [f1,f2,...fn]
  432.  
  433. Function construction is defined by the equality:
  434.  
  435.  
  436.              x : [f1,f2,...fn] ≡ <x:f1,x:f2,...x:fn>
  437.  
  438.  
  439. 2.5.  Apply to Each
  440.  
  441.  
  442.      The EACH functional form applys a function to  each  element
  443.  
  444. of a sequence.  It is written as
  445. 
  446.                           IFP Reference                         9
  447.  
  448.         EACH f END
  449.  
  450.  
  451. It is defined by the equality:
  452.  
  453.  
  454.         <x1,x2,...xn> : EACH f END ≡ <x1:f,x2:f,...xn:f>
  455.  
  456.  
  457. 2.6.  If-Then-Else
  458.  
  459.  
  460.      The IF functional form allows conditional function  applica-
  461.  
  462. tion.  It is written as
  463.  
  464.  
  465.         IF p THEN g ELSE h END
  466.  
  467.  
  468. and is defined by the equality:
  469.  
  470.                                      | x:g  if p=#t
  471.                                      |
  472.         x : IF p THEN g ELSE h END ≡ | x:h  if p=#f
  473.                                      | ?   otherwise
  474.                                      |
  475.  
  476. The level of nesting of conditional forms may be reduced by using
  477.  
  478. ELSIF clauses:
  479.  
  480.  
  481.         IF p1 THEN f1 ELSIF p2 THEN f2 ELSIF ... ELSE g END
  482.  
  483.  
  484. 2.7.  Filter
  485.  
  486.  
  487.      The FILTER functional form filters  through  elements  of  a
  488.  
  489. sequence satisfying a predicate.  It is written as:
  490.  
  491.  
  492.         FILTER p END
  493.  
  494. where p is the predicate.  It is defined by the functional equal-
  495.  
  496. ity:
  497.  
  498.         FILTER p END ≡ EACH IF p THEN [id] ELSE [ ] END END | cat
  499.  
  500.  
  501. For example, if you wish  to  find  all  numeric  elements  in  a
  502.  
  503. sequence, you could write:
  504. 
  505.                           IFP Reference                        10
  506.  
  507.  
  508.         FILTER numeric END
  509.  
  510.  
  511. The FILTER functional form is an IFP extension to Backus' FP.
  512.  
  513.  
  514. 2.8.  Right Insert
  515.  
  516.  
  517.      The INSERT functional form is defined by the recursion:
  518.  
  519.  
  520.         INSERT f END ≡ IF tl|null THEN 1 ELSE [1,tl | INSERT f END] | f END
  521.  
  522.  
  523. Typically it is used for crunching a sequence down.  For example,
  524.  
  525.  
  526.         INSERT + END
  527.  
  528.  
  529. returns the sum of a sequence.
  530.  
  531.  
  532.      Unlike Backus' FP, functions formed with INSERT  are  always
  533.  
  534. undefined  for empty sequences.  The reason is that it is imprac-
  535.  
  536. tical for the interpreter to know the identity element  of  user-
  537.  
  538. defined  functions.   The  number  of cases where the interpreter
  539.  
  540. could know the identity element are so few that you might as well
  541.  
  542. define special functions for those cases, e.g:
  543.  
  544.  
  545.         DEF sum AS IF null THEN #0 ELSE INSERT + END END;
  546.  
  547.  
  548. Alternatively, you can append the identity element to the end  of
  549.  
  550. the sequence before inserting, e.g.:
  551.  
  552.  
  553.         DEF sum AS [id,#0] | apndr | INSERT + END;
  554.  
  555.  
  556.  
  557.      Currently there is  no  ``left  insert''  form.d   The  left
  558.  
  559. insertion of f can be written as:
  560.  
  561.  
  562.         reverse | INSERT reverse|f END
  563. 
  564.                           IFP Reference                        11
  565.  
  566. 2.9.  While
  567.  
  568.  
  569.      The WHILE functional form allows indefinite composition.  It
  570.  
  571. is written as:
  572.  
  573.  
  574.         WHILE p DO f END;
  575.  
  576.  
  577. and is defined by the recursive functional equality:
  578.  
  579.  
  580.         WHILE p DO f END ≡ IF p THEN f | WHILE p DO f END ELSE id END
  581.  
  582.  
  583.  
  584. 2.10.  Fetch
  585.  
  586.  
  587.      The fetch functional form allows easy access to  association
  588.  
  589. sequences  (see function /sys/assoc for a description of associa-
  590.  
  591. tion sequences.)  A fetch is written as ^c, where c is an object.
  592.  
  593. The fetch form is defined by the functional equality:
  594.  
  595.  
  596.         ^c ≡ IF EACH pair END | all THEN [id,#c]|assoc|2
  597.              ELSE #?
  598.              END;
  599.  
  600.  
  601. Note that the input is restricted to a sequence of pairs.
  602.  
  603.  
  604. 3.  Comments
  605.  
  606.  
  607.      Comments are delimited  by  matching  pairs  of  ``(*''  and
  608.  
  609. ``*)''.   Comments  may  be  inserted  anywhere not adjacent to a
  610.  
  611. token.  For example:
  612.  
  613.  
  614.         DEF foo AS bar; (* This is a comment.  DEF foo AS bar isn't comment *)
  615.  
  616.  
  617.  
  618. 4.  Syntax Summary
  619.  
  620.  
  621.      Below is an EBNF grammar for IFP:
  622. 
  623.                           IFP Reference                        12
  624. ____________________________________________________________________________
  625. |Def ->            'DEF String 'AS' Comp ';'                               |
  626. |Comp ->            Simple { '|' Simple }                                  |
  627. |Simple ->          Conditional | Constant | Construction | Each | Filter ||
  628. |                  Insert  | Path | While | Fetch | Debug                  |
  629. |Conditional ->    'IF' Comp 'THEN' Comp { 'ELSIF' Comp 'THEN' Comp }      |
  630. |                  'ELSE' Comp 'END'                                       |
  631. |While ->          'WHILE' Comp 'DO' Comp 'end'                            |
  632. |Insert ->         'INSERT' Comp 'END'                                     |
  633. |Each ->           'EACH' Comp 'END'                                       |
  634. |Filter ->         'FILTER' Comp 'END'                                     |
  635. |Fetch ->          '^' String                                              |
  636. |Constant ->       '#' Object                                              |
  637. |Debug ->          '@' Object                                              |
  638. |Construction ->   '[' [Comp {',' Comp}] ']'                               |
  639. |Path ->           ['/'] String {'/' String}                               |
  640. |Object ->         Bottom | Atom | '<' [Atom {','Atom}] '>'                |
  641. |Bottom ->         '?'                                                     |
  642. |Atom ->           Number | String | Boolean                               |
  643. |Boolean_->________'t'_|_'f'_________________________________________________|
  644.  
  645. Strings may be in single or double quotes.  The strings ``t'' and
  646.  
  647. ``f''  must  be  quoted  to  distinguish them from boolean atoms.
  648.  
  649. Strings of digits must also be quoted to  distinguish  them  from
  650.  
  651. numeric atoms.
  652.  
  653. 5.  Running IFP with MS-DOS
  654.  
  655. 5.1.  Prerequisite Hardware
  656.  
  657.      The MS-DOS version needs at  least  a  256K  system.   Extra
  658.  
  659. memory for a RAM-disk is convenient but not necessary.
  660.  
  661.  
  662. 5.2.  Prerequisite Software
  663.  
  664.  
  665.      There are three programs you will need: the IFP  interpreter
  666.  
  667. (IFP.EXE),  a text editor, and a directory lister.  You must sup-
  668.  
  669. ply the text editor and directory lister.  (The ``PC-Write'' edi-
  670.  
  671. tor  works  with  IFP under DOS 2.0 and 3.0; ``edlin'' only works
  672.  
  673. under DOS 3.0; I haven't tried any others).  All three  of  these
  674.  
  675. programs  must  reside  on  a  different disk drive than your IFP
  676.  
  677. functions.  If you have enough memory, it is advantageous to  put
  678.  
  679. these  on a RAM-disk.  The IFP function files should be kept on a
  680.  
  681. floppy or hard disk, just in case your machine crashes.
  682. 
  683.                           IFP Reference                        13
  684.  
  685. 5.3.  Running IFP
  686.  
  687.      Before invoking IFP, two  environment  variables  should  be
  688.  
  689. set.  The  ``EDITOR''  variable should be set to the name of your
  690.  
  691. favorite  editor.   The  default  editor  is  ``c:ed.exe''.   The
  692.  
  693. ``FPDIR''  variable  should  be  set to the name of your favorite
  694.  
  695. directory listing program.  Normally these  variables  should  be
  696.  
  697. set  by  the autoexec.bat file.  Below is an example autoexec.bat
  698.  
  699. file:
  700.  
  701.         set EDITOR = A:edlin.com
  702.         set IFPDIR = A:sd2.com
  703.  
  704.  
  705. 5.4.  Starting IFP
  706.  
  707.  
  708.      To start an IFP session, change your current working  direc-
  709.  
  710. tory  to a directory on the IFP functions disk.  Then execute the
  711.  
  712. ``ifp.exe'' program.  Your current working directory becomes your
  713.  
  714. current  working  IFP  module.   (There  is no way to change your
  715.  
  716. current working directory from within IFP.  To change  it,  leave
  717.  
  718. the  interpreter and change it within DOS.) When IFP is ready, it
  719.  
  720. will respond with the prompt ``ifp> ''.  To end the IFP  session,
  721.  
  722. enter  the command ``exit''. All function definitions are kept in
  723.  
  724. disk files, so you can't lose anything when you exit or the  com-
  725.  
  726. puter crashes.
  727.  
  728.  
  729.      To edit an IFP definition file, type the command:
  730.  
  731.         ed name
  732.  
  733.  
  734. where name is the name of the function to be edited.  (Since  all
  735.  
  736. IFP  reserved  words are upper case, it is a good practice to use
  737.  
  738. lower or mixed case for function names.) The function may be  one
  739.  
  740. local to the current working module, or one that is imported into
  741.  
  742. the current working module.  If  the  function  name  is  neither
  743. 
  744.                           IFP Reference                        14
  745.  
  746. defined  locally  nor  imported,  then  it is assumed to be a new
  747.  
  748. local function.  The function definition  file  must  be  of  the
  749.  
  750. form:
  751.  
  752.  
  753.         DEF name AS f;
  754.  
  755.  
  756. Definitions are in  free  format,  line  breaks  are  treated  as
  757.  
  758. spaces.   Matching pairs of ``(*'' and ``*)'' delimit comments as
  759.  
  760. in Pascal.  Note: Do not switch to another file from  within  the
  761.  
  762. editor.   Always  exit  the  editor  to return to the IFP command
  763.  
  764. interpreter first and then edit the next file.  Otherwise  inter-
  765.  
  766. preter  won't  know  that  its  internal  copy  of  a function is
  767.  
  768. invalid.
  769.  
  770.  
  771.      To apply an IFP function, type the command:
  772.  
  773.  
  774.         show object : function;
  775.  
  776.  
  777. The interpreter evaluates the result of applying the function  to
  778.  
  779. the  object.   The result is then pretty-printed at the terminal.
  780.  
  781. Listing 1 shows a sample session.
  782.  
  783.  
  784.      To list your functions, type the command:
  785.  
  786.  
  787.         dir
  788.  
  789.  
  790. The  directory  listing  program  specified  by  IFPDIR  will  be
  791.  
  792. invoked.   Note:  my  directory lister won't work unless I type a
  793.  
  794. trailing slash, i.e. ``dir/".  I have not tried any other  direc-
  795.  
  796. tory listing programs.
  797.  
  798.  
  799.      To delete a function, type the command:
  800.  
  801.         del f
  802.  
  803. The function definition file (along with the memory copy) will be
  804.  
  805. deleted.   Wildcards  are  not  permitted  in  the function name.
  806. 
  807.                           IFP Reference                        15
  808.  
  809. Warning: do  not  try  to  delete  files  with  extensions  (e.g.
  810.  
  811. ``.bak'')  from  within  IFP, since file names are truncated to 8
  812.  
  813. characters, IFP may delete the wrong file.
  814.  
  815.  
  816. 5.5.  Tracing Functions
  817.  
  818.  
  819.      Currently, IFP has simple program trace mechanism.  To trace
  820.  
  821. a function, respond to the IFP prompt with:
  822.  
  823.  
  824.         trace on f1 ,f2 ,...fn ;
  825.  
  826. where the f's are functions to  be  traced.   Whenever  a  traced
  827.  
  828. function  is  invoked,  its argument and result are shown.  Also,
  829.  
  830. the argument and result of all called functions  are  shown.   To
  831.  
  832. stop tracing functions, respond to the IFP prompt with:
  833.  
  834.  
  835.         trace off f1 ,f2 ,...fn ;
  836.  
  837.  
  838.      When tracing, the interpreter ellipses are used to  abbrevi-
  839.  
  840. ate  functions.   You  can  set the depth at which ellipses occur
  841.  
  842. with the depth command:
  843.  
  844.  
  845.         depth n
  846.  
  847.  
  848. where n is a non-negative integer.  The default depth is two.
  849.  
  850.  
  851.      There is also a functional form  for  creating  trace  func-
  852.  
  853. tions.  Its form is
  854.  
  855.  
  856.         @string
  857. 
  858.                           IFP Reference                        16
  859.  
  860. The function formed always returns its argument unchanged, and it
  861.  
  862. prints ``string: '' followed by its argument.  For example,
  863.  
  864.  
  865.         <1 3 5> : EACH @banana END
  866.  
  867.  
  868. will print the messages:
  869.  
  870.  
  871.         banana: 1
  872.         banana: 2
  873.         banana: 3
  874.  
  875.  
  876. This tracing functional form is  for  debugging  only,  since  it
  877.  
  878. creates a side effect (the message!), it is not truly functional.
  879.  
  880.  
  881.      Program execution can be aborted at  any  time  by  pressing
  882.  
  883. control-C.   A  trace  of  where  the function was will be shown.
  884.  
  885. Pressing control-C again will abort the trace.
  886.  
  887.  
  888.  
  889.  
  890.                         December 5, 1985
  891.  
  892.