Annotation of researchv10dc/cmd/icon/ipl/source/lmap.icn, revision 1.1.1.1

1.1       root        1: #      LMAP
                      2: #
                      3: #      Map list
                      4: #
                      5: #      Ralph E. Griswold
                      6: #
                      7: #      Last modified 12/15/85
                      8: #
                      9: 
                     10: # This procedure is modeled after the built-in string mapping function.
                     11: # The main difference is that the first argument is modified, rather
                     12: # than constructing a new list. This is in the interests of efficiency
                     13: # and likely uses, but is easily changed.
                     14: #
                     15: # Warning:  a2 and a3 are cached so that the table of correspondences
                     16: # is not rebuilt if lmap is called successively with the same mapping
                     17: # lists. Just because a2 and a3 are the same does not mean that they
                     18: # have the same values on successive calls of lmap. Thus, the
                     19: # equivalence of maps is taken from the value of a2 and a3, not their
                     20: # respective elements. This is deliberate, but could result in
                     21: # unexpected results.
                     22: 
                     23: procedure lmap(a1,a2,a3)
                     24:    static lmem2, lmem3, lmaptbl, tdefault
                     25:    local i
                     26:    initial tdefault := []
                     27:    if not(type(a1) == type(a2) == type(a3) == "list")
                     28:       then stop("illegal type in lmap")
                     29:    if not(*a2 = *a3)
                     30:       then stop("Run-time error:\nSecond and third arguments of lmap differ in length")
                     31:    if not(lmem2 === a2 & lmem3 === a3) then {  # if an argument is new, rebuild
                     32:       lmem2 := a2                              # save for future reference
                     33:       lmem3 := a3
                     34:       lmaptbl := table(tdefault)               # new mapping table
                     35:       every i := 1 to *a2 do                   # build the map
                     36:          lmaptbl[a2[i]] := a3[i]
                     37:       }
                     38:    every i := 1 to *a1 do                      # map the values
                     39:       a1[i] := (tdefault ~=== lmaptbl[a1[i]])
                     40:    return a1
                     41: end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.