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+G!R;W1O='EP92YS;&EC92YC86QL*&%R9W5M96YT<RDN:F]I;B G("<I*3L-

M;V8 3&]A9$UO9'5L92`A/2`G=6YD969I;F5D)RD >PT*"4QO861-;V1U;&4H

M<F%Y+G!R;W1O='EP92YJ;VEN+F-A;&PH87)G=6UE;G1S+"`G("<I+"`G7&XG

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;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