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 
go to the radio page Live at electro-music.com radio 1 Please visit the chat
poster
 Forum index » DIY Hardware and Software » ChucK programming language
Guys... I think I broke my ChucK!
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [14 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
sir honey



Joined: Aug 04, 2006
Posts: 36
Location: NY

PostPosted: Sat Feb 10, 2007 1:06 pm    Post subject: Guys... I think I broke my ChucK! Reply with quote  Mark this post and the followings unread

Naw, not really,

but my terminal throws me a bus error when I try to run this:

Code:


for( 0 => int x; x < 4; x++)
{
   int b;
   int plop[];
   Std.rand2(0,4) => b;
   b @=> plop[x];
   <<<plop[x]>>>;
}



the <<<print>>> is only there to diagnose this thing. I'm actually trying to seed the array, not just print a random number 0-4, 4 times.


Is there something wrong here? Thanks for any input, comments, suggestions.


jack
Back to top
View user's profile Send private message
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Sat Feb 10, 2007 2:43 pm    Post subject: Reply with quote  Mark this post and the followings unread

i think the reason it crashes chuck..
(it crashes here also..)
because it refers to places not defined while initiating the plop[] array.

i've modified your program into this:

Code:
int b;
int plop[4];

for( 0 => int x; x < plop.cap(); x++)
{
   Std.rand2(0,4) => b;
   b @=> plop[x];
   <<< plop[x] >>>;
}


and also this alternative:

Code:
int b;
int plop[4];

for( 0 => int x; x < plop.cap(); x++)
{
   Std.rand2(0,4) => b;
   b @=> plop[x];
   <<< plop[x] >>>;
}

for( 0 => int x; x < plop.cap(); x++)
{
   <<< plop[x] >>>;
}


this one shows that after assigning each plop[x]..
they still point to the values defined.

this one assign address of another array to plop:

Code:
int b;
int plop[];

for( (0 => int x), (int dummy[6] @=> plop); x < plop.cap(); x++)
{
   Std.rand2(0,4) => b;
   b @=> plop[x];
   <<< plop[x] >>>;
}


i dunno much about OOP or c programming or c++ ..
and now i'm a little confused..
but it doens't crash now hahah.
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
sir honey



Joined: Aug 04, 2006
Posts: 36
Location: NY

PostPosted: Sat Feb 10, 2007 3:34 pm    Post subject: Reply with quote  Mark this post and the followings unread

hey kijaz,

thanks for the help! I didn't know about the .cap() method, that is a great help. I'm really new to this, and learning as I go.

jack
Back to top
View user's profile Send private message
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Sun Feb 11, 2007 3:39 pm    Post subject: Reply with quote  Mark this post and the followings unread

thanks. i've just personal-messaging you.
i hope we can chat more about synthesis and chuck soon!

i've got some experiment i've done to understand more how it worls.
now i'll show you the declaration within for loop.

Code:
for(0 => int i; i < 10; i++)
{
   int x[10];
   Std.rand2(0, 10) => x[i];
   if (i > 0) <<< x[i - 1] >>>;
}


then we'll move the int x[10]; declaration part out to make it global comparing to the function.
so now it'd be..
Code:

int x[10];
for(0 => int i; i < 10; i++)
{
   Std.rand2(0, 10) => x[i];
   if (i > 0) <<< x[i - 1] >>>;
}


so .. declaring in any captive area .. are still

hey i was drunk and day-dreaming.. sorry where were we oh!

Code:
int x[10];
for(0 => int i; i < 10; i++)
{
   Std.rand2(0, 10) => x[i];
}

for(0 => int i; i < 10; i++) <<< x[i] >>>;

the above ensure that declaring before the for loop makes the array availble for later use.
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Kassen
Janitor
Janitor


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

PostPosted: Mon Feb 12, 2007 8:31 am    Post subject: Reply with quote  Mark this post and the followings unread

kijjaz wrote:
i think the reason it crashes chuck..
(it crashes here also..)
because it refers to places not defined while initiating the plop[] array.


Yeah, looks like it BUT that shouldn't crash ChucK. I think ChucK should either complain when compiling or it should report the array being out of range and just abandoning that shred. It shouldn't crash, I think. ChucK isn't supposed to crash the whole VM at all, I think it counts as a bug when it does.

I'll put it up at the WIKI.

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



Joined: Aug 04, 2006
Posts: 36
Location: NY

PostPosted: Mon Feb 12, 2007 11:06 am    Post subject: Reply with quote  Mark this post and the followings unread

thanks, kassen..


I suppose I'll reveal the reason why I posted this problematic code to begin with.

I'm trying to create an array of randomized, non repeating integers to use as a lookup reference for another array of string literals.

I suppose I don't need two arrays to achieve this task, just some way to remove the repeating values from a stream of random ints. Hmm, I seem to remember there being some object in puredata that would do this thing for me, but I don't mind coding the thing in Chuck. If anybody has suggestions I'd welcome them.
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: Mon Feb 12, 2007 5:08 pm    Post subject: Reply with quote  Mark this post and the followings unread

sir honey wrote:

I suppose I don't need two arrays to achieve this task, just some way to remove the repeating values from a stream of random ints. Hmm, I seem to remember there being some object in puredata that would do this thing for me, but I don't mind coding the thing in Chuck. If anybody has suggestions I'd welcome them.


Yeah, sure.

How about this for a structure, lets asume we have a array called "array" and it's already filled with random numbers that might repeat;
Code:

int temp;
int repeats;
for(0=>a; a< ( array.cap() - repeats); a++)
 {
 array[a] => temp;
  {
  for( (temp +1) => int b; b <  ( array.cap() - repeats ); b++)
   {
   if ( array[b] == temp )
    {
    if ( (b + 1) < array.cap)
     {
     for ( (b + 1) => int c; c < array.cap(); c++)
      {
      array[c] => array[c-1];
      repeats++;
      }
     }
   }
  }
  else repeats++;
  }
 }

int new_array[ (array.cap() - repeats) ];
for(0 => int n; n < new_array.cap(); n++)
    {
    array[n] => new_array[n];   
    }


The idea here is that we check every vallue, one by one. If the same value is seen again in the array we move everthing that comes after it one spot to the left (thus eliminating that value). This leaves us with a lot of junk at the end but we know how much junk since we kept track of it using the "repeats" counter.

Finally we create a new array that's as long as the old one minus the repeats and copy the good bits over.

Disclaimers;
*I didn't actually test this code Surprised .
*this is close to how a pure turing machine would do it, a tendency I got ages back writing in Prolog. I'm sure real computer sience types will point out this is rediculously ineficient.....
*I think there might be some tricky bits left still with the end of the whole array and risks of going out of bound but I'm sure this structure as a overall plan should work and at least get you started.

_________________
Kassen

Last edited by Kassen on Mon Feb 12, 2007 5:24 pm; edited 2 times in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Kassen
Janitor
Janitor


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

PostPosted: Mon Feb 12, 2007 5:15 pm    Post subject: Reply with quote  Mark this post and the followings unread

Curses! I'm never writing something with that many brackets in this text box again!
Wink

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



Joined: Aug 04, 2006
Posts: 36
Location: NY

PostPosted: Mon Feb 12, 2007 5:55 pm    Post subject: Reply with quote  Mark this post and the followings unread

wow kassen,

that is some advanced looking code for me to parse!

I'll check it out soon (when I'm not at work).

