1 ;;;; fret-diagrams.scm --
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2004--2006 Carl D. Sorensen <c_sorensen@byu.edu>
7 (define (fret-parse-marking-list marking-list fret-count)
8 (let* ((fret-range (list 1 fret-count))
13 (let parse-item ((mylist marking-list))
14 (if (not (null? mylist))
15 (let* ((my-item (car mylist)) (my-code (car my-item)))
17 ((or (eq? my-code 'open)(eq? my-code 'mute))
18 (set! xo-list (cons* my-item xo-list)))
20 (set! barre-list (cons* (cdr my-item) barre-list)))
21 ((eq? my-code 'place-fret)
22 (set! dot-list (cons* (cdr my-item) dot-list))))
23 (parse-item (cdr mylist)))))
24 ; calculate fret-range
25 (let ((maxfret 0) (minfret 99))
26 (let updatemax ((fret-list dot-list))
29 (let ((fretval (second (car fret-list))))
30 (if (> fretval maxfret) (set! maxfret fretval))
31 (if (< fretval minfret) (set! minfret fretval))
32 (updatemax (cdr fret-list)))))
33 (if (> maxfret fret-count)
34 (set! fret-range (list minfret
35 (let ((upfret (- (+ minfret fret-count) 1)))
36 (if (> maxfret upfret) maxfret upfret)))))
37 ; subtract fret from dots
38 (set! dot-list (subtract-base-fret (- (car fret-range) 1) dot-list)))
39 (acons 'fret-range fret-range
40 (acons 'barre-list barre-list
41 (acons 'dot-list dot-list
42 (acons 'xo-list xo-list '()))))))
44 (define (subtract-base-fret base-fret dot-list)
45 "Subtract @var{base-fret} from every fret in @var{dot-list}"
48 (let ((this-list (car dot-list)))
49 (cons* (list (car this-list) (- (second this-list) base-fret) (if (null? (cddr this-list))
52 (subtract-base-fret base-fret (cdr dot-list))))))
54 (define (sans-serif-stencil layout props mag text)
55 "create a stencil in sans-serif font based on @var{layout} and @var{props}
56 with magnification @varr{mag} of the string @var{text}."
57 (let* ((my-props (prepend-alist-chain 'font-size (stepmag mag)
58 (prepend-alist-chain 'font-family 'sans props))))
59 (interpret-markup layout my-props text)))
62 (define (draw-strings string-count fret-range th size)
63 "Draw the strings (vertical lines) for a fret diagram with
64 @var{string-count} strings and frets as indicated in @var{fret-range}.
65 Line thickness is given by @var{th}, fret & string spacing by
67 (let* ((fret-count (+ (- (cadr fret-range) (car fret-range)) 1))
68 (sl (* (+ fret-count 1) size))
70 (half-thickness (* sth 0.5))
72 (string-stencil (ly:make-stencil (list 'draw-line sth 0 0 0 sl)
73 (cons (- half-thickness) half-thickness)
74 (cons (- half-thickness) (+ sl half-thickness)))))
75 (if (= string-count 1)
77 (ly:stencil-combine-at-edge
78 (draw-strings (- string-count 1) fret-range th size) X RIGHT
82 (define (draw-fret-lines fret-count string-count th size)
83 "Draw @var{fret-count} frets (horizontal lines) for a fret diagram
84 with @var{string-count} strings. Line thickness is given by @var{th},
85 fret & string spacing by @var{size}. "
86 (let* ((fret-length (* (- string-count 1) size))
88 (half-thickness (* sth 0.5))
90 (fret-line (ly:make-stencil (list 'draw-line sth half-thickness size (- fret-length half-thickness) size)
92 (cons (- size half-thickness) (+ size half-thickness)))))
95 (ly:stencil-combine-at-edge fret-line Y UP
96 (draw-fret-lines (- fret-count 1) string-count th size)
99 (define (draw-thick-top-fret props string-count th size)
100 "Draw a thick top fret for a fret diagram whose base fret is not 1."
101 (let* ((sth (* th size))
102 ; (top-fret-thick (* sth (chain-assoc-get 'top-fret-thickness props 3.0)))
103 (top-fret-thick (* sth 3.0))
104 ; (top-half-thick (* top-fret-thick 0.5))
105 (half-thick (* sth 0.5))
107 (x2 (+ half-thick (* size (- string-count 1))))
109 (y2 (+ top-fret-thick half-thick))
110 (x-extent (cons (- x1) x2))
111 (y-extent (cons 0 y2)))
112 (ly:make-stencil (list 'round-filled-box x1 x2 y1 y2 sth)
116 (define (draw-frets layout props fret-range string-count th size)
117 "Draw the frets (horizontal lines) for a fret diagram with
118 @var{string-count} strings and frets as indicated in @var{fret-range}.
119 Line thickness is given by @var{th}, fret & string spacing by
121 (let* ((fret-count (+ (- (cadr fret-range) (car fret-range)) 1))
122 (fret-length (* (- string-count 1) size))
123 (half-thickness (* th 0.5))
124 (base-fret (car fret-range)))
125 (ly:stencil-combine-at-edge
126 (draw-fret-lines fret-count string-count th size) Y UP
128 (draw-thick-top-fret props string-count th size)
129 (draw-fret-lines 1 string-count th size))
133 (define (draw-dots layout props string-count fret-range size finger-code
134 dot-position dot-radius dot-thickness dot-list)
135 "Make dots for fret diagram."
136 (let* ((scale-dot-radius (* size dot-radius))
137 (scale-dot-thick (* size dot-thickness))
138 (dot-color (chain-assoc-get 'dot-color props 'black))
139 ; (finger-xoffset (chain-assoc-get 'finger-xoffset props -0.25))
140 ; (finger-yoffset (chain-assoc-get 'finger-yoffset props (- size)))
141 (finger-xoffset -0.25)
142 (finger-yoffset (- (* size 0.5)))
143 ; (dot-label-font-mag (* scale-dot-radius (chain-assoc-get 'dot-label-font-mag props 1.0)))
144 (dot-label-font-mag scale-dot-radius)
145 ; (string-label-font-mag (* size (chain-assoc-get 'label-font-mag props 0.7)))
146 (string-label-font-mag (* size 0.6))
147 (fret-count (+ (- (cadr fret-range) (car fret-range) 1)))
148 (mypair (car dot-list))
149 (restlist (cdr dot-list))
150 (xpos (* size (- string-count (car mypair))))
151 ;TODO -- figure out what 4 is and get rid of it
153 (ypos (* size (+ 4 (- fret-count (cadr mypair) dot-position ))))
154 (extent (cons (- scale-dot-radius) scale-dot-radius))
155 (finger (caddr mypair))
156 (finger (if (number? finger) (number->string finger) finger))
157 (dotstencil (if (eq? dot-color 'white)
159 (make-circle-stencil scale-dot-radius scale-dot-thick #t)
162 (- scale-dot-radius (* 0.5 scale-dot-thick)) 0 #t)
164 (make-circle-stencil scale-dot-radius scale-dot-thick #t)))
165 (positioned-dot (begin
166 ;(display dotstencil)
167 (ly:stencil-translate-axis
168 (ly:stencil-translate-axis dotstencil xpos X)
172 (if (or (eq? finger '())(eq? finger-code 'none))
174 (if (eq? finger-code 'in-dot)
175 (let* ((finger-label (centered-stencil
176 (sans-serif-stencil layout props
177 dot-label-font-mag finger))))
178 (ly:stencil-translate-axis
179 (ly:stencil-translate-axis
182 (if (eq? dot-color 'white)
184 (ly:stencil-in-color finger-label 1 1 1)))
187 (if (eq? finger-code 'below-string)
190 (ly:stencil-translate-axis
191 (ly:stencil-translate-axis
192 (centered-stencil (sans-serif-stencil layout props
193 string-label-font-mag finger))
195 (* size finger-yoffset) Y))
201 (draw-dots layout props string-count fret-range size finger-code
202 dot-position dot-radius dot-thickness restlist)
203 labeled-dot-stencil))))
205 (define (draw-xo layout props string-count fret-range size xo-list)
206 "Put open and mute string indications on diagram, as contained in @var{xo-list}."
207 (let* ((fret-count (+ (- (cadr fret-range) (car fret-range) 1)))
208 ; (xo-font-mag (* size (chain-assoc-get 'xo-font-magnification props 0.5)))
209 (xo-font-mag (* size 0.5))
210 ; (xo-horizontal-offset (* size (chain-assoc-get 'xo-horizontal-offset props -0.35)))
211 (xo-horizontal-offset (* size -0.35))
212 (mypair (car xo-list))
213 (restlist (cdr xo-list))
214 (glyph-string (if (eq? (car mypair) 'mute) "X" "O"))
215 (xpos (+ (* (- string-count (cadr mypair)) size) xo-horizontal-offset ))
216 (glyph-stencil (ly:stencil-translate-axis
217 (sans-serif-stencil layout props (* size xo-font-mag) glyph-string) xpos X)))
221 (draw-xo layout props string-count fret-range size restlist)
224 (define (make-bezier-sandwich-list left right bottom height thickness)
225 " Make the argument list for a horizontal bezier sandwich from
226 @var{left} to @var{right} with a bottom at @var{bottom}, a height of
227 @var{height}, and a thickness of @var{thickness}."
228 (let* ((width (+ (- right left) 1))
229 (x1 (+ (* width thickness) left))
230 (x2 (- right (* width thickness)))
231 (bottom-control-point-height (+ bottom (- height thickness)))
232 (top-control-point-height (+ bottom height)))
233 ; order of points is: left cp low, right cp low, right end low, left end low
234 ; right cp high, left cp high, left end high, right end high.
235 (list (cons x1 bottom-control-point-height) (cons x2 bottom-control-point-height) (cons right bottom) (cons left bottom)
236 (cons x2 top-control-point-height) (cons x1 top-control-point-height) (cons left bottom) (cons right bottom))))
238 (define (draw-barre layout props string-count fret-range size finger-code dot-position dot-radius barre-list)
239 "Create barre indications for a fret diagram"
240 (if (not (null? barre-list))
241 (let* ((string1 (caar barre-list))
242 (string2 (cadar barre-list))
243 (fret (caddar barre-list))
244 (barre-type (chain-assoc-get 'barre-type props 'curved))
245 (scale-dot-radius (* size dot-radius))
246 (barre-vertical-offset (chain-assoc-get 'barre-vertical-offset props 0.5))
247 ;; 2 is 1 for empty fret at bottom of figure + 1 for interval (top-fret - fret + 1) -- not an arbitrary constant
248 (dot-center-y (* size
249 (- (+ 2 (- (cadr fret-range) fret)) dot-position)))
250 (bottom (+ dot-center-y (* barre-vertical-offset scale-dot-radius)))
251 (left (* size (- string-count string1)))
252 (right (* size (- string-count string2)))
253 ;; (bezier-thick (chain-assoc-get 'bezier-thickness props 0.1))
255 ;; (bezier-height (chain-assoc-get 'bezier-height props 0.5))
257 (bezier-list (make-bezier-sandwich-list left right bottom (* size bezier-height) (* size bezier-thick)))
258 (barre-stencil (if (eq? barre-type 'straight)
259 (ly:make-stencil (list 'draw-line (* size dot-radius) left dot-center-y right dot-center-y)
261 (cons (- dot-center-y scale-dot-radius) (+ dot-center-y scale-dot-radius)))
262 (ly:make-stencil (list 'bezier-sandwich `(quote ,bezier-list) (* size bezier-thick))
264 (cons bottom (+ bottom (* size bezier-height)))))))
265 (if (not (null? (cdr barre-list)))
266 (ly:stencil-add barre-stencil
267 (draw-barre layout props string-count fret-range size finger-code
268 dot-position dot-radius (cdr barre-list)))
271 (define (stepmag mag)
272 "Calculate the font step necessary to get a desired magnification"
273 (* 6 (/ (log mag) (log 2))))
275 (define (label-fret layout props string-count fret-range size)
276 "Label the base fret on a fret diagram"
277 (let* ((base-fret (car fret-range))
278 ; (label-font-mag (chain-assoc-get 'label-font-mag props 0.7))
280 ; (label-vertical-offset (chain-assoc-get 'fret-label-vertical-offset props -0.2))
281 (label-vertical-offset -0.2)
282 (number-type (chain-assoc-get 'number-type props 'roman-lower))
283 (fret-count (+ (- (cadr fret-range) (car fret-range)) 1))
286 ((equal? number-type 'roman-lower) (format #f "~(~:@r~)" base-fret))
287 ((equal? number-type 'roman-upper) (format #f "~:@r" base-fret))
288 ((equal? 'arabic number-type) (format #f "~d" base-fret))
289 (else (format #f "~(~:@r~)" base-fret)))))
290 (ly:stencil-translate-axis
291 (sans-serif-stencil layout props (* size label-font-mag) label-text)
292 (* size (+ fret-count label-vertical-offset)) Y)))
294 (define-markup-command (fret-diagram-verbose layout props marking-list)
296 "Make a fret diagram containing the symbols indicated in @var{marking-list}
301 \\markup \\fret-diagram #'((mute 6) (mute 5) (open 4)
302 (place-fret 3 2) (place-fret 2 3) (place-fret 1 2))
305 will produce a standard D chord diagram without fingering indications.
307 Possible elements in @var{marking-list}:
309 @item (mute string-number)
310 Place a small 'x' at the top of string @var{string-number}
312 @item (open string-number)
313 Place a small 'o' at the top of string @var{string-number}
315 @item (barre start-string end-string fret-number)
316 Place a barre indicator (much like a tie) from string @var{start-string}to string @var{end-string} at fret @var{fret-number}
318 @item (place-fret string-number fret-number finger-value)
320 Place a fret playing indication on string @var{string-number} at fret
321 @var{fret-number} with an optional fingering label @var{finger-value}.
322 By default, the fret playing indicator is a solid dot. This can be
323 changed by setting the value of the variable @var{dot-color}. If the
324 @var{finger} part of the place-fret element is present,
325 @var{finger-value} will be displayed according to the setting of the
326 variable @var{finger-code}. There is no limit to the number of fret
327 indications per string.
331 (make-fret-diagram layout props marking-list))
333 (define (make-fret-diagram layout props marking-list)
334 " Make a fret diagram markup"
336 ; note: here we get items from props that are needed in this routine, or that are needed in more than one
337 ; of the procedures called from this routine. If they're only used in one of the sub-procedure, they're
338 ; obtained in that procedure
340 (size (chain-assoc-get 'size props 1.0)) ; needed for everything
341 ;TODO -- get string-count directly from length of stringTunings; requires FretDiagram engraver, which is not yet available
342 ;TODO -- adjust padding for fret label? it appears to be too close to dots
343 (string-count (chain-assoc-get 'string-count props 6)) ; needed for everything
344 (fret-count (chain-assoc-get 'fret-count props 4)) ; needed for everything
345 (finger-code (chain-assoc-get 'finger-code props 'none)) ; needed for both draw-dots and draw-barre
346 (default-dot-radius (if (eq? finger-code 'in-dot) 0.425 0.25)) ; bigger dots if labeled
347 (default-dot-position (if (eq? finger-code 'in-dot) (- 0.95 default-dot-radius) 0.6)) ; move up to make room for bigger if labeled
348 (dot-radius (chain-assoc-get 'dot-radius props default-dot-radius)) ; needed for both draw-dots and draw-barre
349 (dot-position (chain-assoc-get 'dot-position props default-dot-position)) ; needed for both draw-dots and draw-barre
350 (th (* (ly:output-def-lookup layout 'line-thickness)
351 (chain-assoc-get 'thickness props 0.5))) ; needed for both draw-frets and draw-strings
353 (alignment (chain-assoc-get 'align-dir props -0.4)) ; needed only here
354 ; (xo-padding (* th (chain-assoc-get 'padding props 2))) ; needed only here
355 (label-space (* 0.25 size))
356 (xo-padding (* th size 5))
357 (label-dir (chain-assoc-get 'label-dir props RIGHT))
358 (parameters (fret-parse-marking-list marking-list fret-count))
359 (dot-list (cdr (assoc 'dot-list parameters)))
360 (xo-list (cdr (assoc 'xo-list parameters)))
361 (fret-range (cdr (assoc 'fret-range parameters)))
362 (barre-list (cdr (assoc 'barre-list parameters)))
363 (fret-diagram-stencil (ly:stencil-add
364 (draw-strings string-count fret-range th size)
365 (draw-frets layout props fret-range string-count th size))))
366 (if (not (null? barre-list))
367 (set! fret-diagram-stencil (ly:stencil-add
368 (draw-barre layout props string-count fret-range size finger-code
369 dot-position dot-radius barre-list)
370 fret-diagram-stencil)))
371 (if (not (null? dot-list))
372 (set! fret-diagram-stencil (ly:stencil-add
374 (draw-dots layout props string-count fret-range size finger-code
375 dot-position dot-radius th dot-list))))
376 (if (not (null? xo-list))
377 (set! fret-diagram-stencil (ly:stencil-combine-at-edge
378 fret-diagram-stencil Y UP
379 (draw-xo layout props string-count fret-range size xo-list) xo-padding 0)))
380 (if (> (car fret-range) 1)
381 (set! fret-diagram-stencil
382 (ly:stencil-combine-at-edge fret-diagram-stencil X label-dir
383 (label-fret layout props string-count fret-range size) label-space 0)))
384 (ly:stencil-aligned-to fret-diagram-stencil X alignment)
387 (define-markup-command (fret-diagram layout props definition-string)
393 \\markup \\fret-diagram #\"s:0.75;6-x;5-x;4-o;3-2;2-3;1-2;\"
396 for fret spacing 3/4 of staff space, D chord diagram
398 Syntax rules for @var{definition-string}:
402 Diagram items are separated by semicolons.
409 s:number -- set the fret spacing of the diagram (in staff spaces). Default 1
412 t:number -- set the line thickness (in staff spaces). Default 0.05
415 h:number -- set the height of the diagram in frets. Default 4
418 w:number -- set the width of the diagram in strings. Default 6
421 f:number -- set fingering label type (0 = none, 1 = in circle on string, 2 = below string) Default 0
424 d:number -- set radius of dot, in terms of fret spacing. Default 0.25
427 p:number -- set the position of the dot in the fret space. 0.5 is centered; 1 is on lower fret bar,
428 0 is on upper fret bar. Default 0.6
431 c:string1-string2-fret -- include a barre mark from string1 to string2 on fret
434 string-fret -- place a dot on string at fret. If fret is o, string is identified
435 as open. If fret is x, string is identified as muted.
438 string-fret-fingering -- place a dot on string at fret, and label with fingering as
444 Note: There is no limit to the number of fret indications per string.
448 (let ((definition-list (fret-parse-definition-string props definition-string)))
449 (make-fret-diagram layout (car definition-list) (cdr definition-list))))
451 (define (fret-parse-definition-string props definition-string)
452 "parse a fret diagram string and return a pair containing:
453 props, modified as necessary by the definition-string
454 a fret-indication list with the appropriate values"
455 (let* ((fret-count 4)
457 (fret-range (list 1 fret-count))
463 (items (string-split definition-string #\;)))
464 (let parse-item ((myitems items))
465 (if (not (null? (cdr myitems)))
466 (let ((test-string (car myitems)))
467 (case (car (string->list (substring test-string 0 1)))
468 ((#\s) (let ((size (get-numeric-from-key test-string)))
469 (set! new-props (acons 'size size new-props))))
470 ((#\f) (let* ((finger-code (get-numeric-from-key test-string))
471 (finger-id (case finger-code
474 ((2) 'below-string))))
476 (acons 'finger-code finger-id new-props))))
477 ((#\c) (set! output-list (cons-fret (cons 'barre (numerify (string-split (substring test-string 2) #\-)))
479 ((#\h) (let ((fret-count (get-numeric-from-key test-string)))
480 (set! new-props (acons 'fret-count fret-count new-props))))
481 ((#\w) (let ((string-count (get-numeric-from-key test-string)))
482 (set! new-props (acons 'string-count string-count new-props))))
483 ((#\d) (let ((dot-size (get-numeric-from-key test-string)))
484 (set! new-props (acons 'dot-radius dot-size new-props))))
485 ((#\p) (let ((dot-position (get-numeric-from-key test-string)))
486 (set! new-props (acons 'dot-position dot-position new-props))))
488 (let ((this-list (string-split test-string #\-)))
489 (if (string->number (cadr this-list))
490 (set! output-list (cons-fret (cons 'place-fret (numerify this-list)) output-list))
491 (if (equal? (cadr this-list) "x" )
492 (set! output-list (cons-fret (list 'mute (string->number (car this-list))) output-list))
493 (set! output-list (cons-fret (list 'open (string->number (car this-list))) output-list)))))))
494 (parse-item (cdr myitems)))))
495 (if (eq? new-props '())
496 `(,props . ,output-list)
497 `(,(cons new-props props) . ,output-list))))
499 (define (cons-fret new-value old-list)
500 " Put together a fret-list in the format desired by parse-string "
501 (if (eq? old-list '())
503 (cons* new-value old-list)))
505 (define (get-numeric-from-key keystring)
506 "Get the numeric value from a key of the form k:val"
507 (string->number (substring keystring 2 (string-length keystring))))
509 (define (numerify mylist)
510 "Convert string values to numeric or character"
513 (let ((numeric-value (string->number (car mylist))))
515 (cons* numeric-value (numerify (cdr mylist)))
516 (cons* (car (string->list (car mylist))) (numerify (cdr mylist)))))))
518 (define-markup-command (fret-diagram-terse layout props definition-string)
520 "Make a fret diagram markup using terse string-based syntax.
524 \\markup \\fret-diagram-terse #\"x;x;o;2;3;2;\"
526 for a D chord diagram.
528 Syntax rules for @var{definition-string}:
532 Strings are terminated by semicolons; the number of semicolons
533 is the number of strings in the diagram.
536 Mute strings are indicated by \"x\".
539 Open strings are indicated by \"o\".
542 A number indicates a fret indication at that fret.
545 If there are multiple fret indicators desired on a string, they
546 should be separated by spaces.
549 Fingerings are given by following the fret number with a \"-\",
550 followed by the finger indicator, e.g. 3-2 for playing the third
551 fret with the second finger.
554 Where a barre indicator is desired, follow the fret (or fingering) symbol
555 with \"-(\" to start a barre and \"-)\" to end the barre.
557 ;TODO -- change syntax to fret\string-finger
558 (let ((definition-list (fret-parse-terse-definition-string props definition-string)))
559 (make-fret-diagram layout (car definition-list) (cdr definition-list))))
561 (define (fret-parse-terse-definition-string props definition-string)
562 "parse a fret diagram string that uses terse syntax; return a pair containing:
563 props, modified to include the string-count determined by the definition-string
564 a fret-indication list with the appropriate values"
565 ;TODO -- change syntax to fret\string-finger
566 (let* ((barre-start-list '())
569 (items (string-split definition-string #\;))
570 (string-count (- (length items) 1)))
571 (let parse-item ((myitems items))
572 (if (not (null? (cdr myitems)))
573 (let* ((test-string (car myitems))
574 (current-string (- (length myitems) 1))
575 (indicators (string-split test-string #\ )))
576 (let parse-indicators ((myindicators indicators))
577 (if (not (eq? '() myindicators))
578 (let* ((this-list (string-split (car myindicators) #\-))
579 (max-element-index (- (length this-list) 1))
580 (last-element (car (list-tail this-list max-element-index)))
581 (fret (if (string->number (car this-list)) (string->number (car this-list)) (car this-list))))
582 (if (equal? last-element "(")
584 (set! barre-start-list (cons-fret (list current-string fret) barre-start-list))
585 (set! this-list (list-head this-list max-element-index))))
586 (if (equal? last-element ")")
587 (let* ((this-barre (get-sub-list fret barre-start-list))
588 (insert-index (- (length this-barre) 1)))
589 (set! output-list (cons-fret (cons* 'barre (car this-barre) current-string (cdr this-barre))
591 (set! this-list (list-head this-list max-element-index))))
593 (set! output-list (cons-fret (cons* 'place-fret current-string (drop-paren (numerify this-list))) output-list))
594 (if (equal? (car this-list) "x" )
595 (set! output-list (cons-fret (list 'mute current-string) output-list))
596 (set! output-list (cons-fret (list 'open current-string) output-list))))
597 (parse-indicators (cdr myindicators)))))
598 (parse-item (cdr myitems)))))
599 (set! new-props (acons 'string-count string-count new-props))
601 `(,(cons new-props props) . ,output-list)))
603 (define (drop-paren item-list)
604 " drop a final parentheses from a fret indication list resulting from a terse string specification of barre."
605 (if (> (length item-list) 0)
606 (let* ((max-index (- (length item-list) 1))
607 (last-element (car (list-tail item-list max-index))))
608 (if (or (equal? last-element ")") (equal? last-element "("))
609 (list-head item-list max-index)
613 (define (get-sub-list value master-list)
614 " Get a sub-list whose cadr is equal to @var{value} from @var{master-list}"
615 (if (eq? master-list '())
617 (let ((sublist (car master-list)))
618 (if (equal? (cadr sublist) value)
620 (get-sub-list value (cdr master-list))))))