RE: Changing Euphoria
- Posted by kbochert at ix.netcom.com Feb 04, 2002
- 408 views
-------Phoenix-Boundary-07081998- Hi Shawn Pringle, you wrote on 1/31/02 9:37:11 AM: >Ofcourse pass by reference is relatively cheap in EUPHORIA, being copy >on write pointers. It would seem to me that code like: >list = append(list,a) should be optimized to something like: >append(!!list,a) keeping with your notation. As, the object passed in >will be reassigned there is no need to copy a new list in append. > >Apparently EUPHORIA already does this, at least for append. The >documentation says "highly optimized." > Built-in functions like append follow their own rules. If the user writes a function that modifies one of it's sequence parameters, the sequence is copied before modification. If the user wants the modification AND a return value, one or the other must be not passed to the function or they must be combined into a sequence (more copying!). A third reason to add PBR (and slicing shorthands) to Euphoria is to reduce redundancy: I have read (and written) too many code lines like: MOD1_base_elements = doit (MOD1_base_elements[2..MOD1_base_elements]) Much better without the redundancy: doit (!!MOD1_base_elements[2..]) >As for object orientation, as you said, something like: > stack.push( 9 ) >would have to be stack = stack.push( 9 ), unless ofcourse we have >stack=.push(9) for pass by reference like the other = ops. > >It may be pass by reference but we still only change things on the left >side of the "=". > Generally, the method dispatch 'stack.push(9)' gets handled as 'push(stack, 9)' i.e. the instance to operate on is passed as a a hidden parameter. Remember 'stack' here is an instance (maybe of class STACK?) NOT a class!'. In Euphoria this is: 1) stack=push(stack,9) -- push() can't return a value or: 2) push(stack,9) -- stack must at file scope, or unchanged We could make the rule that class methods can either return a value OR modify the instance but I would rather make it more general, especially when PBR brings other advantages. -------Phoenix-Boundary-07081998---