Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 16, 2016
0 parents commit 283805a
Show file tree
Hide file tree
Showing 2,726 changed files with 359,391 additions and 0 deletions.
Binary file added 9781430268727.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,27 @@
Freeware License, some rights reserved

Copyright (c) 2012 James Weaver, Weiqi Gao, Stephen Chin, Dean Iverson, and Johan Vos

Permission is hereby granted, free of charge, to anyone obtaining a copy
of this software and associated documentation files (the "Software"),
to work with the Software within the limits of freeware distribution and fair use.
This includes the rights to use, copy, and modify the Software for personal use.
Users are also allowed and encouraged to submit corrections and modifications
to the Software for the benefit of other users.

It is not allowed to reuse, modify, or redistribute the Software for
commercial use in any way, or for a user�s educational materials such as books
or blog articles without prior permission from the copyright holder.

The above copyright notice and this permission notice need to be included
in all copies or substantial portions of the software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


30 changes: 30 additions & 0 deletions ProJavaFX2/8727_ApxAcode/AbstractClass.visage
@@ -0,0 +1,30 @@
/*
* @test
* @run
*/

// The interface
abstract class Food {
abstract function getName():String;
abstract function whatsInIt():String;
}

// The implementation
class Hamburger extends Food {
override function getName() {
"Hamburger"
}
override function whatsInIt() {
"beef patties"
}
}

// A function that gives the calling code an instance of Food
function getTodaysSpecial():Food {
Hamburger {}
}

// The calling code, no direct mentioning of Hamburger is made here
var food = getTodaysSpecial();
println("Today's special is {food.getName()}. "
"It has {food.whatsInIt()} in it.");
1 change: 1 addition & 0 deletions ProJavaFX2/8727_ApxAcode/AbstractClass.visage.EXPECTED
@@ -0,0 +1 @@
Today's special is Hamburger. It has beef patties in it.
23 changes: 23 additions & 0 deletions ProJavaFX2/8727_ApxAcode/AccessingInstanceVariables.visage
@@ -0,0 +1,23 @@
/*
* @test
* @run
*/

class Point {
var x: Number;
var y: Number;
override function toString(): String {
"Point({x}, {y})"
}
}

// reading member variables
var p = Point { x: 3.0, y: 4.0 };
println("p.x = {p.x}");
println("p.y = {p.y}");
println("p = {p}");

// writing to member variables
p.x = 5.0;
p.y = 12.0;
println("p = {p}");
@@ -0,0 +1,4 @@
p.x = 3.0
p.y = 4.0
p = Point(3.0, 4.0)
p = Point(5.0, 12.0)
16 changes: 16 additions & 0 deletions ProJavaFX2/8727_ApxAcode/AnonymousFunction.visage
@@ -0,0 +1,16 @@
/*
* @test
* @run
*/

import java.lang.Math.*;

{
var hypot: function(:Number, :Number):Number;

hypot = function(x, y) {
sqrt(x*x + y*y);
};

println("hypot(3, 4) = {hypot(3, 4)}");
}
1 change: 1 addition & 0 deletions ProJavaFX2/8727_ApxAcode/AnonymousFunction.visage.EXPECTED
@@ -0,0 +1 @@
hypot(3, 4) = 5.0
11 changes: 11 additions & 0 deletions ProJavaFX2/8727_ApxAcode/AnonymousFunctionWithExplicitTypes.visage
@@ -0,0 +1,11 @@
/*
* @test
* @run
*/

{
var primes = function(n:Integer):Integer[] {
[2..n][k | sizeof [2..<k][d | k mod d == 0] == 0]
};
println(primes(64));
}
@@ -0,0 +1 @@
[ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61 ]
72 changes: 72 additions & 0 deletions ProJavaFX2/8727_ApxAcode/BasicExpressions.visage
@@ -0,0 +1,72 @@
/*
* @test
* @run
*/

// block expressions
var x = {
var a = 3;
var b = 4;
a*a + b*b
};
println("The value of x is {x}");

// precedence and groupings
println("1 + 2 * 3 = {1 + 2 * 3}");
println("(1 + 2) * 3 = {(1 + 2) * 3}");
println("6 / 2 * 3 = {6 / 2 * 3}");
println("6 / (2 * 3) = {6 / (2 * 3)}");

// var and def
var o;
var i: Integer;
var n: Number = 3.14;
var str = "Hello, World.";
var j = bind i;
var greeting = str on replace { println("greeting changed") };

def PI = 3.14159;
def k = bind i;

// assignment and type inference
var v1;
println("Before: v1 = {v1}");
v1 = 42;
println("After: v1 = {v1}");

