Re: pbr vs multiple returns

new topic     » goto parent     » topic index » view thread      » older message » newer message

Pete Lomax wrote:
> 
> Jason Gade wrote:
> > 
> > I don't understand linking two separate concepts (pass by reference and 
> > multiple returns). Can you explain a little better how they are related?
> 
> Just two different techniques that can both be used to implement a generic pop
> function that does two things, ie get top and modify stack.
> 
> Is that any clearer?
> 
> I have a gut feeling that multiple returns will prove much easier to implement
> than pbr, and now I think of it, there seems little to stop
> }}}
<eucode>
>     top=pop(*stack)
> </eucode>
{{{

> from being nothing more than syntactic sugar for
> }}}
<eucode>
>     {top,stack}=pop(stack)
> </eucode>
{{{

> 
> Regards,
> Pete

So it's just for this specific application?

I can see the argument for multiple returns in some cases but I would rather use
PBR in this particular case.

Using ooeu syntax:
function pop( sequence * stack )
    object tos -- why have a stack that only holds numbers?
    tos = stack[$]
    stack = stack[1..$-1] -- Matt, does this make a copy or not?
    return tos
end function

...

top = pop(my_stack) -- my_stack is actually modified by the pop() function


This makes the most sense to me.


--
"Any programming problem can be solved by adding a level of indirection."
--anonymous
"Any performance problem can be solved by removing a level of indirection."
--M. Haertel
"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare
j.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu