observablehq/runtime

Builtin functions must be wrapped in a function.

mbostock opened this issue · 2 comments

Contrary to the documentation, it appears that if you want to implement a builtin as a function, it has to be wrapped in a function that return this function.

I don’t think this is true (today)…

variable.define(name, constant(this._builtins.get(name)));

This is still true:

(new Variable(TYPE_IMPLICIT, builtin)).define(name, [], builtins[name]);

Furthermore, this is desirable because it allows you to provide lazy definitions of built-in functions. For example, you can define a md tagged template literal that only loads Marked.js if it’s actually needed.

Another way to avoid the wrapper function is to use a Promise wrapper: Promise.resolve(fun).