[chuck-users] include/import (am noob)
Michael Heuer
heuermh at gmail.com
Mon Mar 5 17:52:24 EST 2012
George Locke wrote:
> I want to make a library of functions that I can call from any chuck script.
> If I put those functions in one file, how do I access them from another?
> It would be great if I could make them into a new namespace, akin to Std.X
> or Math.X (I am using miniAudicle 0.2.0, not command line.)
>
> (I checked the language specification for the words "include" and "import"
> and found nothing relevant.)
Machine.add("filename.ck"); loads filename.ck on a separate shred.
There is no include/import or namespace mechanism in ChucK.
> PS is there a popular/built-in solution for making exponentially
> distributed, normally distributed, etc random variables?
No. I would love to see such. I ported this just recently but
haven't tested it yet
//
// adapted from org.apache.commmons.math3.random.AbstractRandomGenerator,
// which implements the Polar Method, due to G.E.P. Box, M.E.
Muller and G. Marsaglia,
// as described in D. Knuth, _The Art of Computer Programming_, 3.4.1C.
//
fun static float nextGaussian()
{
0.0 => float v1;
0.0 => float v2;
1.0 => float s;
while (s >= 1.0)
{
2.0 * Std.randf() - 1.0 => v1;
2.0 * Std.randf() - 1.0 => v2;
s = v1 * v1 + v2 * v2;
}
if (s > 0.0)
{
s = Math.sqrt(-2.0 * Math.log(s)/s);
}
v2 * s => cached;
return v1 * s;
}
> PPS If not, I'd be happy to share my work - is there a common way for people
> to share code like this?
This mailing list, or the ChucK wiki
http://wiki.cs.princeton.edu/index.php/ChucK
or e.g. github
https://github.com/heuermh/lick
michael
More information about the chuck-users
mailing list