Eliminate use of map*, append-map*, append-map*!.
authorChris Hanson <org/chris-hanson/cph>
Thu, 5 Dec 2019 00:19:41 +0000 (16:19 -0800)
committerChris Hanson <org/chris-hanson/cph>
Mon, 9 Dec 2019 09:49:28 +0000 (01:49 -0800)
15 files changed:
src/compiler/back/regmap.scm
src/compiler/base/pmerly.scm
src/compiler/base/utils.scm
src/compiler/fggen/fggen.scm
src/compiler/machines/svm/assembler-compiler.scm
src/ffi/generator.scm
src/imail/imail-top.scm
src/runtime/dynamic.scm
src/runtime/environment.scm
src/runtime/mit-macros.scm
src/sf/copy.scm
src/sf/pardec.scm
src/sf/tables.scm
src/sf/xform.scm
src/xdoc/xdoc.scm

index 1d2083a092d36ad5ce855175d8932c63886ddc06..89ee290464edf3b2efcaaae135b0edcd8abe738f 100644 (file)
@@ -311,9 +311,11 @@ registers into some interesting sorting order.
   (if (null? entries)
       regmap
       (make-register-map
-       (map* (map-entries:delete* regmap entries)
-            pseudo-register-entry->temporary-entry
-            entries)
+       (fold-right (lambda (reg entries)
+                    (cons (pseudo-register-entry->temporary-entry reg)
+                          entries))
+                  (map-entries:delete* regmap entries)
+                  entries)
        (map-registers regmap))))
 \f
 (define (register-map:keep-live-entries map live-registers)
index 58ff5b19673dbc22a48ac87e3d4e5f1db2daf560..95d9dde6e00ff9e868ab0ff19158f6d2afbe3196 100644 (file)
@@ -665,11 +665,12 @@ USA.
              (make-unassigned-reference-trap))
    '()
    (scode/make-sequence
-    (map* body
-         (lambda (binding)
-           (scode/make-assignment (scode/binding-variable binding)
-                                  (scode/binding-value binding)))
-         bindings))))
+    (fold-right (lambda (binding exprs)
+                 (cons (scode/make-assignment (scode/binding-variable binding)
+                                              (scode/binding-value binding))
+                       exprs))
+               body
+               bindings))))
 \f
 (define (scode/make-case-expression expression default clauses)
   (define (kernel case-selector)
index 7406976ca21dc97bc3cb18210dc98d991e6a3d1c..99dc8d6e45f7115f37e3c8e2de94c9026fd88a95 100644 (file)
@@ -509,11 +509,19 @@ USA.
   (let ((names (global-valued function-additional-names)))
     (let ((procedures (map global-value names)))
       (set! function-variables
-           (map* boolean-valued-function-variables cons names procedures))))
+           (fold-right (lambda (name proc vars)
+                         (cons (cons name proc) vars))
+                       boolean-valued-function-variables
+                       names
+                       procedures))))
   (let ((names (global-valued side-effect-free-additional-names)))
     (let ((procedures (map global-value names)))
       (set! side-effect-free-variables
-           (map* function-variables cons names procedures))))
+           (fold-right (lambda (name proc vars)
+                         (cons (cons name proc) vars))
+                       function-variables
+                       names
+                       procedures))))
   unspecific)
 
 (define function-primitives
index bf8e2df40e4e33287741c9186edbc456cec5c72b..4629bcb136dbbd24b4226997991699a877bfd025 100644 (file)
@@ -455,7 +455,12 @@ USA.
                     (scode/make-lambda
                      scode-lambda-name:let auxiliary '() #f names '()
                      (scode/make-sequence
-                      (map* actions scode/make-assignment names values)))
+                      (fold-right (lambda (name value exprs)
+                                    (cons (scode/make-assignment name value)
+                                          exprs))
+                                  actions
+                                  names
+                                  values)))
                     (map (lambda (name)
                            name ;; ignored
                            (make-unassigned-reference-trap))
index 7fef59ea72e4d1c26ea5264e69c2990d3ada096c..6c49e4a913f252a3f4109f72de39357eaff697bf 100644 (file)
@@ -249,12 +249,14 @@ USA.
 (define (expand-abbrevs inputs abbrevs)
   (receive (abbrev-defs inputs) (split-list inputs abbrev-def?)
     (let ((abbrevs
-          (map* abbrevs
-                (lambda (abbrev-def)
-                  (cons `(',(caadr abbrev-def) ,@(cdadr abbrev-def))
-                        (eval (caddr abbrev-def)
-                              (make-top-level-environment))))
-                abbrev-defs))
+          (fold-right (lambda (abbrev-def abbrevs)
+                        (cons (cons `(',(caadr abbrev-def)
+                                      ,@(cdadr abbrev-def))
+                                    (eval (caddr abbrev-def)
+                                          (make-top-level-environment)))
+                              abbrevs))
+                      abbrevs
+                      abbrev-defs))
          (any-expansions? #f))
       (let ((outputs
             (append-map (lambda (input)
index f848e27df0b0383f575ed04eb688c27896c3d945..0dc8f4f81496af553669cbe053296f9d6eded26b 100644 (file)
@@ -587,36 +587,38 @@ grovel_enums (FILE * out)
 
 (define (gen-struct-grovel-funcs includes)
   ;; Returns the names of the generated functions.
-  (append-map*!
+  (fold-right
+   (lambda (name.info result)
+     ;; Typedefs giving names to struct types.
+     (let* ((name (car name.info))
+           (ctype (definite-ctype name includes)))
+       (if (ctype/struct? ctype)
+          (cons (gen-struct-union-grovel-func name includes)
+                result)
+          result)))
    (map (lambda (name.info)
          ;; The named structs, top-level OR internal.
          (let ((name (list 'struct (car name.info))))
            (gen-struct-union-grovel-func name includes)))
        (c-includes/structs includes))
-   (lambda (name.info)
-     ;; Typedefs giving names to struct types.
-     (let* ((name (car name.info))
-           (ctype (definite-ctype name includes)))
-       (if (ctype/struct? ctype)
-          (list (gen-struct-union-grovel-func name includes))
-          '())))
    (c-includes/type-names includes)))
 
 (define (gen-union-grovel-funcs includes)
   ;; Returns the names of the generated functions.
-  (append-map*!
+  (fold-right
+   (lambda (name.info result)
+     ;; Typedefs giving names to union types.
+     (let* ((name (car name.info))
+           (ctype (definite-ctype name includes)))
+       (if (ctype/union? ctype)
+          (cons (gen-struct-union-grovel-func name includes)
+                result)
+          result)))
    (map (lambda (name.info)
          ;; The named unions, top-level OR internal.
          (let ((name (list 'union (car name.info))))
            (gen-struct-union-grovel-func name includes)))
        (c-includes/unions includes))
-   (lambda (name.info)
-     ;; Typedefs giving names to union types.
-     (let* ((name (car name.info))
-           (ctype (definite-ctype name includes)))
-       (if (ctype/union? ctype)
-          (list (gen-struct-union-grovel-func name includes))
-          '())))
    (c-includes/type-names includes)))
 
 (define (gen-struct-union-grovel-func name includes)
index f14814a95b21d8b4da9af13877f5ff4836236311..08b6747b4899f42d11177da6b4c9145404febcf5 100644 (file)
@@ -2307,14 +2307,16 @@ WARNING: With a prefix argument, this command may take a very long
           (cond ((ref-variable imail-kept-headers context)
                  => (lambda (regexps)
                       (remove-duplicates!
-                       (append-map*!
+                       (fold-right
+                        (lambda (regexp result)
+                          (append! (filter (lambda (header)
+                                             (re-string-match
+                                              regexp
+                                              (header-field-name header)
+                                              #t))
+                                           headers)
+                                   result))
                         (mime-headers)
-                        (lambda (regexp)
-                          (filter (lambda (header)
-                                    (re-string-match regexp
-                                                     (header-field-name header)
-                                                     #t))
-                                  headers))
                         regexps)
                        (lambda (a b) (eq? a b)))))
                 ((ref-variable imail-ignored-headers context)
index fc9a13c823f745b22ea7f1985475b71ffeddaed1..81c3a0f1c306857c354916bafd7f5a091b2a0c75 100644 (file)
@@ -102,9 +102,11 @@ USA.
 (define (parameterize* new-bindings thunk)
   (guarantee alist? new-bindings 'parameterize*)
   (let ((temp
-        (map* bindings
-              (lambda (p) (create-binding (car p) (cdr p)))
-              new-bindings)))
+        (fold-right (lambda (p bindings)
+                      (cons (create-binding (car p) (cdr p))
+                            bindings))
+                    bindings
+                    new-bindings)))
     (let ((swap!
           (lambda ()
             (set! bindings (set! temp (set! bindings)))
index 5d892ae8acb5e03e9b1f39eb08d14d99a017aff7..5969c36d1c3275d9f6080250bd21213d3f8ba1f3 100644 (file)
@@ -629,12 +629,14 @@ USA.
                       (stack-ccenv/safe-lookup
                        environment
                        (dbg-variable/name variable)))))))
-         (map* (map* (let ((rest (dbg-procedure/rest procedure)))
-                       (if rest (lookup rest) '()))
-                     lookup
-                     (dbg-procedure/optional procedure))
-               lookup
-               (dbg-procedure/required procedure)))
+         (fold-right (lambda (variable values)
+                       (cons (lookup variable) values))
+                     (fold-right (lambda (variable values)
+                                   (cons (lookup variable) values))
+                                 (let ((rest (dbg-procedure/rest procedure)))
+                                   (if rest (lookup rest) '()))
+                                 (dbg-procedure/optional procedure))
+                     (dbg-procedure/required procedure)))
        'unknown)))
 
 (define (stack-ccenv/bound-names environment)
index da5dd480d451cda8c28c7b3880c394cfcff14441..3082ae9cfdf4527eb7520babfb22734353521529 100644 (file)
@@ -535,11 +535,12 @@ USA.
                               (scons-lambda '() expr)
                               (apply scons-lambda
                                      temp-bvl
-                                     (map* (list (unspecific-expression))
-                                           (lambda (name temp)
-                                             (scons-set! name temp))
-                                           names
-                                           temps))))))))))))
+                                     (fold-right (lambda (name temp exprs)
+                                                   (cons (scons-set! name temp)
+                                                         exprs))
+                                                 (list (unspecific-expression))
+                                                 names
+                                                 temps))))))))))))
 \f
 ;;; This optimizes some simple cases, but it could be better.  Among other
 ;;; things it could take advantage of arity-dispatched procedures in the right
index 834154485dd5c28bd9ea434a32385e25a0282f65..36ec6749246fdde327147576b7a95dde30c6ce54 100644 (file)
@@ -67,7 +67,11 @@ USA.
   '())
 
 (define (environment/bind environment variables values)
-  (map* environment cons variables values))
+  (fold-right (lambda (var val env)
+               (cons (cons var val) env))
+             environment
+             variables
+             values))
 
 (define (environment/lookup environment variable if-found if-not)
   (guarantee-variable variable 'environment/lookup)
index 63997b31fe09e1589490f8428903a5f732efbf43..40492ea2248a03bcdd8368ffd8d78193deb50211 100644 (file)
@@ -233,19 +233,21 @@ USA.
          (for-each (constructor 'integrate)
                    constant-names
                    constant-values)))
-      (map* declarations
-           (let ((top-level-block
-                  (let loop ((block block))
-                    (if (block/parent block)
-                        (loop (block/parent block))
-                        block))))
-             (lambda (remaining)
-               (make-declaration
-                (vector-ref remaining 0)
-                (variable/make&bind! top-level-block (vector-ref remaining 1))
-                (vector-ref remaining 2)
-                'global)))
-           remaining))))
+      (fold-right (let ((top-level-block
+                        (let loop ((block block))
+                          (if (block/parent block)
+                              (loop (block/parent block))
+                              block))))
+                   (lambda (remaining decls)
+                     (cons (make-declaration
+                            (vector-ref remaining 0)
+                            (variable/make&bind! top-level-block
+                                                 (vector-ref remaining 1))
+                            (vector-ref remaining 2)
+                            'global)
+                           decls)))
+                 declarations
+                 remaining))))
 \f
 ;;; The corresponding case for R7RS is much simpler since the imports are
 ;;; explicit.
index 8933fca79983422134820c1736796014a4c06823..dc0a520f642f526ffda3e43c785cc439308b3bbc 100644 (file)
@@ -44,7 +44,11 @@ USA.
   (alist-cons variable value environment))
 
 (define-integrable (environment/bind-multiple environment variables values)
-  (map* environment cons variables values))
+  (fold-right (lambda (var val env)
+               (cons (cons var val) env))
+             environment
+             variables
+             values))
 
 (define (environment/lookup environment variable if-found if-unknown if-not)
   (let ((association (assq variable environment)))
@@ -217,11 +221,11 @@ USA.
        (if-not))))
 
 (define (operations/shadow operations variables)
-  (vector (map* (vector-ref operations 0)
-               (lambda (variable)
-                 (guarantee-variable variable 'operations/shadow)
-                 (cons variable false))
-               variables)
+  (vector (fold-right (lambda (variable operations)
+                       (guarantee-variable variable 'operations/shadow)
+                       (cons (cons variable false) operations))
+                     (vector-ref operations 0)
+                     variables)
          (vector-ref operations 1)
          (vector-ref operations 2)))
 
index 22209149a6e16b9231a4e04cf1dd79ca25dec077..a5075eecf7d1414b18e8b3607efb8bbc53e9ad23 100644 (file)
@@ -114,10 +114,11 @@ USA.
            (variable/make&bind! top-level-block name)))))
 
 (define (environment/bind environment variables)
-  (map* environment
-       (lambda (variable)
-         (cons (variable/name variable) variable))
-       variables))
+  (fold-right (lambda (variable env)
+               (cons (cons (variable/name variable) variable)
+                     env))
+             environment
+             variables))
 \f
 (define (transform/open-block block environment expression)
   (transform/open-block* expression
index 39ae99b48942c8d2cf7aa7e2b75aa393b41872bf..350da57ee3b32d077c2cfbb50292f3314eec314b 100644 (file)
@@ -1275,17 +1275,19 @@ USA.
   (filter preserved-attribute? (xml-element-attributes elt)))
 
 (define (merge-attributes attrs defaults)
-  (map* (remove (lambda (attr)
-                 (%find-attribute (xml-attribute-name attr) attrs))
-               defaults)
-       (lambda (attr)
-         (let ((attr*
-                (and (merged-attribute? attr)
-                     (%find-attribute (xml-attribute-name attr) defaults))))
-           (if attr*
-               (merge-attribute attr attr*)
-               attr)))
-       attrs))
+  (fold-right (lambda (attr attrs)
+               (cons (let ((attr*
+                            (and (merged-attribute? attr)
+                                 (%find-attribute (xml-attribute-name attr)
+                                                  defaults))))
+                       (if attr*
+                           (merge-attribute attr attr*)
+                           attr))
+                     attrs))
+             (remove (lambda (attr)
+                       (%find-attribute (xml-attribute-name attr) attrs))
+                     defaults)
+             attrs))
 
 (define (preserved-attribute? attr)
   (let ((name (xml-attribute-name attr)))