From 01fc086e62c037ccf12f9d3ed32debae4488146c Mon Sep 17 00:00:00 2001 From: Nikolay Puzanov Date: Wed, 30 Nov 2022 18:02:43 +0300 Subject: [PATCH] Add substitute function --- embddr/common.scm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/embddr/common.scm b/embddr/common.scm index 50859de..7efb175 100644 --- a/embddr/common.scm +++ b/embddr/common.scm @@ -19,6 +19,7 @@ has-duplicates? find-duplicates insert-between string-replace-text + substitute read-template make-mux-selectors)) @@ -194,6 +195,15 @@ str)) str)))))) +;;; Substitute template +(define (substitute text template-format subst-list) + (fold (lambda (s out) + (string-replace-text + out + (format template-format (first s)) + (format "~a" (second s)))) + text subst-list)) + ;;; Read template and substitute replacements ;;; Returns list of strings (lines) (define (read-template template-file template-format subst-list) @@ -204,10 +214,6 @@ (if (eof-object? s) (reverse l) (loop (cons s l))))))))) - (map (lambda (str) (fold (lambda (s out) - (string-replace-text - out - (format template-format (first s)) - (format "~a" (second s)))) - str subst-list)) + (map (lambda (str) + (substitute str template-format subst-list)) ls)))