RETURN / RETURN-FROM and values 
Author Message
 RETURN / RETURN-FROM and values

I keep finding myself typing things like this:

        (return-from foo x nil t)

when I mean

        (return-from foo (values x nil t))

Can anyone think of a good reason why RETURN and RETURN-FROM should
not be defined that way?

I can think of one good reason which is that it's not compatible with
what they do now -- (return-from foo) returns a single value of NIL
and not no values, but other than the small issue of breaking lots of
code, are there any others?

Thanks

--tim



Mon, 15 Mar 2004 21:01:39 GMT  
 RETURN / RETURN-FROM and values

Quote:

> Can anyone think of a good reason why RETURN and RETURN-FROM should
> not be defined that way?

What would be your syntax for (cl:return-from foo (values-list bar))?
It can't be (apply #'tfb:return-from foo bar).


Mon, 15 Mar 2004 22:09:27 GMT  
 RETURN / RETURN-FROM and values

Quote:
> What would be your syntax for (cl:return-from foo (values-list bar))?
> It can't be (apply #'tfb:return-from foo bar).

Right.  That's the example I was looking for that shoots the whole
thing down in flames, thank you!

In fact even better is (return-from x
(function-returning-multiple-values)) which in my system would return
just one value, but in CL returns all of them.

--tim



Mon, 15 Mar 2004 22:30:22 GMT  
 RETURN / RETURN-FROM and values

Quote:

> I keep finding myself typing things like this:

>         (return-from foo x nil t)

> when I mean

>         (return-from foo (values x nil t))

> Can anyone think of a good reason why RETURN and RETURN-FROM should
> not be defined that way?

Yes.  Because it's not as compatible as it probably looks.

Consider (defun foo () (values 1 2)) and the following set of examples:

 (return-from foo 1)        ; #1: CL defines this to return 1 value
 (return-from foo 1 2)      ; #2: CL doesn't define this, but you want to
 (return-from foo (foo) 3)  ; #3: You want this to return 1, 3 I'm betting
 (return-from foo (foo))    ; #4: CL defines this returns 1, 2

The only way to make RETURN-FROM work compatibly with what you want is
to make it pick up arguments like MULTIPLE-VALUE-CALL, but I find that
to be a remarkably unintuitive merge to be used only very, very carefully.
That would change example #3 above to return 1,2,3, which would give all
four examples consistent behavior, but I think would often not be what
people want.  Also, just guessing, I bet it's tricky and computationally
expensive to set up that kind of return-value accumulation.

Quote:
> I can think of one good reason which is that it's not compatible with
> what they do now -- (return-from foo) returns a single value of NIL
> and not no values, but other than the small issue of breaking lots of
> code, are there any others?

This is also so, but is "in the noise" compared to the above problems.


Mon, 15 Mar 2004 22:52:27 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Getting Return Key to Not Send Return Character?

2. Return selected application window on mousedown and return to Realbasic

3. return -code return doesn't play nice with set

4. returning values through functions calls

5. ActiveX Double return value passed by reference?

6. Q:Pattern for nil return values

7. Smalltalk return value customs?0

8. return multiple values from an awk function?

9. Return value from awk snipet via korn shell subroutine

10. Return value of printf?

11. returning values from a function in a shell script

12. getting the return value of a command executed on another host

 

 
Powered by phpBB® Forum Software