[PRL] Of course our programming language can do this
Dave Herman
dherman at ccs.neu.edu
Wed Aug 2 13:29:10 EDT 2006
> I just realized another bit of irony about this post: his examples are
> written in ECMAScript, which is, of course, an object-oriented
> programming language. In particular,
There's nothing ironic about that. His point stands without claiming
that object-oriented and functional programming are mutually exclusive.
ECMAScript in fact happily mixes the two.
> function(x) { alert("pot " + x); } );
>
> is basically just syntactic sugar for
>
> new Function("x", "alert(\"pot \" + x);");
>
> which results in an object whose [[Call]] method will execute that
> alert statement. (And "foo(bar)" is syntactic sugar for "execute the
> [[Call]] method of object foo with argument bar".) So it seems like
Not really. The lambda form closes over its lexical environment. The
reflective form doesn't. The [[Call]] method is only a specification
construct, and is not programmer-accessible; an implementation may
choose not to make this an ECMAScript "method." You're still right,
though, that functions in ECMAScript are objects and may have arbitrary
fields and methods.
> the main reason ECMAScript wins over Java (by Spolsky's measure) is
> that it has this syntactic sugar to make function expressions simpler.
Well, yes, that's the whole point. You can implement the same things in
Java, but it's painful. In ECMAScript it's not nearly as painful because
of constructs like higher-order functions.
> Now if only Java had macros... http://jse.sourceforge.net/
If it ever does, let's hope it's not JSE. Notice the TO-DO page:
http://jse.sourceforge.net/doc/todo.html
Under "Macros" it includes the to-do item "implement hygiene." This page
has not been updated since around when the original paper was written,
five years ago.
Dave
More information about the PRL
mailing list