guppy icon indicating copy to clipboard operation
guppy copied to clipboard

Evaluate / Func can't take a function as an evaluator

Open arguiot opened this issue 4 years ago • 0 comments

I was trying with the func method in Guppy, and I tried to add an ln alias of log, but it consistently gives me an error.

Here's my code:

window.onload = function () {
  var g1 = new Guppy("guppy1");
  g1.event("change", function (e) {
    var a = document.getElementById("ans");
    try {
      var fn = e.target.func();
      a.innerHTML = fn({
        pi: Math.PI,
        e: Math.E,
        x: 3,
        gamma: 5,
        ln: function (args) {
          return function (vars) {
            return Math.log(args[0](vars));
          };
        },
      }).toFixed(3);
    } catch (e) {
      a.innerHTML = "Error";
    }
  });
};

It throws:

[Log] TypeError: undefined is not an object (evaluating 'e[1].length') — guppy.min.js:1:5237 (iframeConsoleRunner-dc0d50e60903d6825042d06159a8d5ac69a6c0e9bcef91e3380b17617061ce0f.js, line 1)
[Log] Error: Function not implemented: ln(function (){return e[0]}) — guppy.min.js:1:5169 (iframeConsoleRunner-dc0d50e60903d6825042d06159a8d5ac69a6c0e9bcef91e3380b17617061ce0f.js, line 1)

Maybe my code is wrong, but I can't figure out why.

arguiot avatar Apr 29 '20 02:04 arguiot