lilypond-devel
[Top][All Lists]
Advanced

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

Re: reading material?


From: Heikki Johannes Junes
Subject: Re: reading material?
Date: Wed, 24 Mar 2004 02:46:04 +0200 (EET)
User-agent: HUT webmail, IMP 2.2.6

> =================  
>   
> (define (iterate func k)  
>   "Produce the function x -> FUNC(FUNC .. (x) .. ) "  
>   (if (> k 0)  
>       (lambda (x) (func ((iterate func (1- k)) x)))  
>       (lambda (x) x)))  
>   
> (define to-6th-power (iterate sqr 3))  
>   
>   
> =================  
>   
> C++ equivalent  
>   
> =================  
>   
> template <typename FUNCTOR, typename TYPE, unsigned int ITERS>  
> struct Iterate {  
>         TYPE operator() (TYPE operand) {  
>                 FUNCTOR func;  
>                 for (int i = 0; i < ITERS; ++i) operand = func(operand);  
>                 return operand; } };  
>   
>   
> typedef Iterate<Square, int, 3> TripleSquared;  
> - or -  
> class TripleSquared : public Iterate<Square, int, 3> {};  
  
For me, it looks like the first fundamental difference between these two  
syntaxes is that in C++ you have to be extremely careful with type and  
inheritance, whereas in Scheme (seems like) you do not usually need to care.  
  
The second fundamental difference is between an user and the language. Since  
Scheme is interpreted, the behavior of the program (say LilyPond) can be  
changed dynamically. This is not the case with C(++), since the structure of a  
compiled program becomes changed only after recompiling. Therefore, an  
interpreted language, like Scheme, is the only choice in the user end in order  
to satisfy the needs of a high-level (or low-level -- I mix these always)  
language.  
  
IMO, the discussion here have been somewhat between C and C++. The second one,  
i.e. object-oriented language, is indeed better in some cases if you have  
different people in groups programming snippets of programs which should  
interoperate through well-defined interfaces. But, what happens in LilyPond  
which may be used as a kind of 'music-programming language'?  
  
First,   
 (1) you have the a .ly file,   
 (2) whose syntax (or grammatical rules) is the analysed lexically, then  
 (3) the found grammatical 'words' are interpreted for the lilypond-compiler.  
 (4) But, an earlier grammatical 'word' may itself define a new grammatical  
     rule, which overrides an existing grammatical rule, and thus changes  
     the grammary!  
 (5) After everything has interpreted as atomary grammatical units,  
 (6) a lilypond-compiler can do the hard work of placing graphical objects  
     in music in a wise manner with respect to each other.  
  
As far as I see, steps (1)-(5) have to be done with the aid of an interpreted  
language, Scheme is used, and step (6) can be done using, for example, C.  
  
Greetings,  
   
  Heikki Junes  




reply via email to

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