home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / logo / powerlogo / utilities / words-lists.doc < prev    next >
Text File  |  1992-11-10  |  9KB  |  235 lines

  1.  
  2.    Words-Lists.doc
  3.  
  4. Some procedures for processing words and lists. Some of these procedures
  5. require sub-procedures defined in the default 'LOGO-Startup' file.
  6.  
  7.  
  8. col-print      object ( margin spacing )
  9.          object = Any list or word.
  10.          margin = Integer.
  11.          spacing = Integer.
  12.    Prints the contents of a (flat) list in vertical columns.  `margin'
  13.    is the number of spaces from the left to start the first column
  14.    (default is 0).  `spacing' is the minimum number of spaces required
  15.    between columns (from end of longest item to start of next column)
  16.    (default is 4).
  17.  
  18. dr             ( path pattern )
  19.                ( path pattern-list )
  20.          path = An AmigaDOS directory name (word or list).
  21.          pattern = Word, a match pattern. Within a pattern the asterisk
  22.                    (*) is a wild card and will match any group of zero
  23.                    or more characters. A pattern that starts with a
  24.                    tilde (~) will match anything that does not match the
  25.                    rest of the pattern.
  26.          pattern-list = A list of patterns.
  27.    Print out contents of directory.
  28.  
  29. dra            ( path pattern )
  30.                ( path pattern-list )
  31.          path = An AmigaDOS directory name (word or list).
  32.          pattern = Word, a match pattern. Within a pattern the asterisk
  33.                    (*) is a wild card and will match any group of zero
  34.                    or more characters. A pattern that starts with a
  35.                    tilde (~) will match anything that does not match the
  36.                    rest of the pattern.
  37.          pattern-list = A list of patterns.
  38.    Print out contents of directory, and all sub directories.
  39.  
  40. eval          run-object
  41.          run-object = Word, or list of LOGO instructions.
  42.    Similar to `run', but can be used on words as well as lists.
  43.  
  44. for           word n1 n2 n3 run-list
  45.          word = Name of the loop variable.
  46.          n1 = Number; initial value.
  47.          n2 = Number; final value.
  48.          n3 = Number; stepping value.
  49.          run-list = List of LOGO instructions.
  50.    The `for loop' executes the run list repeatedly, while assigning
  51.    values to the loop variable.  On the first iteration, the loop variable
  52.    is assigned the value of `n1'.  On subsequent iterations, the loop
  53.    variable is adjusted `n3'.  When the loop variable "goes beyond" `n2',
  54.    the loop stops.  The loop variable should be local to calling
  55.    procedure.  The run list should not produce an output.  Use `ignore',
  56.    if necessary.  See examples below.
  57.  
  58. foreach       word object run-list
  59.          word = Name of the loop variable.
  60.          object = Any word or list.
  61.          run-list = List of LOGO instructions.
  62.    The `foreach loop' executes the run list repeatedly, while assigning
  63.    values to the loop variable.  On each iteration, the loop variable is
  64.    assigned, in order, an item from `object'.  The loop variable should be
  65.    local to calling procedure.  The run list should not produce an output.
  66.    Use `ignore', if necessary.  See examples below.
  67.  
  68. lcase          object
  69.          object = Any word or list.
  70.    Output is just like input with all upper case letters converted to
  71.    lower case.
  72.  
  73. link           name
  74.          name = Word, a procedure name.
  75.    Output list of all procedures needed to run the named procedure.
  76.  
  77. list->word     list
  78.          list = Any non-nested (flat) list.
  79.    Concatenates the words in the list into a single word.
  80.  
  81. map            procedure object
  82.          procedure = A word that is a procedure name or list of commands
  83.                      that will operate on a single argument.
  84.          object = Any list or word.
  85.    Output object after applying the procedure to each item.  Example,
  86.    `map [ + 1 ] [ 1 2 3 4 ]' produces `[ 2 3 4 5 ]'.
  87.  
  88. map2           procedure object object
  89.          procedure = A word that is a procedure name or list of commands
  90.                      that will operate on two arguments.
  91.          object = Any list or word.
  92.    Output object that results from applying the procedure to items taken,
  93.    in order, from objects.  The objects would normally be of the same
  94.    length, but may be of different lengths, in which case the "extra" is
  95.    appended to the result.  See examples below.
  96.  
  97. matchp         pattern word
  98.                pattern-list word
  99.          pattern = Word, a match pattern. Within a pattern the asterisk
  100.                    (*) is a wild card and will match any group of zero
  101.                    or more characters. A pattern that starts with a
  102.                    tilde (~) will match anything that does not match the
  103.                    rest of the pattern.
  104.          pattern-list = A list of patterns.
  105.          word = Any word.
  106.    Output true if word fits pattern.
  107.  
  108. patfilter      pattern list
  109.                pattern-list list
  110.          pattern = Word, a match pattern. Within a pattern the asterisk
  111.                    (*) is a wild card and will match any group of zero
  112.                    or more characters. A pattern that starts with a
  113.                    tilde (~) will match anything that does not match the
  114.                    rest of the pattern.
  115.          pattern-list = A list of patterns.
  116.          list = A list of words.
  117.    Output list of all words in the list that fit the pattern.
  118.  
  119. reduce        procedure obj1 obj2
  120.          procedure = A word that is a procedure name or list of commands
  121.                      that will operate on two arguments.
  122.          obj1 = Any list or word that will serve as the `zero case'.
  123.          obj2 = Any list or word that is to be operated on.
  124.    Output the result of recursively applying the procedure to `obj2' with
  125.    `obj1' serving as the base or `zero' case.  See examples below.
  126.  
  127. sdir           ( path pattern )
  128.                ( path pattern-list )
  129.          path = An AmigaDOS directory name (word or list).
  130.          pattern = Word, a match pattern. Within a pattern the asterisk
  131.                    (*) is a wild card and will match any group of zero
  132.                    or more characters. A pattern that starts with a
  133.                    tilde (~) will match anything that does not match the
  134.                    rest of the pattern.
  135.          pattern-list = A list of patterns.
  136.    Output sorted directory list.
  137.  
  138. sdira          ( path pattern )
  139.                ( path pattern-list )
  140.          path = An AmigaDOS directory name (word or list).
  141.          pattern = Word, a match pattern. Within a pattern the asterisk
  142.                    (*) is a wild card and will match any group of zero
  143.                    or more characters. A pattern that starts with a
  144.                    tilde (~) will match anything that does not match the
  145.                    rest of the pattern.
  146.          pattern-list = A list of patterns.
  147.    Output sorted directory list.
  148.  
  149. ucase          object
  150.          object = Any word or list.
  151.    Output is just like input with all lower case letters converted to
  152.    upper case.
  153.  
  154. word->ascii    word
  155.          word = Any word.
  156.    Converts a word into a list of ASCII values for each characters.
  157.  
  158. word->list     word
  159.          word = Any word.
  160.    Converts a word into a list of single character words.
  161.  
  162. Examples:
  163.  
  164. The following procedure illustrates the use of `for':
  165.  
  166.    make "countdown [
  167.      procedure [ [ ] [ ] [ :cnt ] ]
  168.      for "cnt 10 1 -1 [
  169.        pr :cnt
  170.        wait 1 ]
  171.      pr "Blast-off! ]
  172.  
  173. The following procedure illustrates the use of `foreach':
  174.  
  175.    make "vertical-word [
  176.      procedure [ [ :wrd ] [ ] [ :chr ] ]
  177.      foreach "chr :wrd [ pr :chr ] ]
  178.  
  179. The following are examples of using map2:
  180.  
  181.    map2 "+ [ 1 2 3 ] [ 4 5 6 ]
  182.    [ 5 7 9 ]
  183.  
  184.    map2 [ * 2 + ] [ 1 2 3 ] [ 2 3 4 5 ]
  185.    [ 6 10 14 5 ]
  186.  
  187.    map2 "fput "xxx [ a b c ]
  188.    [ xa xb xc ]
  189.  
  190.    map2 "fput "xxx [ a b c d ]
  191.    [ xa xb xc d ]
  192.  
  193.    map2 "fput "xxxx [ a b c ]
  194.    xaxbxcx
  195.  
  196. Reduce is a powerful, advanced programming construct for operating on
  197. lists and words.  Several procedures in this file make use of it (see
  198. list->word, word->list and word->ascii).  (There are others that could have
  199. used reduce, but were "hard-coded" for speed.)  Reduce recursively applies
  200. a function to the elements of an object.  When the "end" of the object is
  201. reached, the `zero case' is used to complete the process.  To sum the
  202. numbers in a list, for example:
  203.  
  204.    reduce "+ 0 [ 1 2 3 4 ]
  205.    10
  206.  
  207. `reduce' effective produces the following:
  208.  
  209.    + 1 + 2 + 3 + 4 0
  210.  
  211. Similarly,
  212.  
  213.    reduce "* 1 [ 2 3 4 5 ]
  214.    120
  215.  
  216. is equivalent to:
  217.  
  218.    * 2 * 3 * 4 * 5 1
  219.  
  220. To reverse a list, we could use:
  221.  
  222.    make "rev-list [
  223.      procedure [ [ :lst ] ]
  224.      output reduce "lput [ ] :lst ]
  225.  
  226. which would work as follows:
  227.  
  228.    rev-list [ a b c ]
  229.    [ c b a ]
  230.  
  231. which is equivalent to:
  232.  
  233.    lput a lput b lput c [ ]
  234.  
  235.