electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
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 
Live streaming at radio.electro-music.com

  host / artist show at your time
  Live Improvisations by Faux Pas Quartet and friends Music From Last Thursday
Please visit the chat
 Forum index » DIY Hardware and Software » ChucK programming language
@=> operator
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [4 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
jirko



Joined: Dec 15, 2009
Posts: 59

PostPosted: Sun Dec 26, 2010 4:56 am    Post subject: @=> operator Reply with quote  Mark this post and the followings unread

Hi,

I have an issue with the @=> operator. I need to share the data of one array into a temporal array. So I thought that the assignment operator is the way to go, but it seems that using this assignment operator will bond the arrays. Please see the code below to see what I mean.

Code:

int A[1]; //first array
int B[1]; // second array

[50] @=> A @=> B; //assign a value to the arrays

while(1)
{
    Std.rand2( 0 , 16 )=>A[0]; //assign a new value only to the first array
    0.3::second=>now;
   
    <<<"A ", A[0] , "B ", B[0]>>>;
// we are only making new values for the first array, so
// why do we get the same values in both arrays? why is "B" not = 50?


}




thanks a lot!
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 3391
Location: Sweden
Audio files: 218
G2 patch files: 93

PostPosted: Sun Dec 26, 2010 11:20 am    Post subject: Reply with quote  Mark this post and the followings unread

Attaching an image descibing my take on how arrays work in ChucK. An array is a chunk of allocated memory, and the variable that you assign to point to the array is just a pointer to that chunk. Objects (instances of classes) work the same way.

There is no simple shorthand way to copy an array or an object in ChucK (much like the C-like languages it is inspired by), so you need to do something like this:

Code:
for (0 => int i; i < A.size(); i++) {
A[i] => B[i];
}


of course, you could just do

Code:
A[0] => B[0];


in your case, but I assume you'll want to do something more clever with the array further on.

Generally, when you're using the @=> operator, you're dealing with pointers like this, and you have to know that you're not really copying any data.

Edit: forgot to turn off html


SafariScreenSnapz004.jpg
 Description:
 Filesize:  31.29 KB
 Viewed:  1745 Time(s)

SafariScreenSnapz004.jpg



_________________
Antimon's Window
@soundcloud @Flattr @myspace A blog home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
jirko



Joined: Dec 15, 2009
Posts: 59

PostPosted: Tue Dec 28, 2010 1:21 am    Post subject: Reply with quote  Mark this post and the followings unread

Ok, so this operator works like a pointer!
Very clear!

Thanks a lot Stefan for your help!
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 3391
Location: Sweden
Audio files: 218
G2 patch files: 93

PostPosted: Tue Dec 28, 2010 4:50 am    Post subject: Reply with quote  Mark this post and the followings unread

Glad when I'm able to help!

ChucK's memory handling works pretty much like the one in Java, though the requirement that you sometimes need to use @=> whith pointers adds a visible distinction from regular assignment (or copying) in the code.

Come to think of it, this is a nice effort, in the spirit of making the assignment operator => distinctively different from the equals operator ==. These things are common sources for errors in other C-like languages, and tricky to troubleshoot.

_________________
Antimon's Window
@soundcloud @Flattr @myspace A blog home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [4 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
AmbiphonicDSP

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


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