|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
DMDScript - DMDScript doesn't support closure at all
I'm so disappointed that DMDScript doesn't support such core features of
ECMAScript!
If you never plan to support closure, please don't declare DMDScript as a
implementation of ECMA 262.
Test code
=========
// for browsers
if (typeof alert != 'undefined') {
print = function () {
alert(Array.prototype.slice.call(arguments).join(' '));
}
}
// for jshost (jslibs)
else if (typeof LoadModule != 'undefined') {
LoadModule('jsstd');
print = function () {
Print(Array.prototype.join.call(arguments, ' '), '\n');
}
}
// for DMDScript
else if (typeof ScriptEngine == 'function' && ScriptEngine() == 'DMDScript') {
_print = print;
print = function () {
_print(Array.prototype.join.call(arguments, ' '), '\n');
}
}
void function () {
function A(x) {
function B() {
return x * x;
}
return B;
}
var b1 = A(1);
var b2 = A(2);
print('b1() =', b1());
print('b2() =', b2());
print('b1', b1 == b2 ? '==' : '!=', 'b2');
}.call();
=================
Result of the browsers, rhino, jshost(SpiderMonkey):
b1() = 1
b2() = 4
b1 != b2
Result of DMDScript:
Digital Mars DMDScript 1.13
www.digitalmars.com
Compiled by Digital Mars DMD D compiler
Copyright (c) 1999-2007 by Digital Mars
written by Walter Bright
1 source files
b1() = NaN
b2() = NaN
b1 == b2
BTW, DMDScript doesn't allow definitely correct function calling syntax:
(function (s) { print(s) })('Hello world')
void function (s) { print(s) } ('Hello world')
So I must write
void function () {...}.call()
Too bad! You should fix it.
Jul 19 2007
this is fixed in my modified dmdscript http://www.akbkhome.com/svn/gtkDS/ download a tarball here. http://devel.akbkhome.com/gtkjs/ The problem revolves around dmdscript caching function defintions, rather than creating new references where they are found. It required an additional opcode IRfunction, and a few changes to the call method for ddeclaredfunction. Regards Alan hax wrote: Aug 01 2007
|