Hi Daniel,
I'm glad to be part of the discussion :)
On Aug 28, 2012 8:53 PM, "Daniel Gackle" <danielgackle@gmail.com> wrote:Hi Red,I was hoping you'd chime in. I'll see your scenario 3 and raise you a3a and a 3b:Scenario 3a: A non-Parenscript function that calls a mv-returningParenscript function but only needs its first return value;Scenario 3b: A non-Parenscript function that calls a mv-returningParenscript function and needs all its return values.3a works fine as long as the MV implementation is careful to use anormal JS return to pass the first return value back to the caller.That's true both of what PS does today and of the global-var proposal.As for 3b (the scenario, not the hacker!), seems to me this can't workat all and there's no need to support it. If you're a non-PS functionthen by definition you can't use PS's MULTIPLE-VALUE-BIND to accessthe additional return values because the MV construct only exists inPS. I suppose if you really wanted to you could manually write JS todo whatever PS does to supply those values to the caller, but thenyou're not really a non-PS function anymore, so much as amanually-compiled PS function.DanielI wasn't clear in my original post. I'm not concerned with the non-Parenscript function's ability to receive multiple values. I'm concerned that the non-Parenscript function will interfere with the multiple value return.If a non-Parenscript function calls a Parenscript function that messes with the global variables, the non-Parenscript function could end up returning stuff unintentionally. This is because the non-Parenscript function will not manipulate the global variables to clean up the unused multiple values that are returned.Here's some code to illustrait the point:(defun ps-foo ()(multiple-value-bind (a b) (bar)(+ a b)))(defun ps-fn-returns-mv ()(values 1 2))
function barWorks() {return psFnReturnsMv();}function barBreaks() {psFnReturnsMv(); // global variables for MV returning get set up and linger// return a single value: 42return 42;}Let's assume the two Parenscript functions translate into something like this:var RETURN_VALUES = null;var MV_CALL = false;... other global variables related to multiple valuesfunction psFoo() {// global variable stuffMV_CALL = true;RETURN_VALUES = null;var a = bar();MV_CALL = false;var b = RETURN_VALUES ? RETURN_VALUES[0] : undefined;return a + b;}function psFnReturnsMv() {if (MV_CALL)RETURN_VALUES = [ 2 ];return 1;}
When bar = barWorks, foo will return 1 + 2, as intended. When bar = barBreaks, foo will incorrectly return 42 + 2 because the global variables were not properly cleaned up.I hope this makes sense.- Red