From af3e0d104a70c3bba418f32583006ad31accd8a8 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Wed, 1 Mar 2017 00:33:51 +0100 Subject: [PATCH] Issue 5079/2: with-music-match: lists should match completely Previously music properties that were matched to a list of wildcards could contain fewer elements than the list they were matched to, leading to an error when the wildcard variable was being assigned to. Now the list lengths have to be matched exactly: a shorter pattern than the actual list length of the matched property cannot match any more. --- scm/display-lily.scm | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/scm/display-lily.scm b/scm/display-lily.scm index 6a53f1eded..b5a7cff139 100644 --- a/scm/display-lily.scm +++ b/scm/display-lily.scm @@ -190,20 +190,18 @@ match thoses described in `pattern'." ;; build the test conditions for each element found in a (property . (e1 e2 ...)) pair. ;; this requires accessing to an element of a list, hence the index. ;; (typically, property will be 'elements) - ,@(map (lambda (prop-elements) - (let ((ges (gensym)) - (index -1)) - `(and ,@(map (lambda (e) - (set! index (1+ index)) - (if (music? e) - (gen-condition `(and (> (length (ly:music-property ,expr ',(car prop-elements))) - ,index) - (list-ref (ly:music-property ,expr ',(car prop-elements)) - ,index)) - e) - #t)) - (cdr prop-elements))))) - elements-list)))) + ,@(map + (lambda (prop-elements) + (let ((ges (gensym)) + (len (length (cdr prop-elements)))) + `(let ((,ges (ly:music-property ,expr ',(car prop-elements)))) + (and (eqv? (length+ ,ges) ,len) + ,@(filter-map + (lambda (e index) + (and (music? e) + (gen-condition `(list-ref ,ges ,index) e))) + (cdr prop-elements) (iota len)))))) + elements-list)))) (define (gen-bindings expr pattern) "Helper function for `with-music-match'. @@ -269,10 +267,9 @@ inside body." (pattern (second music-expr+pattern)) (expr-sym (gensym))) `(let ((,expr-sym ,music-expr)) - (if ,(gen-condition expr-sym pattern) - (let ,(gen-bindings expr-sym pattern) - ,@body) - #f)))) + (and ,(gen-condition expr-sym pattern) + (let ,(gen-bindings expr-sym pattern) + ,@body))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; -- 2.39.2