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
Question about Language Syntax
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
sjef



Joined: Jan 22, 2007
Posts: 6
Location: Netherlands

PostPosted: Wed Jan 24, 2007 4:57 am    Post subject: Question about Language Syntax Reply with quote  Mark this post and the followings unread

Hi all,

So I've started programming chuck, and found myself typing 1::second, and such a lot. This double colon makes me wonder because I can not find anything mentioned about it in the manuals, or anywhere else. It also doesn't seem to be a dereference operator like in C++

It seems to me I can think of it as: 1::second meaning 1 'of type' second. Further, like in example otf_01.ck:

1::T => now;

I would read as '1 of type T' is chucked to 'now'. So time advances by 1 T.. Wouldn't T => now be equivalent? I'm already confusing the type and value of a variable here, I notice. Please enlighten me.

Regards,

Sjef.
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: Wed Jan 24, 2007 11:51 am    Post subject: Re: Question about Language Syntax Reply with quote  Mark this post and the followings unread

sjef wrote:
Wouldn't T => now be equivalent?


Yes, it would. More importantly; it is.
Code:

hour => now;



is perfectly fine ChucK syntax. So is this;
Code:

//define a new unit of time
28::day => dur moon;
//notice I'm not using a seperate number for the amount of moons
moon => now;


The type here is "duration". We have strings, floats, ints, arrays, classes, etc like any other language but we also have our very own type "duration". You can treat durations just like you would expect. For example you can devide them;

Code:
(hour / minute) => float This_should_be_sixty;

Is perfectly valid (note that a duration devided by a duration wil yield a float, just like 4 meters devided by 2 meter wil give "2" (without unit) while two meters devided by two will give "two meters".)

Actually if you are uncomfortable with
Code:

//this is convention
2::second => now;

You can also use straight multiplication like this

Code:
//nobody does this but I just checked that it works
2 * second => now;


Also usefull is this;

Code:
//samples per second
second / samp => float sample_rate;


Those two double dots are just a syntactic convention. It's slightly more compact then writing it as a multiplication and I use it too but if you don't like it I can see no harm in always using the multiplication.

I asure you; nothing more complicated then the first lessons in highschool physics covering how we deal with units is going on, nothing up our sleeves.

Wink

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



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

PostPosted: Thu Jan 25, 2007 11:54 am    Post subject: Reply with quote  Mark this post and the followings unread

Kassen, this is very nice & complete example about time and :: indeed. cool!
Razz
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 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