Jump to content

Wikipedia talk:Sandbox: Difference between revisions

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Content deleted Content added
Line 14: Line 14:


----
----
::: ''"what if I don't want to return from the topmost enclosing non-closure, but from a closure 2 levels up? and if I can't, why not?"'' <br />I think JavaScript lets you do that, but through an improper use of a differently aimed construct, so I'm writing this just for comparison sake (since this method could make one of the javascript examples to behave like the Smaltalk one on the "^" operator). Furthermore, this method requires an explicit handling of the "exit point", yet it's very easy and maybe obvious: just use <pre>throw</pre> instead of <pre>return</pre> and capture the result as an exception, wherever you need it.<br /><br />Of course, that's not the right way one should use :::::// The first function passed is the condition to be tested, and is expected to evaluate as
::: ''"what if I don't want to return from the topmost enclosing non-closure, but from a closure 2 levels up?
and if I can't, why not?"'' <br />I think JavaScript lets you do that, but through an improper use of a
differently aimed construct, so I'm writing this just for comparison sake (since this method could make one of
the javascript examples to behave like the Smaltalk one on the "^" operator). Furthermore, this method
requires an explicit handling of the "exit point", yet it's very easy and maybe obvious: just use

:::::// true or false; the second one is the block to be executed if the test condition evaluates to
<pre>throw</pre> instead of <pre>return</pre> and capture the result as an exception, wherever you need it.<br
:::::// true, and may optionally return a value; the third is the alternative block to be executed

:::::// and may optionally return a value. One of such optional values is returned (null or undefined
/><br />Of course, that's not the right way one should use an exception-handling construct, so that'd be
:::::// if none is supplied). The calling function might assign the result value to a somewhat variable,

:::::// or let the function-block to handle it. A preferred way to call this function and easily handle
perhaps misleading/confusing in a real script, yet that should work as wished. And of course, great troubles
:::::// variables as in a standard if-else statement is throughout internal functions, as shown in

:::::// the alertMax function below.
might arise when using such an improper return method combined with regular exceptions, yet it's possible to
:::::function if_else(ifcond, ifblock, elseblock){

::::: var result = null;
make it work: in example, one could wrap the "exception-like" result into a certain "class" object and verify
::::: var doIF = ( ifcond() ) && ( result = ifblock() ); //when ifcond evaluates to true ifblock is

::::: //called and results assigned to result,
whether a captured exception is an instance of such a "class". So doing, the <pre>throw</pre> keyword whould
::::: var doELSE = (! ifcond() ) && ( result = elseblock() ); //otherwise elseblock is called in

::::: //the same fashion.
behave quite like the <pre>^</pre> operator in Smalltalk, while <pre>return</pre> whould be the equivalent of
::::: return result;

:::::}
a "normal" procedure end.--[[Special:Contributions/151.74.14.142|151.74.14.142]] ([[User talk:151.74.14.142|talk]]) 00:29, 2 April 2008 (UTC)xeal
:::::

:::::
::::: ''"Alternatively, I suggest you attempt to write a function in JavaScript that can be used in place of
:::::// Comparing values by calling if_else function with opportune parameters.