these were my ideas:

Code:


// create array #1.

int wordcount;

5 => wordcount;

string words[wordcount];

"jack" => words[0];
"is" => words[1];
"the" => words[2];
"shizzle" => words[3];
"werd" => words[4];

// Pick Random element # => Check against already chosen element #s => add to output.
// 1st array-string   2nd array-integers.

int b;
int plop[wordcount];

0 => int x;
   
while( x <wordcount> b;
   
   for ( 0 => int y; y <x> plop[x];
      }

      else
      {
         continue;
      }

   }
   x++;
   //<<<"TEST PRINT STRING">>>;
}




It dosen't do exactly what I want yet, but I'm still working on it.

jack
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 Feb 13, 2007 9:09 am    Post subject: Reply with quote  Mark this post and the followings unread

Jack (I'm not going to call you "honey", the gf is around, you see :-p ),

Are you sure you disabled HTML for that post? That's one of the settings below your text field. You need to switch it off when posting code or the board gets all confused about all those triangular brackets that we use. I can't make sense of some of that now.

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



Joined: Aug 04, 2006
Posts: 36
Location: NY

PostPosted: Tue Feb 13, 2007 11:09 am    Post subject: Reply with quote  Mark this post and the followings unread

right, sorry, must've forgot.

here's my latest effort.

Code:


//attempting to randomize array of strings, no repeated elements!

5 => int wordcount;

string words[wordcount];

"jack" => words[0];
"is" => words[1];
"the" => words[2];
"shizzle" => words[3];
"werd" => words[4];

int b;

int lookup[wordcount];

for( 0=> int init; init < lookup.cap(); init++) -1 @=> lookup[init];

<<<"done init">>>;

0 => int x;
   
while( x < lookup.cap())
{

   Std.rand2(0, lookup.cap() - 1) => b;
   //<<<b>>>;
   
   if ( !b == lookup[x])   
   {   
      b @=> lookup[x];
      x++;
      <<<"working working working (debug)">>>;
   }

}

for( 0 => int z; z < lookup.cap(); z++) <<<words[lookup[z]]>>>;



what'ya think?

I can't get this bitch to run, and I cannot fathom why.


jack
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 Feb 13, 2007 12:00 pm    Post subject: Reply with quote  Mark this post and the followings unread

Looks like a cool puzzle and I'd like to help you solve it but now I have to cook dinner Smile

at first sight the bit that looks dubious is this;
Code:

if ( !b == lookup[x])   


Are you sure you don't mean to write

Code:

if ( ! (b == lookup[x]) )   


or more traditionally (I think)

Code:

if ( b != lookup[x] )   


What you are doing right now is a boolean "not" aplied to integer and I think you want to express "if b doesn't equal some element of my array".

you see,

1 => int foo;
<<<!foo>>>;

will print "0 (int)"

While this;

0 => int bar;
<<<!bar>>>;

should result in "1".

This is a tricky bit where natural languages like english will asume the reader will sort out for you what you intend to say when you say "not" while formal languages like ChucK (did I just call ChucK formal?!!!!) are very picky about exactly where the "not" is and thus what it refers to. Another bit that Porlog forced upon me; in case of doubt add more brackets Smile

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



Joined: Aug 04, 2006
Posts: 36
Location: NY

PostPosted: Tue Feb 13, 2007 12:58 pm    Post subject: Reply with quote  Mark this post and the followings unread

I think you're right.

I'm finding ChucK to be such an invaluable learning experience. Thanks for the reply, and I'll try and spork this code right now!

best
jack
Back to top
View user's profile Send private message
sir honey



Joined: Aug 04, 2006
Posts: 36
Location: NY

PostPosted: Sat Feb 17, 2007 10:25 am    Post subject: I've done it! Reply with quote  Mark this post and the followings unread

I've actually finished this program. And it works!

it eliminates duplicates in randomized integers used as lookup indecies for another array of strings.

Code:


//attempting to randomize array of strings, no repeated elements!

10 => int wordcount; //must equal number of words + 1.

string words[wordcount]; //must equal wordcount - 1.

"I'm" => words[0];
"having" => words[1];
"trouble" => words[2];
"with" => words[3];
"this" => words[4];
"now" => words[5];
"coma" => words[6];
"joker" => words[7];
"bitches" => words[8];
"working" => words[9];

int b;

int lookup[wordcount];

for( 0=> int init; init < lookup.cap(); init++) -1 @=> lookup[init];

//<<<"done init">>>;

//for( 0 => int z; z < lookup.cap(); z++) <<<lookup[z]>>>;

0 => int x;
   
while( x < lookup.cap())
{
   //<<<"TOP x =", x>>>;
   Std.rand2(0, (wordcount - 1)) => b;
   //<<<"random b =", b>>>;

   for( 0 => int y; y < lookup.cap(); y++)
   {
      //<<<"for loop iteration =", y>>>;
      if ( b == lookup[y])   
      {   
         break;
      }
      else
      {
         //<<<"b != lookup[y]">>>;
         if (y == x)
         {
            b @=> lookup[x];
            //<<<"b assigned to lookup",x>>>;
            x++;
            break;
         }
      }
   }   
}

<<<"////////////////////////////////////////////////////////////////">>>;

for( 0 => int z; z < lookup.cap(); z++) <<<words[lookup[z]]>>>;

<<<"////////////////////////////////////////////////////////////////">>>;



what do you think?

I'd love to make a GUI for this thing, any suggestions about how I could go about that?

have a nice weekend!

jack



[/i]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [14 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