File: machine-help.ck

package info (click to toggle)
chuck 1.5.5.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,056 kB
  • sloc: cpp: 123,473; ansic: 35,893; javascript: 2,111; yacc: 609; makefile: 457; python: 174; perl: 86
file content (56 lines) | stat: -rw-r--r-- 1,473 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// usage examples for a number of Machine functions
// (requires chuck-1.5.1.3 or higher)
//
// see ChucK API Reference on Machine
// https://chuck.stanford.edu/doc/reference/base.html#Machine
//
// or uncomment the next line to print Machine usage
// Machine.help()

// print language version
<<< "chuck version:", Machine.version() >>>;

// keep informed
<<< "\nMachine.eval() example...", "" >>>;

// compile the string as code and spork it as a new shred
// also see eval.ck for more on Machine.eval()
Machine.eval( "repeat(5) { <<< Math.random2f(0,1) >>>; }" );

// keep informed
<<< "\nwaiting for half a second...", "" >>>;

// advance time
.5::second => now;

// keep informed
<<< "\ntrying some shred management...", "" >>>;

// add
Machine.add( me.dir() + "test1.ck:foo" ) => int id;
// yield to give new shred a chance to run
me.yield();

// replace
Machine.replace( id, me.dir() + "test2.ck:bar:5" ) => id;
// yield to give new shred a chance to run
me.yield();

// print current VM status (list of shreds)
Machine.printStatus();
// remove shred
Machine.remove( id );

// keep informed
<<< "\ntrying more Machine functions...", "" >>>;
// print current VM time
Machine.printTimeCheck();
// reset shred IDs to current highest + 1
Machine.resetShredID();
// remove all shreds (including this one!)
Machine.removeAllShreds();
// reset type system and all global variables; remove all shreds
// Machine.clearVM();

// unreachable code
<<< "shouldn't get here" >>>;