Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README 2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the source code for the Snap! Virtual programming language.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
This is the source code for the Snap! Virtual programming language.
# Snap-Final-Project
Creating Variable Number of Inputs for “Or” and “And” Blocks

Project Description



Under the "Operators" section in Snap, there is a block called "join" which joins together the two strings you insert into the two blanks.
You can also extend the join block in order to get more entries to insert more strings.
We would like to apply this same functionality to the "and" and "or" blocks so that it is more convenient to use them.
With this functionality, you would never need to nest several “and” or “or” blocks together when you have more than two inputs, and it would be much easier to read your code.




Implementation Plan:

1. Look up where the "join" functionality is described in Snap

2. Understand how this functionality is implemented

3. Apply this functionality to the "and" and "or" blocks

-Make sure the “and” and “or” blocks return the correct response with more than 2 inputs

-Add the arrows on the block to control the number of inputs (like the join block)

Group members: Jasmine Deng and Sophie Cooper

9 changes: 9 additions & 0 deletions blocks.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -825,12 +825,20 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
part.isDraggable = true;
part.isStatic = true;
break;

// JOIN WORDS STUFF HERE
case '%words':
part = new MultiArgMorph('%s', null, 0);
part.addInput(); // allow for default value setting
part.addInput(); // allow for default value setting
part.isStatic = false;
break;
case '%addargs':
part = new MultiArgMorph('%b', null, 0);
part.addInput(); // allow for default value setting
part.addInput(); // allow for default value setting
part.isStatic = false;
break;
case '%exp':
part = new MultiArgMorph('%s', null, 0);
part.addInput();
Expand Down Expand Up @@ -2007,6 +2015,7 @@ BlockMorph.prototype.zebraContrast = 40; // alternating color brightness

// BlockMorph sound feedback:


BlockMorph.prototype.snapSound = null;

