A Snap! Mod Idea (Part 2)

reportCombine requires a ringified expression, not a JS function.

How do I turn

into ringified expressions?

I'm thinking it's the wrong idea.
If you want to solve the problem with blocks this seems to be a better way
untitled script pic (81)

For JS you may use native Array.reduce (~Snap combine).

So something like return Array.reduce(this.reportCONS(a, b), this.reportSum);?

Rather (op is an array ?!?!?)

Process.prototype.reportCommutativeOperator = function (a, op, b) { // a is a number,
    switch (op[0]) {                                                   // op is an operator,
        case '+':                                                   // b is a list of nums
            return b.asArray().reduce(this.reportSum, a);

No, op is the dropdown of [scratchblocks](() [+ v] () @delInput @addInput :: operators)[/scratchblocks]. a is the first number, b is the multi-input list of numbers.

So this?:

Process.prototype.reportCommutativeOperator = function (a, op, b) { // a is a number,
    switch (op) {                                                   // op is an operator,
        case '+':                                                   // b is a list of nums
            return b.asArray().reduce(this.reportSum, a);
        case '\u00D7':
            return b.asArray().reduce(this.reportProduct, a);
        case 'max':
            return b.asArray().reduce(this.reportMax, a);
        case 'min':
            return b.asArray().reduce(this.reportMin, a);
    };
};

Yes but there is also built-in witch can be used this way

return a*this.reportListAggregation( b, 'reportProduct');

I'll try that.

You need a reportBasicSum as reportSum is hyperized.

What if I want to do this?:

So you probably need just built-in hyperized operator
return this.reportSum( a, b)

Or concat>>flatten>>reduce to get single value.

The code I used for the pic was this: (ignore that it only does addition)


How can I make that in JS?

Exactly as my blocks does
variadicOP script pic

Using this:

Process.prototype.reportCommutativeOperator = function (a, op, b) { // a is a number,
    switch (op) {                                                   // op is an operator,
        case '+':                                                   // b is a list of nums
            return a + this.reportListAggregation(b, 'reportSum');
        case '\u00D7':
            return a * this.reportListAggregation(b, 'reportProduct');
        case 'max':
            return Math.max(a, this.reportListAggregation(b, 'reportMax'));
        case 'min':
            return Math.min(a, this.reportListAggregation(b, 'reportMin'));
    }
};

Process.prototype.reportNonCommutativeOperator = function (a, op, b) {
    switch (op) {
        case '\u2212':
            return this.reportDifference(a, b);
        case '÷':
            return this.reportQuotient(a, b);
        case '^':
            return this.reportPower(a, b);
        case 'mod':
            return this.reportModulus(a, b);
    }
};

these
untitled script pic (77)
untitled script pic (78)
do nothing. I don't know why.

Edit: I'll see if using op[0] in the switch statements works.

Edit 2:
untitled script pic (79)
untitled script pic (80)
but

Edit 3: With this:

Process.prototype.reportCommutativeOperator = function (a, op, b) { // a is a number,
    switch (op[0]) {                                                // op is an operator,
        case '+':                                                   // b is a list of nums
            return this.reportListAggregation(this.reportCONS(a, b), 'reportSum');
        case '\u00D7':
            return this.reportListAggregation(this.reportCONS(a, b), 'reportProduct');
        case 'max':
            return this.reportListAggregation(this.reportCONS(a, b), 'reportMax');
        case 'min':
            return this.reportListAggregation(this.reportCONS(a, b), 'reportMin');
    }
};




Edit 4: And this:
untitled script pic (86)
untitled script pic (87)
untitled script pic (88)
untitled script pic (89)

Is there an easy way to know if there are any blocks in the Other category that aren't in another category like WARP in Control? I need it for scrolling to the Lists category when there are no blocks (except for WARP, the lambdas, and SCRIPT VARIABLES) in the Other category.

Edit: "No more than 2 consecutive replies are allowed. Please edit your previous reply, or wait for someone to reply to you.":

This is the implementation of "or":

Process.prototype.reportOr = function (block) {
    var inputs = this.context.inputs;

    if (inputs.length < 1) {
        this.evaluateNextInput(block);
    } else if (inputs.length === 1) {
        // this.assertType(inputs[0], 'Boolean');
        if (inputs[0]) {
            if (this.flashContext()) {return; }
            this.returnValueToParentContext(true);
            this.popContext();
        } else {
            this.evaluateNextInput(block);
        }
    } else {
        // this.assertType(inputs[1], 'Boolean');
        if (this.flashContext()) {return; }
        this.returnValueToParentContext(inputs[1] === true);
        this.popContext();
    }
};

Given that template, how can I make "xor"?

Edit 2: "No more than 2 consecutive replies are allowed. Please edit your previous reply, or wait for someone to reply to you.":

Here are all the new/unhidden blocks:
untitled script pic (91)

Edit 3: that <<> [and v] <> < >> block has and, or, nand, nor, xor, and xnor.

Something like

Process.prototype.reportBasicXor = function ( a, b) { 
  return a ? !a : b;
};

Process.prototype.reportXor = function (a, b) {
    return this.hyperDyadic(this.reportBasicXor, a, b);
};

I made it already:

but thanks.

We don't think of WARP, rings, and SCRIPT VARIABLES as being in the Other category. They're in the categories where you see them in the palette. Afaik there are no primitive Other blocks.

They are in the Other category for its gray color. The code still says they're in the Other category, but they aren't shown in the Other category.

If I were to make one, I wouldn't need the code. But if I didn't, and there were custom blocks in it, I'd want the category switching to scroll to the Other category when I click its button. But if there are no custom blocks in it, I want it to scroll to the Lists category.

This topic was automatically closed after reaching the maximum limit of 100 replies. Continue discussion at A Snap! Mod Idea (Part 3).