Permalink
Browse files

Merge branch 'master' into string-table

Conflicts:

	version.rkt
  • Loading branch information...
2 parents f7ec58d + f6b2132 commit c0722ea28f336c7155ee285aa3645d37d99544dc Danny Yoo committed Jan 19, 2012
View
@@ -45,8 +45,8 @@ cs019-doc:
setup:
- raco setup --no-docs -P dyoo whalesong.plt 1 13
+ raco setup --no-docs -P dyoo whalesong.plt 1 14
planet-link:
- raco planet link dyoo whalesong.plt 1 13 .
+ raco planet link dyoo whalesong.plt 1 14 .
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,66 @@
+#lang planet dyoo/whalesong/base
+(require (planet dyoo/whalesong/resource)
+ (planet dyoo/whalesong/image))
+
+;; The Iron Image Puzzle
+;; Part of the Nifty Assignments page by Nick Parlante.
+;; http://nifty.stanford.edu/2011/parlante-image-puzzle/
+
+;; To run this program locally on your machine under Google Chrome, you'll
+;; probably need to use --allow-file-access-from-files to get around
+;; the same-origin policy. The program should run normally if served on
+;; a web server
+
+(define-resource iron-puzzle.png)
+
+
+;; First, grab the image by its url.
+(define distorted-image iron-puzzle.png)
+
+
+distorted-image
+(image-width distorted-image)
+(image-height distorted-image)
+
+;; We will want to decompose the image into its individual pixels. We can use
+;; image->color-list to do this.
+;; To make experimenting with the pixels an easy thing to do, let?s write
+;; a function that will let us ?map? across the pixels of an image
+;; to get another image.
+(define (image-transform an-image a-pixel-transform)
+ (local [(define colors (image->color-list an-image))
+ (define new-colors (map a-pixel-transform colors))]
+ (color-list->image new-colors
+ (image-width an-image)
+ (image-height an-image)
+ 0
+ 0)))
+
+
+;; With image-transform in hand, we can apply a filter,
+;; such as zeroing out the blue and green components like this:
+(define (zero-blue-green a-color)
+ (make-color (color-red a-color)
+ 0
+ 0))
+(define dark-image
+ (image-transform distorted-image zero-blue-green))
+
+dark-image
+
+
+;; The image is still a bit darkened. Let?s bump up the red component
+;; by a factor of ten.
+(define (red*10 a-color)
+ (make-color (* (color-red a-color) 10)
+ (color-green a-color)
+ (color-blue a-color)))
+(define red-eye-image
+ (image-transform dark-image red*10))
+
+;; And now we should be able to look at red-eye-image and recognize
+;; the landmark.
+
+red-eye-image
+(image-width red-eye-image)
+(image-height red-eye-image)
@@ -0,0 +1,39 @@
+#lang planet dyoo/whalesong/base
+(require (planet dyoo/whalesong/image))
+;; Sierpenski carpet.
+;; http://rosettacode.org/wiki/Sierpinski_carpet#Scheme
+
+(define SQUARE (square 5 "solid" "red"))
+(define SPACE (square 5 "solid" "white"))
+
+(define (carpet n)
+ (local [(define (in-carpet? x y)
+ (cond ((or (zero? x) (zero? y))
+ #t)
+ ((and (= 1 (remainder x 3)) (= 1 (remainder y 3)))
+ #f)
+ (else
+ (in-carpet? (quotient x 3) (quotient y 3)))))]
+
+ (letrec ([outer (lambda (i)
+ (cond
+ [(< i (expt 3 n))
+ (local ([define a-row
+ (letrec ([inner
+ (lambda (j)
+ (cond [(< j (expt 3 n))
+ (cons (if (in-carpet? i j)
+ SQUARE
+ SPACE)
+ (inner (add1 j)))]
+ [else
+ empty]))])
+ (inner 0))])
+ (cons (apply beside a-row)
+ (outer (add1 i))))]
+ [else
+ empty]))])
+ (apply above (outer 0)))))
+
+
+(carpet 4)
View
@@ -4,7 +4,7 @@
var colorNamespace = MACHINE.modules['whalesong/image/private/color.rkt'].namespace;
var colorStruct = colorNamespace['struct:color'];
-var makeColor = colorStruct.constructor;
+var makeColor = function(r,g,b,a) { return colorStruct.constructor([r,g,b,a]); };
View
@@ -6,7 +6,7 @@
//////////////////////////////////////////////////////////////////////
var colorNamespace = MACHINE.modules['whalesong/image/private/color.rkt'].namespace;
var colorStruct = colorNamespace['struct:color'];
-var makeColor = colorStruct.constructor;
+var makeColor = function(r,g,b,a) { return colorStruct.constructor([r,g,b,a]); };
var isColor = colorStruct.predicate;
var colorRed = function(c) { return colorStruct.accessor(c, 0); };
var colorGreen = function(c) { return colorStruct.accessor(c, 1); };
@@ -1437,7 +1437,7 @@ var imageToColorList = function(img) {
a = data[i+3];
colors.push(makeColor(r, g, b, a));
}
- return plt.baselib.lists.makeList.apply(null, colors);
+ return plt.baselib.lists.arrayToList(colors);
}
View
@@ -2,8 +2,8 @@
(define name "Whalesong")
(define blurb '("A Racket to JavaScript compiler"))
-(define release-notes '((p "Intermediate release to support the upcoming Racket 5.2.1.")))
-(define version "1.13")
+(define release-notes '((p "Bug fix: corrected issue 73 and 74. (https://github.com/dyoo/whalesong/issues/73)")))
+(define version "1.14")
(define categories '(devtools))
(define repositories '("4.x"))
(define required-core-version "5.1.1")
@@ -57,7 +57,10 @@
//////////////////////////////////////////////////////////////////////
exports.ArityAtLeast = ArityAtLeast;
- exports.makeArityAtLeast = ArityAtLeast.constructor;
+ exports.makeArityAtLeast = function() {
+ var args = [].slice.call(arguments);
+ return ArityAtLeast.constructor(args);
+ };
exports.isArityAtLeast = isArityAtLeast;
exports.isArityMatching = isArityMatching;
exports.arityAtLeastValue = arityAtLeastValue;
@@ -120,10 +120,10 @@
baselib.exceptions.raise(
MACHINE,
baselib.exceptions.ExnFailContractArity.constructor(
- callerName + ": expected at least " + minimum
- + " arguments "
- + " but received " + observed,
- MACHINE.captureContinuationMarks()));
+ [callerName + ": expected at least " + minimum
+ + " arguments "
+ + " but received " + observed,
+ MACHINE.captureContinuationMarks()]));
}
};
@@ -43,7 +43,7 @@
}
}
}
- return baselib.lists.makeList.apply(null, result);
+ return baselib.lists.arrayToList(result);
};
// Returns an approximate stack trace.
@@ -81,12 +81,12 @@
var raiseFailure = function(MACHINE, msg) {
var contMarks = MACHINE.captureContinuationMarks();
- raise(MACHINE, ExnFail.constructor(msg, contMarks));
+ raise(MACHINE, ExnFail.constructor([msg, contMarks]));
};
var raiseContractError = function(MACHINE, msg) {
var contMarks = MACHINE.captureContinuationMarks();
- raise(MACHINE, ExnFailContract.constructor(msg, contMarks));
+ raise(MACHINE, ExnFailContract.constructor([msg, contMarks]));
};
@@ -95,9 +95,9 @@
var message = baselib.format.format("Not bound: ~a", [name]);
var contMarks = MACHINE.captureContinuationMarks();
raise(MACHINE,
- ExnFailContractVariable.constructor(message,
- contMarks,
- baselib.symbols.makeSymbol(name)));
+ ExnFailContractVariable.constructor([message,
+ contMarks,
+ baselib.symbols.makeSymbol(name)]));
};
@@ -115,22 +115,22 @@
expectedTypeName,
(argumentOffset + 1),
actualValue]);
- raise(MACHINE, ExnFailContract.constructor(message, contMarks));
+ raise(MACHINE, ExnFailContract.constructor([message, contMarks]));
} else {
message = baselib.format.format(
"~a: expected ~a but received ~e",
[callerName,
expectedTypeName,
actualValue]);
- raise(MACHINE, ExnFailContract.constructor(message, contMarks));
+ raise(MACHINE, ExnFailContract.constructor([message, contMarks]));
}
};
var raiseContextExpectedValuesError = function(MACHINE, expected) {
var message = baselib.format.format("expected ~e values, received ~e values",
[expected, MACHINE.a]);
var contMarks = MACHINE.captureContinuationMarks();
- raise(MACHINE, ExnFailContract.constructor(message, contMarks));
+ raise(MACHINE, ExnFailContract.constructor([message, contMarks]));
};
var raiseArityMismatchError = function(MACHINE, proc, received) {
@@ -139,15 +139,15 @@
proc.racketArity,
received]);
var contMarks = MACHINE.captureContinuationMarks();
- raise(MACHINE, ExnFailContractArity.constructor(message, contMarks));
+ raise(MACHINE, ExnFailContractArity.constructor([message, contMarks]));
};
var raiseOperatorApplicationError = function(MACHINE, operator) {
var message = baselib.format.format("not a procedure: ~e",
[operator]);
var contMarks = MACHINE.captureContinuationMarks();
raise(MACHINE,
- ExnFailContract.constructor(message, contMarks));
+ ExnFailContract.constructor([message, contMarks]));
};
@@ -156,15 +156,15 @@
[operator]);
var contMarks = MACHINE.captureContinuationMarks();
raise(MACHINE,
- ExnFailContract.constructor(message, contMarks));
+ ExnFailContract.constructor([message, contMarks]));
};
var raiseUnimplementedPrimitiveError = function(MACHINE, name) {
var message = "unimplemented kernel procedure: " + name;
var contMarks = MACHINE.captureContinuationMarks();
raise(MACHINE,
- ExnFailContract.constructor(message, contMarks));
+ ExnFailContract.constructor([message, contMarks]));
};
@@ -184,40 +184,40 @@
exceptions.isRacketError = isRacketError;
exceptions.Exn = Exn;
- exceptions.makeExn = Exn.constructor;
+ exceptions.makeExn = function(msg, marks) { return Exn.constructor([msg, marks]); };
exceptions.isExn = Exn.predicate;
exceptions.exnMessage = function(exn) { return Exn.accessor(exn, 0); };
exceptions.exnContMarks = function(exn) { return Exn.accessor(exn, 1); };
exceptions.exnSetContMarks = function(exn, v) { Exn.mutator(exn, 1, v); };
exceptions.ExnBreak = ExnBreak;
- exceptions.makeExnBreak = ExnBreak.constructor;
+ exceptions.makeExnBreak = function(msg, marks) { return ExnBreak.constructor([msg, marks]); };
exceptions.isExnBreak = ExnBreak.predicate;
exceptions.exnBreakContinuation =
function(exn) { return ExnBreak.accessor(exn, 0); };
exceptions.ExnFail = ExnFail;
- exceptions.makeExnFail = ExnFail.constructor;
+ exceptions.makeExnFail = function(msg, marks) { return ExnFail.constructor([msg, marks]); };
exceptions.isExnFail = ExnFail.predicate;
exceptions.ExnFailContract = ExnFailContract;
- exceptions.makeExnFailContract = ExnFailContract.constructor;
+ exceptions.makeExnFailContract = function(msg, marks) { return ExnFailContract.constructor([msg, marks]); };
exceptions.isExnFailContract = ExnFailContract.predicate;
exceptions.ExnFailContractArity = ExnFailContractArity;
- exceptions.makeExnFailContractArity = ExnFailContractArity.constructor;
+ exceptions.makeExnFailContractArity = function(msg, marks) { return ExnFailContractArity.constructor([msg, marks]); };
exceptions.isExnFailContractArity = ExnFailContractArity.predicate;
exceptions.ExnFailContractVariable = ExnFailContractVariable;
- exceptions.makeExnFailContractVariable = ExnFailContractVariable.constructor;
+ exceptions.makeExnFailContractVariable = function(msg, marks) { return ExnFailContractVariable.constructor([msg, marks]); };
exceptions.isExnFailContractVariable = ExnFailContractVariable.predicate;
exceptions.exnFailContractVariableId =
function(exn) { return ExnFailContractVariable.accessor(exn, 0); };
exceptions.ExnFailContractDivisionByZero = ExnFailContractDivisionByZero;
exceptions.makeExnFailContractDivisionByZero =
- ExnFailContractDivisionByZero.constructor;
+ function(msg, marks) { return ExnFailContractDivisionByZero.constructor([msg, marks]); };
exceptions.isExnFailContractDivisionByZero = ExnFailContractDivisionByZero.predicate;
@@ -38,7 +38,7 @@
// When we're in the middle of computing with-cont-mark, we
// stash the key in here temporarily.
- this.pendingContinuationMarkKey = undefined;
+ // this.pendingContinuationMarkKey = undefined;
};
CallFrame.prototype = baselib.heir(Frame.prototype);
@@ -55,7 +55,7 @@
// When we're in the middle of computing with-cont-mark, we
// stash the key in here temporarily.
- this.pendingContinuationMarkKey = undefined;
+ // this.pendingContinuationMarkKey = undefined;
};
PromptFrame.prototype = baselib.heir(Frame.prototype);
@@ -2249,12 +2249,8 @@
constructorName,
initFieldCount + (superType ? superType.numberOfArgs : 0),
function (M) {
- var args = [];
- var i;
- for(i = 0; i < M.a; i++) {
- args.push(M.e[M.e.length - 1 - i]);
- }
- return structType.constructor.apply(null, args);
+ var args = M.e.slice(M.e.length - M.a).reverse();
+ return structType.constructor(args);
});
var predicateValue =
@@ -9,7 +9,10 @@
var srcloc = baselib.structs.makeStructureType(
'srcloc', false, 5, 0, false, false);
- var makeSrcloc = srcloc.constructor;
+ var makeSrcloc = function() {
+ var args = [].slice.call(arguments);
+ return srcloc.constructor(args);
+ };
var isSrcloc = srcloc.predicate;
var srclocSource = function(x) { return srcloc.accessor(x, 0); };
Oops, something went wrong.

0 comments on commit c0722ea

Please sign in to comment.