Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 11, 2016
0 parents
commit c745674
Showing
117 changed files
with
1,442 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module greetings; | ||
|
||
import tango.io.Stdout; | ||
|
||
void hello (char[][] names) | ||
{ | ||
foreach (name; names) | ||
Stdout.formatln ("hello {}", name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import tango.io.Stdout; | ||
|
||
void main() | ||
{ | ||
Stdout ("hello world").newline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import tango.io.Stdout; | ||
|
||
void main (char[][] args) | ||
{ | ||
if (args.length < 2) | ||
Stdout ("usage is: hello name [name] ... [name]").newline; | ||
else | ||
foreach (name; args[1..$]) | ||
Stdout.formatln ("hello {}", name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import greetings; | ||
|
||
void main(char[][] args) | ||
{ | ||
hello (args[1..$]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import tango.io.Stdout; | ||
|
||
void main() | ||
{ | ||
int x = 1; | ||
int y = 2; | ||
int z = 3; | ||
|
||
Stdout.formatln("In main, x: {} y: {} z: {}", x, y, z); | ||
|
||
// Call some function. | ||
someFunction(x, y, z); | ||
|
||
Stdout.formatln("In main again, x: {} y: {} z: {}", x, y, z); | ||
} | ||
|
||
void someFunction(int x, out int y, ref int z) | ||
{ | ||
Stdout.formatln("In someFunction, x: {} y: {} z: {}", x, y, z); | ||
|
||
x = 10; | ||
y = 20; | ||
z = 30; | ||
|
||
Stdout.formatln("In someFunction again, x: {} y: {} z: {}", x, y, z); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import tango.io.Stdout; | ||
|
||
void main() | ||
{ | ||
Stdout.formatln("int.init is {}", int.init); | ||
Stdout.formatln("int.sizeof is {}", int.sizeof); | ||
Stdout.formatln("int.alignof is {}", int.alignof); | ||
Stdout.formatln("int.mangleof is '{}'", int.mangleof); | ||
Stdout.formatln("int.stringof is '{}'", int.stringof); | ||
|
||
int x; | ||
Stdout.formatln("x.init is {}", x.init); | ||
Stdout.formatln("x.sizeof is {}", x.sizeof); | ||
Stdout.formatln("x.alignof is {}", x.alignof); | ||
Stdout.formatln("x.mangleof is '{}'", x.mangleof); | ||
Stdout.formatln("x.stringof is '{}'", x.stringof); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// This is module scope. Here, we declare x and initialize it with a constant | ||
// expression. | ||
int x = 1; | ||
|
||
void main() | ||
{ // A new block scope starts here--a child of the module scope. | ||
|
||
// y is declared inside main's block scope, meaning it is local to main. | ||
// It can see x, but x can't see it. | ||
int y = x; | ||
|
||
if(1 < 2) | ||
{ // A new block scope starts here--a child of main's scope. | ||
|
||
// Because x is visible in main's scope, it is also visible here. And | ||
// because main's scope is this scope's parent, y is visible, too. | ||
// However, z is visible neither in main's scope nor in the module | ||
// scope. | ||
int z = x + y; | ||
|
||
} // The end of the if block scope | ||
|
||
} // The end of main's block scope | ||
|
||
void someFunc() | ||
{ // A new block scope starts here--a child of the module scope and a | ||
// sibling of main's scope. | ||
|
||
// This y is declared inside someFunc's scope. It can see x, but x can't | ||
// see it. Also, neither it nor the y in main's scope are visible to each | ||
// other. | ||
int y = x; | ||
|
||
} // The end of someFunc's block scope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module Time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Parser; | ||
|
||
int state; | ||
|
||
class Parser { | ||
int state; | ||
int outerState() { return .state; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
uint square (int x) { return x*x; } | ||
|
||
unittest { | ||
assert (square(4) == 16); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
struct Time { | ||
uint hour; | ||
int timeZone; | ||
bool usingAM; | ||
|
||
int time() { | ||
if (usingAM && hour > 12) return hour - 12; | ||
else return hour; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
struct S { | ||
align(4) int a; | ||
align(4) int b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
align(1) struct S { | ||
int a; | ||
int b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
union Error { | ||
int errorCode; | ||
char[] errorMessage; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import example12; | ||
|
||
static Time t1 = { hour:7, timeZone:-2 }; | ||
|
||
static Time t2 = { 7, -2 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import example12; | ||
|
||
void main() { | ||
Time t; | ||
t.hour = 3; | ||
Time at = t; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
struct Time { | ||
int hour; | ||
|
||
static Time opAssign(int time) { | ||
Time t; | ||
t.hour = time; | ||
return t; | ||
} | ||
} | ||
|
||
Time t = Time(3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
void setTime(Time t); | ||
setTime( Time(1, 2) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module tango.time.Time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import tango.time.Time; | ||
|
||
void main() { | ||
Time * dt = new Time; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Time { | ||
uint h; | ||
int tz; | ||
|
||
uint hour() { return h; } | ||
|
||
this(uint hour, int timeZone) { | ||
this.h = hour; | ||
this.tz = timeZone; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import tango.io.File; | ||
|
||
void main() { | ||
File f = new File("tango/io/File.d"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import tango.io.File; | ||
|
||
void main() { | ||
scope f = new File("tango/io/File.d"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Time { | ||
private uint month; // 0 is January, 11 December | ||
invariant() { | ||
assert ( month < 12 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
void main() { | ||
auto o = new Object; | ||
assert (o); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import tango.io.FilePath; | ||
|
||
class FileConduit : DeviceConduit { | ||
private PathView path_; | ||
PathView path() { return path_; } | ||
} | ||
|
||
class DeviceConduit { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
final class FilePath { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
abstract class Conduit { | ||
|
||
abstract uint write (void [] src); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import tango.io.model.IConduit; | ||
|
||
class MyProducer { | ||
void[] buffer; | ||
void produce(InputStream data) { | ||
data.read(buffer); | ||
data.clear.close; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import tango.time.Time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Pipe : DeviceConduit { | ||
alias DeviceConduit.copy copy; | ||
alias DeviceConduit.read read; | ||
} | ||
|
||
class DeviceConduit { | ||
|
||
void copy () {} | ||
void read () {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class FileConduit : DeviceConduit { | ||
private void closeFile() { } | ||
|
||
override void close() { | ||
super.close(); | ||
closeFile(); | ||
} | ||
} | ||
|
||
class DeviceConduit { | ||
|
||
void close() { } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class DataInput : InputStream | ||
{ | ||
public DataInput clear() | ||
{ | ||
super.clear; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import tango.io.Conduit; | ||
|
||
class SocketConduit : Conduit { | ||
private static SocketConduit freelist; | ||
private SocketConduit next; | ||
|
||
package static synchronized SocketConduit allocate () | ||
{ | ||
SocketConduit s; | ||
|
||
if (freelist) | ||
{ | ||
s = freelist; | ||
freelist = s.next; | ||
} | ||
else | ||
{ } | ||
return s; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SocketConduit sc = SocketConduit.allocate(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class SC : C { | ||
private int i; | ||
this (int i) { this(i, true); } | ||
this (int i, bool b) { super (i, b); } | ||
} | ||
|
||
class C { | ||
this (int i, bool b) { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Outer { | ||
class Nested { } | ||
} | ||
|
||
void main() { | ||
Outer o = new Outer; | ||
Outer.Nested nested = o.new Nested; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
interface EventHandler { void handle(Event); } | ||
|
||
class Event { | ||
void printDetails(); | ||
} | ||
|
||
class Events { | ||
void registerHandler(EventHandler eh) { } | ||
} | ||
|
||
void main() { | ||
auto e = new Events; | ||
e.registerHandler( | ||
new class EventHandler { | ||
void handle(Event e) { e.printDetails(); } | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import tango.io.FilePath; | ||
|
||
class File { | ||
private PathView path_; | ||
void path(PathView p) { path_ = p; } | ||
PathView path() { return path_; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import tango.io.Stdout; | ||
import tango.io.FilePath; | ||
|
||
class File { | ||
private FilePath path_; | ||
void path(FilePath newpath) { path_ = newpath; } | ||
FilePath path() { return path_; } | ||
} | ||
|
||
void main() { | ||
File f = new File; | ||
f.path = new FilePath("tango/io/FilePath.d"); | ||
|
||
Stdout (f.path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
public import tango.time.Time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface IConduit { } | ||
|
||
interface InputStream { | ||
IConduit conduit (); | ||
uint read (void[] dst); | ||
void clear (); | ||
} |
Oops, something went wrong.