Re: [frogs] Re: Named book file suffixes -- regtest?

[ Thread Index | Date Index | More lilynet.net/frogs Archives ]




On 3/1/09 2:44 PM, "Marek Klein" <marek@xxxxxxxxxxxxx> wrote:

> 
> 
> With your suggestion and one more line of code it works now with
> ly:parser-define!
> 
> (define counter-alist '())


Will it work with the above line missing?  The whole point of using
ly:parser-define! is to avoid having a global variable.

When you use

(define counter-alist '())

you are defining counter-alist as a global variable.   I think you should be
able to just remove that line.


> 
> (define (print-book-with parser book process-procedure)
>   (let*
>       ((paper (ly:parser-lookup parser '$defaultpaper))
>        (layout (ly:parser-lookup parser '$defaultlayout))
>        (output-suffix (ly:parser-lookup parser 'output-suffix))
>        (counter-alist (ly:parser-lookup parser 'counter-alist))
^^^^^^^ Here you're making a local variable counter-alist by getting the
parser value of counter-alist;  I don't like to use the same name for both,
although Scheme allows it.  I would use a variable name like local-counter,
so that there would be no confusion between the two.
>        (output-count (assoc-ref counter-alist output-suffix))
>        (base (ly:parser-output-name parser)) )
>       
>       (if (string? output-suffix)
>     (set! base (format "~a-~a" base (string-regexp-substitute
>                        "[^a-zA-Z0-9-]" "_" output-suffix))))
> 
>     ;; must be careful: output-count is under user control.
>     (if (not (integer? output-count))
>     (set! output-count 0))
> 
>     (if (> output-count 0)
>     (set! base (format #f "~a-~a" base output-count)))
>     (ly:parser-define! parser 'counter-alist (assoc-set! counter-alist
> output-suffix (1+ output-count)))
^^^    Here you do an assoc-set! on the local counter-alist and define the
parser value of counter-alist to be the assoc-set! on the local value.  So I
don't think you ever use the global value of counter-alist.

>     (process-procedure book paper layout base)
>     ))
> 
> 

HTH,

Carl


---

----
Join the Frogs!


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/