class Point {
var x: Number;
var y: Number;
override function toString() {
"Point \{ x: {x}, y: {y} \}"
}
}
var v2;
println("Before: v2 = {v2}");
v2 = Point {x: 3, y: 4};
println("After: v2 = {v2}");

// compound assignment
x = 1024;
println("x = {x}");
x += 1;
println("x = {x}");
x -= 2;
println("x = {x}");
x *= 3;
println("x = {x}");
x /= 4;
println("x = {x}");

// relational operators
println("true == true is {true == true}");
println("3 == 3.0 is {3 == 3.0}");
println('"hello" == "hello" is {"hello" == "hello"}');

println("3.14159 > 2.71828 is {3.14159 > 2.71828}");
println("1h < 100m is {1h < 100m}");

var p1 = Point {x: 3, y: 4};
var p2 = Point {x: 3, y: 4};
println("p1 == p1 is {p1 == p1}");
println("p1 == p2 is {p1 == p2}");
22 changes: 22 additions & 0 deletions ProJavaFX2/8727_ApxAcode/BasicExpressions.visage.EXPECTED
@@ -0,0 +1,22 @@
The value of x is 25
1 + 2 * 3 = 7
(1 + 2) * 3 = 9
6 / 2 * 3 = 9
6 / (2 * 3) = 1
greeting changed
Before: v1 = 0
After: v1 = 42
Before: v2 = null
After: v2 = Point { x: 3.0, y: 4.0 }
x = 1024
x = 1025
x = 1023
x = 3069
x = 767
true == true is true
3 == 3.0 is true
"hello" == "hello" is true
3.14159 > 2.71828 is true
1h < 100m is true
p1 == p1 is true
p1 == p2 is false
25 changes: 25 additions & 0 deletions ProJavaFX2/8727_ApxAcode/BoundFunction.visage
@@ -0,0 +1,25 @@
/*
* @test
* @run
*/

var x = 3;

bound function f(y:Number, z:Number):Number {
var u = y;
var v = z;
x + u
}

var a = 4;
var b = 5;
var c = bind f(a, b) on replace {
println("x = {x}, a = {a}, b = {b}, c = {c}.");
};

println("About to change x...");
x = 5;
println("About to change a...");
a = 6;
println("About to change b...");
b = 7;
6 changes: 6 additions & 0 deletions ProJavaFX2/8727_ApxAcode/BoundFunction.visage.EXPECTED
@@ -0,0 +1,6 @@
x = 3, a = 4, b = 5, c = 7.0.
About to change x...
x = 5, a = 4, b = 5, c = 9.0.
About to change a...
x = 5, a = 6, b = 5, c = 11.0.
About to change b...
16 changes: 16 additions & 0 deletions ProJavaFX2/8727_ApxAcode/Car.visage
@@ -0,0 +1,16 @@
/*
* @subtest
*/

// Car.visage
public class Car {
public var make: String;
public var model: String;
override function toString() {
"Car \{make: {make}, model: {model}\}"
}
}

public function getACar() {
Car { make: "BMW", model: "Z5" }
}
22 changes: 22 additions & 0 deletions ProJavaFX2/8727_ApxAcode/Casting.visage
@@ -0,0 +1,22 @@
/*
* @test
* @run
*/

class A {
function f() {
println("A.f() called.");
}
}

class B extends A {
function g() {
println("B.g() called.");
}
}

var a: A;
a = B {};
a.f();
(a as B).g();

2 changes: 2 additions & 0 deletions ProJavaFX2/8727_ApxAcode/Casting.visage.EXPECTED
@@ -0,0 +1,2 @@
A.f() called.
B.g() called.
26 changes: 26 additions & 0 deletions ProJavaFX2/8727_ApxAcode/CreatingInstance.visage
@@ -0,0 +1,26 @@
/*
* @test
* @run
*/

// CreatingInstance.visage
import visage.reflect.*;

public class Point {
public var x: Number;
public var y: Number;
public override function toString() {
"Point \{ x: {x}, y: {y} \}"
}
}

public function run() {
var context = VisageLocal.getContext();
var classType = context.findClass("CreatingInstance.Point");
var classValue = classType.allocate();
classValue.initVar("x", context.mirrorOf(3.0));
classValue.initVar("y", context.mirrorOf(4.0));
classValue.initialize();
var p = (classValue as VisageLocal.ObjectValue).asObject();
println(p);
}
1 change: 1 addition & 0 deletions ProJavaFX2/8727_ApxAcode/CreatingInstance.visage.EXPECTED
@@ -0,0 +1 @@
Point { x: 3.0, y: 4.0 }

0 comments on commit 283805a

Please sign in to comment.