From 1dc774fbea585861dd3c958f8ae1efa95e5165fe Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sat, 14 Sep 2013 11:09:18 +0200 Subject: [PATCH] Issue 3552: Don't modify lists returned by markup list functions in interpret-markup-list This requires either a) copying any list manually b) interpreting markup lists right-to-left c) more complicated and/or non-O(n) algorithms This patch chooses b). Modifying the lists is not really appropriate since the lists may be created by user-written markup commands and any problems resulting from not expecting modifications of the return value might be quite hard to debug. --- scm/markup.scm | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/scm/markup.scm b/scm/markup.scm index 69a6ad13ff..64a1139738 100644 --- a/scm/markup.scm +++ b/scm/markup.scm @@ -48,16 +48,13 @@ Example: (define-public interpret-markup ly:text-interface::interpret-markup) (define-public (interpret-markup-list layout props markup-list) - ;; This relies on the markup list returned by a markup list command - ;; to be modifiable - (reverse! - (fold - (lambda (m prev) - (if (markup-command-list? m) - (reverse! (apply (car m) layout props (cdr m)) prev) - (cons (interpret-markup layout props m) prev))) - '() - markup-list))) + (fold-right + (lambda (m prev) + (if (markup-command-list? m) + (append (apply (car m) layout props (cdr m)) prev) + (cons (interpret-markup layout props m) prev))) + '() + markup-list)) (define-public (prepend-alist-chain key val chain) (cons (acons key val (car chain)) (cdr chain))) -- 2.39.5