noob: machine.add but can't find function
Hi, I've got a chuck file called rand.ck that defines functions, and another that machine.add's rand.ck, but can't find the functions rand.ck " fun float rand_norm() { // Marsaglia polar method, wastes the second ind var float s, x, y; 0 => s; while (s == 0 || s >= 1) { Std.randf() => x; Std.randf() => y; x*x + y*y => s; } return x * Math.sqrt(-2 * Math.log(s) / s); } " test.ck "Machine.add("/Users/George/Documents/chucko/util/rand.ck"); for (0 => int i; i<10; i++) { rand_norm() => float x; <<< x >>>; } " I add test.ck to the miniAudicle VM and the following error error: line(3): undefined variable 'rand_norm'... Am noob. plz help. kthx. - George
Hey George,
I add test.ck to the miniAudicle VM and the following error error: line(3): undefined variable 'rand_norm'...
Am noob. plz help. kthx.
That is a simple one; the two files each have their own namespace. This means that stuff defined (and named) in one file can only be read or used from that file. If you put both functions in the same file it should work. Normally this is a good thing; this way we can use a name like "drum" in a file and not worry about whether we already used that name else-where so we don't get toms where we planned a snare. Functions and classes also have their own namespace, for the same reason. If this is not what you want or need you'll have to create a public class and make your function a member of that. Public classes can be accessed from anywhere in the VM. Hope that helps and gets you a bit further. Yours, Kas,
Yes, that helps. I want a sort of library, so I'll wrap rand_norm in a
public class. thanks!
On Sun, Aug 26, 2012 at 3:29 PM, Kassen
Hey George,
I add test.ck to the miniAudicle VM and the following error error: line(3): undefined variable 'rand_norm'...
Am noob. plz help. kthx.
That is a simple one; the two files each have their own namespace. This means that stuff defined (and named) in one file can only be read or used from that file. If you put both functions in the same file it should work.
Normally this is a good thing; this way we can use a name like "drum" in a file and not worry about whether we already used that name else-where so we don't get toms where we planned a snare.
Functions and classes also have their own namespace, for the same reason. If this is not what you want or need you'll have to create a public class and make your function a member of that. Public classes can be accessed from anywhere in the VM.
Hope that helps and gets you a bit further.
Yours, Kas, _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (2)
-
George Locke
-
Kassen