国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ChucK初步(3)

2019-11-14 09:02:09
字體:
來源:轉載
供稿:網友

Types, Values, and Variables(變量)

ChucK is a strongly-typed language, meaning that types are resolved(決定) at compile-time. However, it is not quite statically-typed, because the compiler/type system is a part of the ChucK virtual(虛擬的) machine, and is a runtime component(成分). This type system helps to impose(強加) PRecision(精度) and clarity(清楚) in the code, and naturally lends to organization of complex(復雜的) programs. At the same time, it is also dynamic in that changes to the type system can take place (in a well-defined(定義明確的) manner) at runtime. This dynamic(動態的) aspect(方面) forms the basis(基礎) for on-the-fly programming.

This section deals with types, values, and the declaration(聲明) and usage(使用) of variables. As in other strongly-typed programming languages, we can think of a type as associated(關聯的) behaviors(行為) of data. (For example, an ‘int’ is a type that means integer(整數), and adding two integer is defined(定義) to produce a third integer representing the sum.) Classes and objects allow us to extend(延伸) the type system with our own custom types, but we won’t cover them in this section. We will focus mainly on primitive(原始的) types here, and leave the discussion of more complex types for classes and objects.

primitive types(原始類型)

The primitive(原始的), or intrinsic(本質的) types are those which are simple datatypes (they have no additional(附加的) data attributes(屬性)). Objects are not primitive types. Primitive types are passed by value. Primitive types cannot be extended(延伸). The primitive types in ChucK are:

int : integer(整數) (signed)float : floating point number (in ChucK, a float is by default double-precision(雙精度))time : ChucKian timedur : ChucKian duration(持續)void : (no type)complex : complex number in rectangular(矩形的) form a + bi (see [below][1])polar: complex number in polar(極面) form (see [below][1])

For a summary of Operations on these types, go to operations and operators.

All other types are derived(派生) from ‘object’, either as part of the ChucK standard library, or as a new class that you create. For specification(規格), go to classes and objects.

values (literals(字面值))

Literal values are specified(指定) explicitly(明確地) in code and are assigned(分配) a type by the compiler(編譯器).The following are some examples of literal values:

int:42int (hexidecimal):0xaf30float:1.323dur:5.5::second//In the above code, second is an existing duration(持續) variable(變量). //For more on durations, see the [manipulating time(時間調節)][4] section.

variables

Variables(變量) are locations in memory that hold data. Variables have to be declared in ChucK before they are used. For example, to declare a variable of type int called foo:

// declare an 'int' called 'foo'int foo;

We can assign(分配) a value to an existing variable by using the ChucK operator (=>). This is one of the most commonly used operators in ChucK, it’s the way to do work and take action! (后面會討論)

// assign value of 2 to 'foo'2 => foo;

It is possible to combine the two statements(聲明) into one:

// assign 2 to a new variable 'foo' of type 'int'2 => int foo;

To use a variable, just refer to it by name:

// debug-print the value of foo<<< foo >>>;

To update the value of foo, for example:

// multiply 'foo' by 10, assign back to 'foo'foo * 10 => foo;

You can also do the above using a *=> (mult-chuck):

// multiply 'foo' by 10, and then assign to 'foo'10 *=> foo;

Here is an example of a duration(持續):

// assign value of '5 seconds' to new variable bar5::second => dur bar;

Once you have bar, you can inductively(歸納的) use it to construct new durations:

// 4 bar, a measure?4::bar => dur measure;

輸出: C:/Users/abc1/Desktop>chuck test.ck 882000.000000 :(dur)

Since time is central to programming ChucK, it is important to understand time, dur, the relationship and operations between them. There is more information in the manipulating time section.

reference types(引用類型)

Reference(參考) types are types which inherit(繼承) from the object class. Some default reference types include:

Object : base type that all classes inherit from (directly or indirectly)所有類繼承的基本類型array : N-dimensional ordered(有序的) set of data (of the same type)Event : fundamental(基本的), extendable(可擴展的), synchronization(同步) mechanism(機制)UGen : extendable unit generator(單元發生器) base class (U = unit, Gen = generator)string : string (of characters)

New classes can be created. All classes are reference types. We will leave the full discussion to the objects and classes section.

complex types

(虛數:直角坐標系,極坐標系)

Two special primitive types are available to to represent complex (復雜的)data, such as the output (輸出)of an FFT: complex and polar. A complex number of the form a + bi can be declared as

#(2,3) => complex cmp; //cmp is now 2 + 3i

where the #(…) syntax(語法) explicitly(明確地) denotes(表示) a complex number in rectangular form(矩形). Similarly, explicit complex numbers can be manipulated(操縱) directly:

#(5, -1.5) => complex cmp; // cmp is 5 - 1.5i#(2,3) + #(5,6) + cmp => complex sum; // sum is now 12 + 7.5i

The (floating point) real and imaginary parts(實虛部) of a complex number can be accessed(存取) with the .re and .im components of a complex number:

#(2.0,3.5) => complex cmp;cmp.re => float x; // x is 2.0cmp.im => float y; //y is 3.5

The polar type(極坐標) offers an equivalent(等價的), alternative(供選擇的) representation(表示) of complex numbers in terms of a magnitude(大小) and phase(相) value. A polar representation of a complex number can be declared as

%(2, .5*pi) => polar pol; // pol is 2∠.5π(沒有想到,竟然有這個(●'?'●))

The magnitude(大小) and phase(相) values can be accessed via .mag and .phase:

%(2, .5*pi) => polar pol;pol.mag => float m; // m is 2pol.phase => float p; //p is .5π

polar and complex representations(代表) can be cast to each other and multiplied/added/assigned(分配)/etc.:

%(2, .5*pi) => polar pol;#(3, 4) => complex cmp;pol $ complex + #(10, 3) + cmp => complex cmp2;cmp $ polar + %(10, .25*pi) - pol => polar pol2;

(這里的$實現了兩種坐標系下表示的轉換)

輸出: C:/Users/abc1/Desktop>chuck test.ck %(2.0000,0.5000*pi) :(polar) #(3.0000,4.0000) :(complex) #(13.0000,9.0000) :(complex) %(13.5540,0.2334*pi) :(polar)


上一篇:CentOS7安裝Python3.6.0

下一篇:新I/O

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平乡县| 凉山| 灵寿县| 类乌齐县| 河津市| 莒南县| 福建省| 南和县| 开平市| 垫江县| 灵丘县| 商丘市| 湘潭市| 遂宁市| 永吉县| 磐安县| 三门峡市| 盘山县| 库尔勒市| 盈江县| 庆元县| 昆明市| 九江县| 南充市| 曲松县| 连江县| 迁安市| 曲阳县| 景东| 顺义区| 昌黎县| 斗六市| 剑川县| 修水县| 丹凤县| 十堰市| 阳江市| 渝北区| 宕昌县| 临西县| 策勒县|