Let’s make a language called scriptish of sufficient sophistication to run this test file.
We’ll get there by building the language in small pieces. As you work through, crib as many ideas as you like from previous problems. There’s more than one way to do it. You may also find that later features require you to reconsider choices you made earlier.
Most of the features build on what we’ve already learned. Some require new techniques that will require dipping into the Racket docs. But in your LOP career, knowing how to surmount new obstacles will be a critical skill.
BTW, indenting and syntax coloring of our sample code might look incorrect at times because DrRacket will be applying the default Racket rules. Don’t panic.
#lang scriptish
var x = 42;
var s = "string";
x + x; // prints 84
s + x; // prints "string42"
var thing = {
"foo" : 42,
'bar' : function(x) {
return x + 15;
}
};
thing.foo; // prints 42
thing.bar; // prints #<procedure:...test.rkt:11:12>
thing.bar(3); // prints 18
if ( thing.foo == 42 ) {
// prints "The correct answer is 42"
alert("The correct answer is " + thing.foo);
} else {
alert("Nope");
}
var idx = 0;
while ( idx != 50 ) {
if ( thing.bar(idx) == 35 ) {
// prints "Calamity at 20!"
alert("Calamity at " + idx + "!");
}
idx++;
}
Result:
84
"string42"
42
#<procedure:...ptish-demo/test.rkt:11:12>
18
ALERT! The correct answer is 42
ALERT! Calamity at 20!
Welcome to the jungle.