electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
Latest mystery problem
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
chuckles



Joined: Apr 02, 2007
Posts: 72
Location: San Diego, California

PostPosted: Mon Jun 04, 2007 9:53 am    Post subject: Latest mystery problem
Subject description: Bug?
Reply with quote  Mark this post and the followings unread

OK, here's a simple demonstration of something that gives a compile error that I can't figure out. Mandolin and StifKarp are both StkInstruments, yes?

Then why do these statements compile OK:

Code:
[new StifKarp, new Mandolin ] @=> StkInstrument voice1;

[]; [new Mandolin, new StifKarp ] @=> StkInstrument voice2[];


but these give an error message

Code:
[new StifKarp, new StifKarp ] @=> StkInstrument voice3[];

[new Mandolin, new Mandolin ] @=> StkInstrument voice4[];


Code:
[unnamed2]:line(7): cannot assign '@=>' on types 'Mandolin[]' @=> 'StkInstrument[]'...
[unnamed2]:line(7): ...(reason: --- incompatible types for assignment)


This can be extended too to more than two instruments. I found out about it by experimenting with the "In C" project where he defines something like 9 instruments which are a mixture of StifKarp and Mandolin. I wondered why he did that and it's apparently because you can't create an array of StkInstruments that are all the same type.

Comments, anyone?

Thanks!

c.
Back to top
View user's profile Send private message
spencer



Joined: Aug 16, 2006
Posts: 53
Location: northern california

PostPosted: Mon Jun 04, 2007 4:45 pm    Post subject: Reply with quote  Mark this post and the followings unread

Hey chuckles,
I think ChucK's implicit typing rules force a literal array of objects to be the most specific type/subclass possible while still having them be all the same type at some level. So
Code:
[new StifKarp, new Mandolin ] @=> StkInstrument voice1;
is an array of StkInstruments, but
Code:
[new StifKarp, new StifKarp ] @=> StkInstrument voice3[];
is an array of StifKarps. Also, unfortunately, ChucK's typing rules don't allow you to cast an array of a class to an array of its superclass.

Anyways the solution is this:
Code:
[new Mandolin $ StkInstrument, new Mandolin ] @=> StkInstrument voice4[];
This forces ChucK to think that the most specific type that applies to all elements is StkInstrument, so it is an array of StkInstrument rather than Mandolin.

spencer
Back to top
View user's profile Send private message
chuckles



Joined: Apr 02, 2007
Posts: 72
Location: San Diego, California

PostPosted: Tue Jun 05, 2007 8:26 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks so much Kassan, that will make life easier for me, and it also educates me about $ casting...

(Another way to get around the problem, apparently, though not very elegant, would be to explicitly assign like:

Code:
StkInstrument voice4[2];

new StifKarp @=> voice4[0];
new Mandolin @=> voice4[1];
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Tue Jun 05, 2007 9:35 am    Post subject: Reply with quote  Mark this post and the followings unread

chuckles wrote:
Thanks so much Kassan,


I'm happy you are happy but (Spencer != Kassen), in fact I haven't yet had the pleasure of meeting Spencer in person.

There's more then one person trying to answer question in the ChucK-scene(and that's a good thing too!).

:¬)

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
chuckles



Joined: Apr 02, 2007
Posts: 72
Location: San Diego, California

PostPosted: Fri Jun 08, 2007 8:34 am    Post subject: Reply with quote  Mark this post and the followings unread

My apologies to both Spencer and Kassen; Spencer for not thanking him for his clarification of my problem, and Kassen for spelling his name wrong! Thanks to both of you for helping out in this forum -- the forest of ChucK has some dark areas and mysterious paths for a beginner...

...c...
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Fri Jun 08, 2007 9:23 am    Post subject: Reply with quote  Mark this post and the followings unread

No harm done, Chuckles. I've had a unusual name for quite a while now and I've been dyslexic for a similar period so i can't blame anyone for spelling.

And, yes, it does, but I think that's half the fun.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use