Re: Scheme function evluates only once

2020-01-23 Thread Thomas Morley
Am Do., 23. Jan. 2020 um 22:47 Uhr schrieb Urs Liska :

> But let me take the opportunity to introduce you to Amir who I think
> has never posted on the LilyPond lists so far.

German Forum?
https://lilypondforum.de/index.php/topic,214.msg1333.html

Cheers,
  Harm



Re: Scheme function evluates only once

2020-01-23 Thread David Kastrup
Urs Liska  writes:

> 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.

Since I only quoted the Guile manual, any clarity has to be credited to
the people writing that section.

-- 
David Kastrup



Re: Scheme function evluates only once

2020-01-23 Thread Urs Liska
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  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))
> 
> 
> 




Re: Scheme function evluates only once

2020-01-23 Thread David Kastrup
Amir Teymuri  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))



-- 
David Kastrup



Scheme function evluates only once

2020-01-23 Thread Amir Teymuri
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!
}
%%
-- 
Amir Teymuri