Skip to content

Deviations from JavaScript

null-a edited this page Oct 7, 2016 · 9 revisions

The order in which functions are defined matters in the presence of wrappers/decorators

For example, this works as expected:

var f = function() { return g() };
var g = function() { return 42 };
f(); // => 42

But wrapping f breaks things:

var id = function(x) { return x; };
var f = id(function() { return g() });
var g = function() { return 42 };
f(); // "Uncaught ReferenceError: g is not defined"

See #61.

Variable scope

In JS, the consequent and alternate blocks of an if statement don't introduce new scopes. They do in WebPPL:

if (true){
  var x = 1;
} else {
  var x = 2;
}
x // "Uncaught ReferenceError: x is not defined"

See #103.

Can't pass primitives to higher-order functions

Higer-order functions written in WebPPL don't work when passed primitive JS functions. Perhaps less importantly, higher order JS primitives won't work when passed WebPPL functions.

See #30.

Function declarations (statements) not supported

Functions can only be created with function expressions.

See #2.

Implicit return

WebPPL functions sometimes (always?) implicitly return the value of the last expression evaluated:

var f = function() {
  if (false) {
    0
  } else {
    1
  }
};

f() // => 1