[chuck-users] static strings

Beinan Li li.beinan at gmail.com
Sun Dec 7 23:34:31 EST 2008

Dear ChucKers,

1st of all I'm a newbie to ChucK (Many thanks to Steve who brought me here).

I bumped into a problem regarding static strings, which would really
not have been in my way if I designed it another way, but I still feel it
enough. Here is the story.

I wanted to create a function in a stand-alone .ck module to load my
samples from disk. So I designed my loader class in *instr_loader.ck* like

> public class Instr_loader
> {
>     "path/to/instrument" => static string m_p_instr;
>     fun static string get_instr {return m_p_instr;}
> }

For some reason I just wanted to test the static flavor of ChucK, there is
really no
reason to use a static member here I must confess.

Then my client code *main.ck* looks like this:

> Instr_loader.get_instr() => string path_instr;

when I run both .ck's, I will get:

> [Instr_loader.ck]:line(3): cannot declare static non-primitive objects
> (yet)...
> [Instr_loader.ck]:line(3): ...(hint: declare as ref (@) & initialize
> outside for now)

Then I change the code with the reference to:

> "some/path" => static string @ m_p_loop

Then I run

> chuck Instr_loader.ck main.ck

and get this:

[Instr_loader.ck]:line(3): cannot declare references (@) of primitive type
> 'string'...
> [Instr_loader.ck]:line(3): ...(primitive types: 'int', 'float', 'time',
> 'dur')

So is there a reason why string is not part of primitive types?
BTW: it works perfectly using string as normal class member. I'm just
in this problem here.

Thank you and hope ChucK will chuck it all up~!


On Sun, Dec 7, 2008 at 8:09 PM, Stephen Sinclair <sinclair at music.mcgill.ca>
> Yeah, but you have to make it a static function of a public class.
> The class model in ChucK is still a little awkward, but public classes
> can be instantiated in other files.  Only one public class can be
> defined per file!
> Steve
> On Sun, Dec 7, 2008 at 7:51 PM, Beinan Li <li.beinan at gmail.com> wrote:
>> Hi Steve,
>> Should be a newbie question:
>> In ChuCK, can you define a function in a single .ck file
>> and call it from another .ck like in Matlab?
>> Thanks.
>> Beinan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20081207/52d0a24b/attachment.html>

More information about the chuck-users mailing list