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

2009-03-02 Thread Marek Klein
2009/3/2 Carl D. Sorensen c_soren...@byu.edu




 On 3/1/09 2:44 PM, Marek Klein ma...@gregoriana.sk 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.

 Yes, it works. Thanks for explanation. Do you have some list of recomended
studying materials?

-- 
Marek Klein
http://gregoriana.sk
___
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: Named book file suffixes -- regtest?

2009-03-01 Thread Marek Klein
2009/3/1 Carl D. Sorensen c_soren...@byu.edu


 I think this error message says that it's expecting a symbol, and instead
 it
 gets an empty list, which is the value of counter-alist right now.

 So I think you should try

 (ly:parser-define! parser 'counter-alist (assoc-set! counter-alist
 output-suffix (1+ output-count)))

 This puts the symbol as the argument, rather than the value of the symbol,
 I
 think.

 Carl


With your suggestion and one more line of code it works now with
ly:parser-define!

(define counter-alist '())

(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))
   (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)))
(process-procedure book paper layout base)
))



-- 
Marek Klein
http://gregoriana.sk
___
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel


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

2009-03-01 Thread Carl D. Sorensen



On 3/1/09 2:44 PM, Marek Klein ma...@gregoriana.sk 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



___
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: Named book file suffixes -- regtest?

2009-02-28 Thread Marek Klein
2009/2/28 Carl D. Sorensen c_soren...@byu.edu


 On 2/27/09 11:53 AM, Reinhold Kainhofer reinh...@kainhofer.com wrote:

 
  What about set! versus ly:parser-define! ?
 
  I would rather use ly:parser-define!, if we can find out why it doesn't
 work.
  It's simply cleaner than using a global variable...
 
 

 Marek,

 Can you try again with ly:parser-define!, and try to get some help from
 lilypond-devel by describing in more detail how it doesn't work, i.e. what
 the errors/error messages are?

 Thanks,

 Carl


My current solution is:
(set! counter-alist (assoc-set! counter-alist output-suffix (1+
output-count)))

Reinhold said, it would be better to use ly:parser-define! instead of set!
But I don't understand how... NR says:
*Function:* *ly:parser-define!** parser-smob symbol val*

Bind symbol to val in parser-smob’s module.
It's not clear enough for me... if I try for example:
(ly:parser-define! parser counter-alist (assoc-set! counter-alist
output-suffix (1+ output-count)))
I get following error:

Parsing.../home/marek/lilypond/usr/share/lilypond/current/scm/lily-library.scm:152:5:
In procedure ly:parser-define! in expression (ly:parser-define! parser
counter-alist ...):
/home/marek/lilypond/usr/share/lilypond/current/scm/lily-library.scm:152:5:
Wrong type argument in position 2 (expecting symbol): ()

-- 
Marek Klein
http://gregoriana.sk
___
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: Named book file suffixes -- regtest?

2009-02-28 Thread Carl D. Sorensen

On 2/28/09 5:37 PM, Marek Klein ma...@gregoriana.sk wrote:

 
 My current solution is:
 (set! counter-alist (assoc-set! counter-alist output-suffix (1+
 output-count)))
 
 Reinhold said, it would be better to use ly:parser-define! instead of set!
 But I don't understand how... NR says:
 Function: ly:parser-define! parser-smob  symbol  val
 
 Bind symbol to val in parser-smob¹s module.
 It's not clear enough for me... if I try for example:
 (ly:parser-define! parser counter-alist (assoc-set! counter-alist
 output-suffix (1+ output-count)))
 I get following error:
 
 Parsing.../home/marek/lilypond/usr/share/lilypond/current/scm/lily-library.scm
 :152:5: In procedure ly:parser-define! in expression (ly:parser-define! parser
 counter-alist ...):
 /home/marek/lilypond/usr/share/lilypond/current/scm/lily-library.scm:152:5:
 Wrong type argument in position 2 (expecting symbol): ()

I think this error message says that it's expecting a symbol, and instead it
gets an empty list, which is the value of counter-alist right now.

So I think you should try

(ly:parser-define! parser 'counter-alist (assoc-set! counter-alist
output-suffix (1+ output-count)))

This puts the symbol as the argument, rather than the value of the symbol, I
think.

Carl



___
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel


Named book file suffixes -- regtest?

2009-02-27 Thread Carl D. Sorensen
Marek Klein has made a patch that allows the use of user-defined name
suffixes for lilypond-book output files and eliminates
automatically-generated numbers as part of the file name if the user
specifies the suffixes.

The code he has shared is the following:

 Thank you, 
 now it works as expected:
 
 (define counter-alist '())
 
 (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))
    (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)))
     (set! counter-alist (assoc-set! counter-alist output-suffix (1+
 output-count)))

Marek -- can you check to make sure the code doesn't break if -1 is
specified as a suffix?  I'm afraid that would pass as an integer, but not
pass as 0, so nothing would happen.

 
 What about set! versus ly:parser-define! ?

Can somebody answer Marek's question about set! vs ly:parser-define! ?  I
can't, so I don't want to hazard a guess.

Also, this code needs a regtest, IMO.  But the difference in the code will
be in the names of the files produced, rather than the graphical output.
Will this still be caught by make-check?

Thanks,

Carl

