Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for something similiar to python's isInstance #470

Open
nshaheed opened this issue Oct 28, 2024 · 0 comments
Open

support for something similiar to python's isInstance #470

nshaheed opened this issue Oct 28, 2024 · 0 comments

Comments

@nshaheed
Copy link
Contributor

Python has this function isInstance which tells you if a value is an instance of a class, i.e.

dict = {}
if isInstance(dict, dictionary):
  # do something

it would be nice to have some sort of equivalent in chuck, specifically for the case of storing different subclasses in an array:

[new SinOsc, new SndBuf, new LiSa] @=> UGen ugens[] => dac;

// this won't work
// 220 => ugens[0].freq; 

// this works, but you need to keep track of which
// index is a sinosc
330 => (ugens[0] $ SinOsc).freq; 

// what if we had something like this?
int i;
while (true) {
    if (Type.isInstance(ugens[i], SinOsc) {
        330 => (ugens[i] $ SinOsc).freq;
    }

    (i + 1) % 3 => i;
}

eon => now;

That way, even if the type info gets lost because it needs to be cast to a more general type, we can still get back to its original type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant