Re: pbr vs multiple returns
- Posted by Chris Bensler <bensler at nt.net> Jan 11, 2007
- 571 views
Tommy Carlier wrote: > > I also think the assignment of multiple values would be great. It would make > Euphoria > more functional. The stack code could look like this: > }}} <eucode> > -- pushes o onto stack, and returns stack > function push(sequence stack, object o) > return append(stack, o) > end function > > -- pops an object from the stack, and returns {stack, popped_object} > function pop(sequence stack) > return { stack[1..$-1], stack[$] } > end function > > sequence s > object o > s = {} > for i = 1 to 10 do > s = push(s, i) > end for > > for i = 1 to 10 do > {s, o} = pop(s) > end for > </eucode> {{{ > That said, I also like the idea of PBR. I agree with Matt, that > both the caller and callee have to specify the passing by reference. > I don't really like the * notation of C/C++ (and OOEU?). I quite like the > way it's done in C#, via the 'ref' keyword. In Euphoria, it could look like > this: > }}} <eucode> > procedure swap(ref object o1, ref object o2) > object o > o = o1 > o1 = o2 > o2 = o > end procedure > > integer a, b > a = 1 > b = 2 > swap(ref a, ref b) > </eucode> {{{ > The stack code could look like this, with PBR: > }}} <eucode> > procedure push(ref sequence s, object o) > s = append(s, o) > end procedure > > function pop(ref sequence s) > object o > o = s[$] > s = s[1..$-1] > return o > end function > > sequence s > object o > s = {} > for i = 1 to 10 do > push(ref s, o) > end for > > for i = 1 to 10 do > o = pop(ref s) > end for > </eucode> {{{ > To be honest, I actually like this PBR I agree with Tommy's suggestions 100% A keyword is better than a symbol. Either 'ref' or 'pbr'. 'pbr' might be less likely to be confused with an actual parameter name. Chris Bensler ~ The difference between ordinary and extraordinary is that little extra ~ http://empire.iwireweb.com - Empire for Euphoria