P.S. Marek, you'll need to write a regression test and a documentation
change to go along with the code change before it can be pushed.

Thanks!



___
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: Named book file suffixes -- regtest?

2009-02-27 Thread Reinhold Kainhofer
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Freitag, 27. Februar 2009 16:12:45 Carl D. Sorensen wrote:
 Marek Klein has made a patch that allows the use of user-defined name
 suffixes for lilypond-book output files and eliminates
 automatically-generated numbers as part of the file name if the user
 specifies the suffixes.

To be exact, it does not eliminate the numbering, but it changes the numbering 
to be separate within each suffix. So if you use a different suffix for each 
output file, you won't see any numbering, but if you use the same suffix for 
two files, they will still be numbered and no output file will be overwritten 
(which was the main concern for adding the numbering).

 The code he has shared is the following:
  Thank you,
  now it works as expected:
 
  (define counter-alist '())
 
  (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))
     (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)))
      (set! counter-alist (assoc-set! counter-alist output-suffix (1+
  output-count)))

 Marek -- can you check to make sure the code doesn't break if -1 is
 specified as a suffix?  I'm afraid that would pass as an integer, but not
 pass as 0, so nothing would happen.

Actually, that's not true. -1 will be the key for the lookup in the alist... 
There is no comparison with the actual suffix, just with the value that was 
looked up from the alist, so I don't think that case would be a problem.


  What about set! versus ly:parser-define! ?

I would rather use ly:parser-define!, if we can find out why it doesn't work. 
It's simply cleaner than using a global variable...


 Also, this code needs a regtest, IMO.  But the difference in the code will
 be in the names of the files produced, rather than the graphical output.
 Will this still be caught by make-check?

Good question. I have absolutely no idea, though.

 P.S. Marek, you'll need to write a regression test and a documentation
 change to go along with the code change before it can be pushed.

Yes, that's also quite some work, but it gives you a good insight into the 
whole lilypond distribution... 
What I usually do is to simply search the whole lilypond directory for the 
keyword (output-suffix in this case) and check all files where that keyword 
appears manually to see whether any of them needs some updates, too.

You can ignore all files in directories called out/ or out-www/.

Cheers,
Reinhold
- -- 
- --
Reinhold Kainhofer, reinh...@kainhofer.com, http://reinhold.kainhofer.com/
 * Financial  Actuarial Math., Vienna Univ. of Technology, Austria
 * http://www.fam.tuwien.ac.at/, DVR: 0005886
 * LilyPond, Music typesetting, http://www.lilypond.org
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iD8DBQFJqDadTqjEwhXvPN0RAoRwAKCH7iFYqyr0bVIV3DwWF+uG4DFv4ACaAzMy
0QbipIuD767pvIyrGdNZ4Og=
=UZn0
-END PGP SIGNATURE-


___
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: Named book file suffixes -- regtest?

2009-02-27 Thread Carl D. Sorensen



On 2/27/09 11:53 AM, Reinhold Kainhofer reinh...@kainhofer.com wrote:

 
 Marek -- can you check to make sure the code doesn't break if -1 is
 specified as a suffix?  I'm afraid that would pass as an integer, but not
 pass as 0, so nothing would happen.
 
 Actually, that's not true. -1 will be the key for the lookup in the alist...
 There is no comparison with the actual suffix, just with the value that was
 looked up from the alist, so I don't think that case would be a problem.
 
 

Doh!  You're right, of course.  I misread the code, and didn't catch exactly
how output-count worked.  Thanks for straightening me out.

Carl


 What about set! versus ly:parser-define! ?
 
 I would rather use ly:parser-define!, if we can find out why it doesn't work.
 It's simply cleaner than using a global variable...
 
 
 Also, this code needs a regtest, IMO.  But the difference in the code will
 be in the names of the files produced, rather than the graphical output.
 Will this still be caught by make-check?
 
 Good question. I have absolutely no idea, though.
 
 P.S. Marek, you'll need to write a regression test and a documentation
 change to go along with the code change before it can be pushed.
 
 Yes, that's also quite some work, but it gives you a good insight into the
 whole lilypond distribution...
 What I usually do is to simply search the whole lilypond directory for the
 keyword (output-suffix in this case) and check all files where that keyword
 appears manually to see whether any of them needs some updates, too.
 
 You can ignore all files in directories called out/ or out-www/.

git grep is a good way to do this; it only checks input or source files and
ignores any generated files.

Thanks,

Carl



___
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel


Re: Named book file suffixes -- regtest?

2009-02-27 Thread Carl D. Sorensen



On 2/27/09 11:53 AM, Reinhold Kainhofer reinh...@kainhofer.com wrote:

 
 The code he has shared is the following:
 Thank you,
 now it works as expected:
 
 (define counter-alist '())
 
 (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))
    (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)))
     (set! counter-alist (assoc-set! counter-alist output-suffix (1+
 output-count)))
 
 What about set! versus ly:parser-define! ?
 
 I would rather use ly:parser-define!, if we can find out why it doesn't work.
 It's simply cleaner than using a global variable...
 


Marek,

Can you try again with ly:parser-define!, and try to get some help from
lilypond-devel by describing in more detail how it doesn't work, i.e. what
the errors/error messages are?

Thanks,

Carl



___
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel