www.digitalmars.com         C & C++   DMDScript  

DMDScript - DMDScript doesn't support closure at all

reply hax <hax.sfo gmail.com> writes:
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.
begin 644 test-joined-object.js
M+R\ 9F]R(&)R;W=S97)S#0II9B`H='EP96]F(&%L97)T("$]("=U;F1E9FEN
M960G*2![#0H)<')I;G0 /2!F=6YC=&EO;B`H*2![#0H)"6%L97)T*$%R<F%Y
M+G!R;W1O='EP92YS;&EC92YC86QL*&%R9W5M96YT<RDN:F]I;B G("<I*3L-
M" E]#0I]#0HO+R!F;W( :G-H;W-T("AJ<VQI8G,I#0IE;'-E(&EF("AT>7!E
M;V8 3&]A9$UO9'5L92`A/2`G=6YD969I;F5D)RD >PT*"4QO861-;V1U;&4H
M)VIS<W1D)RD[#0H)<')I;G0 /2!F=6YC=&EO;B`H*2![#0H)"5!R:6YT*$%R
M<F%Y+G!R;W1O='EP92YJ;VEN+F-A;&PH87)G=6UE;G1S+"`G("<I+"`G7&XG
M*3L-" E]#0I]#0HO+R!F;W( 1$U$4V-R:7!T#0IE;'-E(&EF("AT>7!E;V8 
M4V-R:7!T16YG:6YE(#T]("=F=6YC=&EO;B< )B8 4V-R:7!T16YG:6YE*"D 
M/3T )T1-1%-C<FEP="<I('L-" E?<')I;G0 /2!P<FEN=#L-" EP<FEN="`]
M(&9U;F-T:6]N(" I('L-" D)7W!R:6YT*$%R<F%Y+G!R;W1O='EP92YJ;VEN
M+F-A;&PH87)G=6UE;G1S+"`G("<I+"`G7&XG*3L-" E]#0I]#0H-"G9O:60 
M9G5N8W1I;VX *"D >PT*#0H)9G5N8W1I;VX 02AX*2![#0H)"69U;F-T:6]N
M($(H*2![#0H)"0ER971U<FX >"`J(' [#0H)"7T-" D)<F5T=7)N($([#0H)
M?0T*#0H)=F%R(&(Q(#T 02 Q*3L-" EV87( 8C( /2!!*#(I.PT*#0H)<')I
M;G0H)V(Q*"D /2<L(&(Q*"DI.PT*"7!R:6YT*"=B,B I(#TG+"!B,B I*3L-
M" EP<FEN=" G8C$G+"!B,2`]/2!B,B`_("<]/2< .B`G(3TG+"`G8C(G*3L-
," T*?2YC86QL*"D[
`
end
Jul 19 2007
parent Alan Knowles <alan akbkhome.com> writes:
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:
 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()
 
 `
 end
Aug 01 2007