lilypond-user
[Top][All Lists]
Advanced

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

Re: Scheme function evluates only once


From: Urs Liska
Subject: Re: Scheme function evluates only once
Date: Thu, 23 Jan 2020 22:46:55 +0100
User-agent: Evolution 3.34.1-2+b1

Hi,

I intended to write about the same, but when I came back home to switch
the computer back on David had already replied, although in clearer
words than I would have done.

But let me take the opportunity to introduce you to Amir who I think
has never posted on the LilyPond lists so far. For those who might
phyiscally be able but failed to put a face to his name: he also was in
Salzburg, watching the conference closely.

For those who weren't there: We are in the lucky position to have Amir
as my "intern" for some time. He is supposed to spend about 4-5 weeks
of full time work with me, for which he'll be "reimbursed" in credit
points equivalent to 1/3 of a semester for his master in music
informatics. He will mostly spend his energy on openLilyLib, presumably
helping with the integration of the extension mechanism into LilyPond
but also working on some specific functionality we haven't decided yet.
Additionally I hope he will integrate a number of functions into
LilyPond that are now in openLilyLib, \shapeII being on top of my
personal wish list.

He'll start seriously in a few weeks, but an initial pull request and
this question show that he's already started getting familiar with the
matter.

Best
Urs

Am Donnerstag, den 23.01.2020, 21:33 +0100 schrieb David Kastrup:
> Amir Teymuri <address@hidden> writes:
> 
> > Hi,
> > 
> > this is just a nonsense exercise for me to get to know LilyPond
> > better!
> > I can't figure out why in the following the #(rnd-col) is evaluated
> > only
> > once and not upon each compilation of my ly file? The first time i
> > compile this i will get the four colors displayed:
> > 
> > (0.5 0.5 0)
> > (0.5 0 1.0)
> > (0.5 0 1.0)
> > (0 0.5 1.0)
> > 
> > which however doesn't change in next compilations, so that there is
> > no
> > color change. Can someone explain what am i missing?
> > Thanks
> > 
> > 
> > %%
> > \version "2.19.83"
> > 
> > #(define (rnd-col) (map (lambda (x) (* x 0.5)) (list (random 3)
> > (random 3) (random 3))))
> > 
> > coloredAcc = #(define-music-function () ()
> >            (newline)
> >            (display (rnd-col))
> >            #{              
> >            \once \override Accidental.color = #(rnd-col)
> >            #})
> > 
> > \relative c'' {
> >   \coloredAcc cisis
> >   \coloredAcc cisis!
> >   \coloredAcc cisis!
> >   \coloredAcc cisis!
> > }
> > %%
> 
> Guile manual:
> 
> File: guile.info,  Node: Random,  Prev: Bitwise Operations,  Up:
> Numbers
> 
> 6.6.2.14 Random Number Generation
> .................................
> 
> Pseudo-random numbers are generated from a random state object, which
> can be created with ‘seed->random-state’ or ‘datum->random-
> state’.  An
> external representation (i.e. one which can written with ‘write’ and
> read with ‘read’) of a random state object can be obtained via
> ‘random-state->datum’.  The STATE parameter to the various functions
> below is optional, it defaults to the state object in the
> ‘*random-state*’ variable.
> 
> [...]
> 
>    Note that the initial value of ‘*random-state*’ is the same every
> time Guile starts up.  Therefore, if you don’t pass a STATE parameter
> to
> the above procedures, and you don’t set ‘*random-state*’ to
> ‘(seed->random-state your-seed)’, where ‘your-seed’ is something that
> _isn’t_ the same every time, you’ll get the same sequence of “random”
> numbers on every run.
> 
>    For example, unless the relevant source code has changed, ‘(map
> random (cdr (iota 30)))’, if the first use of random numbers since
> Guile
> started up, will always give:
> 
>      (map random (cdr (iota 19)))
>
>      (0 1 1 2 2 2 1 2 6 7 10 0 5 3 12 5 5 12)
> 
>    To seed the random state in a sensible way for non-security-
> critical
> applications, do this during initialization of your program:
> 
>      (set! *random-state* (random-state-from-platform))
> 
> 
> 




reply via email to

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