BlockMorph.prototype.toggleSnapSound = function () {
Expand Down
Empty file modified byob.js
100644 → 100755
Empty file.
51 changes: 45 additions & 6 deletions objects.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,11 @@ SpriteMorph.prototype.initBlocks = function () {
spec: '%n \u00D7 %n',
alias: '*'
},
reportExponent: {
type: 'reporter',
category: 'operators',
spec: '%n ^ %n',
},
reportQuotient: {
type: 'reporter',
category: 'operators',
Expand Down Expand Up @@ -979,6 +984,16 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'operators',
spec: '%b and %b'
},
reportMultiAnd: {
type: 'predicate',
category: 'operators',
spec: 'and together %addargs'
},
reportMultiOr: {
type: 'predicate',
category: 'operators',
spec: 'or together %addargs'
},
reportOr: {
type: 'predicate',
category: 'operators',
Expand Down Expand Up @@ -1295,15 +1310,18 @@ SpriteMorph.prototype.blockAlternatives = {
reportMouseY: ['reportMouseX'],

// operators:
reportSum: ['reportDifference', 'reportProduct', 'reportQuotient'],
reportSum: ['reportDifference', 'reportProduct', 'reportQuotient','reportExponent'],
reportDifference: ['reportSum', 'reportProduct', 'reportQuotient'],
reportProduct: ['reportDifference', 'reportSum', 'reportQuotient'],
reportProduct: ['reportDifference', 'reportSum', 'reportQuotient','reportExponent'],
reportQuotient: ['reportDifference', 'reportProduct', 'reportSum'],
reportExponent: ['reportSum','reportProduct'],
reportLessThan: ['reportEquals', 'reportGreaterThan'],
reportEquals: ['reportLessThan', 'reportGreaterThan'],
reportGreaterThan: ['reportEquals', 'reportLessThan'],
reportAnd: ['reportOr'],
reportOr: ['reportAnd'],
reportAnd: ['reportOr', 'reportMultiAnd', 'reportMultiOr'],
reportOr: ['reportAnd', ' reportMultiAnd', 'reportMultiOr'],
reportMultiAnd: ['reportAnd', ' reportOr', 'reportMultiOr'],
reportMultiOr: ['reportAnd', ' reportOr', 'reportMultiAnd'],
reportTrue: ['reportFalse'],
reportFalse: ['reportTrue'],

Expand Down Expand Up @@ -1628,7 +1646,7 @@ SpriteMorph.prototype.blockForSelector = function (selector, setDefaults) {
defaults = migration ? migration.inputs : info.defaults;
block.defaults = defaults;
inputs = block.inputs();
if (inputs[0] instanceof MultiArgMorph) {
if (inputs[0] instanceof MultiArgMorph) {
inputs[0].setContents(defaults);
inputs[0].defaults = defaults;
} else {
Expand Down Expand Up @@ -1980,6 +1998,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push(block('reportDifference'));
blocks.push(block('reportProduct'));
blocks.push(block('reportQuotient'));
blocks.push(block('reportExponent'));
blocks.push('-');
blocks.push(block('reportModulus'));
blocks.push(block('reportRound'));
Expand All @@ -1992,6 +2011,8 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('reportAnd'));
blocks.push(block('reportOr'));
blocks.push(block('reportMultiAnd'));
blocks.push(block('reportMultiOr'));
blocks.push(block('reportNot'));
blocks.push('-');
blocks.push(block('reportTrue'));
Expand Down Expand Up @@ -5127,6 +5148,23 @@ StageMorph.prototype.fireKeyEvent = function (key) {
if (evt === 'ctrl enter') {
return this.fireGreenFlagEvent();
}
if (evt === 'ctrl c'){
return new CommentMorph().pickUp(this.world());
}
if (evt === 'ctrl g'){
if (ide.getSetting('design') === 'flat'){
ide.defaultDesign();
}
else{
ide.flatDesign();
}
}
if (evt === 'ctrl x'){
return this.removeAllClones();
}
if (evt === 'ctrl b'){
return this.clear();
}
if (evt === 'shift enter') {
return this.editScripts();
}
Expand Down Expand Up @@ -5512,6 +5550,7 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push(block('reportDifference'));
blocks.push(block('reportProduct'));
blocks.push(block('reportQuotient'));
blocks.push(block('reportExponent'));
blocks.push('-');
blocks.push(block('reportModulus'));
blocks.push(block('reportRound'));
Expand All @@ -5522,7 +5561,7 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push(block('reportEquals'));
blocks.push(block('reportGreaterThan'));
blocks.push('-');
blocks.push(block('reportAnd'));
blocks.push(block('repor'));
blocks.push(block('reportOr'));
blocks.push(block('reportNot'));
blocks.push('-');
Expand Down
57 changes: 53 additions & 4 deletions threads.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -538,20 +538,63 @@ Process.prototype.reportOr = function (block) {

Process.prototype.reportAnd = function (block) {
var inputs = this.context.inputs;
var input_count = inputs.length;

if (inputs.length < 1) {
if (input_count < 1) {
this.evaluateNextInput(block);
} else if (!inputs[0]) {
this.returnValueToParentContext(false);
this.popContext();
} else if (inputs.length < 2) {
} else if (input_count < 2) {
this.evaluateNextInput(block);
} else {
this.returnValueToParentContext(inputs[1] === true);
this.popContext();
}
};

Process.prototype.reportMultiAnd = function (block) {
var inputs = this.context.inputs;
var input_count = inputs.length;
var value = true;
var i;
var all_inputs = inputs[0].contents;
if (input_count < 1) {
this.evaluateNextInput(block);
}
if (all_inputs.length == 0) {
value = false;
this.returnValueToParentContext(value);
this.popContext();
}
for (i = 0; i < all_inputs.length; i++) {
value = value && all_inputs[i];
}
this.returnValueToParentContext(value);
this.popContext();
};

Process.prototype.reportMultiOr = function (block) {
var inputs = this.context.inputs;
var input_count = inputs.length;
var value = false;
var i;
var all_inputs = inputs[0].contents;
if (input_count < 1) {
this.evaluateNextInput(block);
}
if (all_inputs.length == 0) {
value = false;
this.returnValueToParentContext(value);
this.popContext();
}
for (i = 0; i < all_inputs.length; i++) {
value = value || all_inputs[i];
}
this.returnValueToParentContext(value);
this.popContext();
};

Process.prototype.doReport = function (block) {
var outer = this.context.outerContext;
if (this.context.expression.partOfCustomCommand) {
Expand Down Expand Up @@ -698,7 +741,6 @@ Process.prototype.evaluateNextInput = function (element) {
args = element.inputs(),
exp = args[nxt],
outer = this.context.outerContext; // for tail call elimination

if (exp.isUnevaluated) {
if (exp.isUnevaluated === true || exp.isUnevaluated()) {
// just return the input as-is
Expand Down Expand Up @@ -2025,6 +2067,13 @@ Process.prototype.reportModulus = function (a, b) {
return ((x % y) + y) % y;
};

/JUST ADDED/
Process.prototype.reportCube = function (a) {
return (+a * +a * +a);
};



Process.prototype.reportRandom = function (min, max) {
var floor = +min,
ceil = +max;
Expand Down Expand Up @@ -2195,7 +2244,7 @@ Process.prototype.reportJoin = function (a, b) {
return x.concat(y);
};

Process.prototype.reportJoinWords = function (aList) {
Process.prototypef= function (aList) {
if (aList instanceof List) {
return aList.asText();
}
Expand Down