:::::function alertMax( a, b ){
the built-in if-then-else statement (of course the invocation syntax would differ; that's OK)."'' <br />I'm
::::: var max = if_else(

::::: function(){ return (a >= b); },
not sure this is exactly what you're asking, but at first glance I'd write the following:<br />
::::: function(){ alert( a + " is greater than or equal to " + b); return a; },
<pre>
::::: function(){ alert( b + " is greater than " + a); return b; }
// Implementing the if-else construct as a function which takes three functions as arguments.
::::: ); //note functions passed as ifblock and elseblock alerts different text;
// The first function passed is the condition to be tested, and is expected to evaluate as
::::: //this shows the alternate execution of statements-equivalent functions works.
// true or false; the second one is the block to be executed if the test condition evaluates to
::::: alert("Max computed value is: " + max);
// true, and may optionally return a value; the third is the alternative block to be executed
:::::}
// and may optionally return a value. One of such optional values is returned (null or undefined
:::::
// if none is supplied). The calling function might assign the result value to a somewhat variable, // or let
:::::alertMax(6, 5);

:::::alertMax(8, 9);
the function-block to handle it. A preferred way to call this function and easily handle
:::::</pre><br />--[[Special:Contributions/151.74.14.142|151.74.14.142]] ([[User talk:151.74.14.142|talk]]) 00:17, 2 April 2008 (UTC) xeal
// variables as in a standard if-else statement is throughout internal functions, as shown in
// the alertMax function below.
function if_else(ifcond, ifblock, elseblock){
var result = null;
var doIF = ( ifcond() ) && ( result = ifblock() ); //when ifcond evaluates to true ifblock is
//called and results assigned to result,
var doELSE = (! ifcond() ) && ( result = elseblock() ); //otherwise elseblock is called in
//the same fashion.
return result;
}


// Comparing values by calling if_else function with opportune parameters.
function alertMax( a, b ){
var max = if_else(
function(){ return (a >= b); },
function(){ alert( a + " is greater than or equal to " + b); return a; },
function(){ alert( b + " is greater than " + a); return b; }
); //note functions passed as ifblock and elseblock alerts different text;
//this shows the alternate execution of statements-equivalent functions works.
alert("Max computed value is: " + max);
}

alertMax(6, 5);
alertMax(8, 9);
</pre><br />--[[Special:Contributions/151.74.14.142|151.74.14.142]] ([[User talk:151.74.14.142|talk]]) 00:29, 2 April 2008 (UTC)xeal

Revision as of 00:29, 2 April 2008


[www.internetisseriousbusiness.com] a a 'a' b c —Preceding unsigned comment added by Pborten (talkcontribs) 20:39, 1 April 2008 (UTC)[reply]

The fourth dimention ?

It is said that the fourth dimention of space is time. But As for as I think that time has its own 3 dimentions so it is itself a dimentioned entity rather than assisting other dimentioned entity like space.--Neeraj 21:56, 1 April 2008 (UTC)

No, it's four dimensions of space-time. Time no more "assists" space than space "assists" time. But if you want to have three-dimensional time, go right ahead, it would be damn useful if you could go off on a perpendicular and get a couple of hours sleep-in. JЇѦρ 00:19, 2 April 2008 :::::(UTC)



"what if I don't want to return from the topmost enclosing non-closure, but from a closure 2 levels up?

and if I can't, why not?"
I think JavaScript lets you do that, but through an improper use of a

differently aimed construct, so I'm writing this just for comparison sake (since this method could make one of

the javascript examples to behave like the Smaltalk one on the "^" operator). Furthermore, this method

requires an explicit handling of the "exit point", yet it's very easy and maybe obvious: just use

throw

instead of

return

and capture the result as an exception, wherever you need it.

Of course, that's not the right way one should use an exception-handling construct, so that'd be

perhaps misleading/confusing in a real script, yet that should work as wished. And of course, great troubles

might arise when using such an improper return method combined with regular exceptions, yet it's possible to

make it work: in example, one could wrap the "exception-like" result into a certain "class" object and verify

whether a captured exception is an instance of such a "class". So doing, the

throw

keyword whould behave quite like the

^

operator in Smalltalk, while

return

whould be the equivalent of

a "normal" procedure end.--151.74.14.142 (talk) 00:29, 2 April 2008 (UTC)xeal[reply]

"Alternatively, I suggest you attempt to write a function in JavaScript that can be used in place of

the built-in if-then-else statement (of course the invocation syntax would differ; that's OK)."
I'm

not sure this is exactly what you're asking, but at first glance I'd write the following:

// Implementing the if-else construct as a function which takes three functions as arguments.
// The first function passed is the condition to be tested, and is expected to evaluate as
// true or false; the second one is the block to be executed if the test condition evaluates to
// true, and may optionally return a value; the third is the alternative block to be executed
// and may optionally return a value. One of such optional values is returned (null or undefined
// if none is supplied). The calling function might assign the result value to a somewhat variable, // or let 

the function-block to handle it. A preferred way to call this function and easily handle
// variables as in a standard if-else statement is throughout internal functions, as shown in
// the alertMax function below.
function if_else(ifcond, ifblock, elseblock){
	var result = null;
	var doIF = ( ifcond() ) && ( result = ifblock() ); //when ifcond evaluates to true ifblock is
                                                           //called and results assigned to result,
	var doELSE = (! ifcond() ) && ( result = elseblock() ); //otherwise elseblock is called in
                                                                //the same fashion.
	return result; 
}


// Comparing values by calling if_else function with opportune parameters.
function alertMax( a, b ){
	var max = if_else(
		function(){ return (a >= b); },
		function(){ alert( a + " is greater than or equal to " + b);  return a; },
		function(){ alert( b + " is greater than " + a);  return b; }
	); //note functions passed as ifblock and elseblock alerts different text;
           //this shows the alternate execution of statements-equivalent functions works.
	alert("Max computed value is: " + max);
}

alertMax(6, 5);
alertMax(8, 9);


--151.74.14.142 (talk) 00:29, 2 April 2008 (UTC)xeal[reply]