Hi Morten,

On Sun, Jan 15, 2012 at 5:27 AM, Morten Jagd Christensen <morte...@jcaps.com
> wrote:

>
> here is a working lisp function
>
> (defun mylist (l1 l2 n1)
>    (cond ((null l1) l2)
>          ( t (mylist (cdr l1)
>                         (append l2 (list (append '(place-fret) (car l1)
> (list (1+ (mod (list-length l2)n1))))))
>                          n1)
>          )))
>
> so if   l1 is ((5 3) (5 2) (5 1) (4 1) (4 3) (4 5) (3 1) (3 3) (2 1) (2 5))
>
> (mylist l4 '() 7) becomes (the number is the number of tones in the
> relevant scale)
>
> ((PLACE-FRET 5 3 1) (PLACE-FRET 5 2 2) (PLACE-FRET 5 1 3) (PLACE-FRET 4 1
> 4)
>  (PLACE-FRET 4 3 5) (PLACE-FRET 4 5 6) (PLACE-FRET 3 1 7) (PLACE-FRET 3 3
> 1)
>  (PLACE-FRET 2 1 2) (PLACE-FRET 2 5 3))
>
> Which is exactly what I want.
>
> However am not having success integrating this in your example because #1
> I
> fail to translate my (defun) based example to a working lambda
> representation
> and #2 I need to pass more than one argument to the lambda function.
>

First of all, I should say that I'm an amateur at all of this, but I'll
answer your questions as best as I can.

Scheme is a dialect of Lisp (and Guile is a dialect of Scheme), so
you should definitely consult the sources mentioned here:


http://www.lilypond.org/doc/v2.15/Documentation/contributor/lilypond-programming-languages

The Guile Reference Manual is _extremely_ helpful, as is examining the code
in .ly and .scm files in the Lilypond distribution.

In making your example work, I had to make a number of changes to the names
of procedures (for example, defun --> define, list-length --> length)
because these aren't defined in Guile.

In the attached file, I've shown you how you can express your function in
several very similar ways, and call it from the custom markup command.  One
of the variants of "mylist" uses lambda, the others one of the alternatives
described here:

http://www.gnu.org/software/guile/manual/html_node/Lambda-Alternatives.html#Lambda-Alternatives

Do you think this is a useful approach?
>

Well, if you enjoy programming and learning Scheme, why not!  As for
practicality: if this will save you (and others) time, make creating a
score less tedious, then it is certainly useful.

HTH,
David

Attachment: morten01.ly
Description: Binary data

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to