lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Transposing in modes??


From: Erik Sandberg
Subject: Re: Transposing in modes??
Date: Thu, 16 Feb 2006 11:44:17 +0100
User-agent: KMail/1.8.3

On Wednesday 15 February 2006 03.49, Johannes Schindelin wrote:
> Hi,
>
> I always wanted to learn how to transform music with scheme, so I
> implemented half of it. If some of you experts could look at it and tell
> me what could be done more elegantly (Scheme is not my native language),
> and especially what needs to be done to make this easy to use, that would
> be super!

In addition to Han-Wen's comments, I can say the following:

Vectors, while constructs and side effects are not encouraged in Scheme; lists 
and tail recursion are the preferred way of doing things. In general, 
functions ending with ! should be avoided whenever possible. This is just a 
convention, there is no penalty in performance or anything like that, so 
there's no big point in rewriting your existing code other than for 
educational purposes.

The "schemeish" way of writing your function, would probably be somethign 
like:
- keep the different scales in ordinary lists, not vectors.
- Instead of the while loop in alter-mode, I'd probably have use fold, to 
create a _list_ of pitch differences. 
simple example: (fold (lambda (x y tail) (cons (- x y) tail)) '() list1 list2)
should, if list1='(a1 a2 a3) and list2='(b1 b2 b3), produce the list of 
differences, something like
((- a1 b1) (- a2 b2) (- a3 b3))
- if it's essential for performance that a vector is used (i.e. if you use 
direct indexing, rather than linearly searching the list) then the list can 
be converted to a vector after it has been created.

-- 
Erik




reply via email to

[Prev in Thread] Current Thread [Next in Thread]