Re: Pass by Reference

new topic     » goto parent     » topic index » view thread      » older message » newer message
Critic said...
ghaberek said...

I really think PBR could be optimized into passing an object to a function and assigning its result to that same object, like:

foo = func(foo) 

In practice, "foo" often is something more complex like "universe[x][y][z][t]":

universe[x][y][z][t] = func(universe[x][y][z][t]) 

Now you have to visually compare the left and right expressions and see if they are the same.

func(byref universe[x][y][z][t]) 

With this syntax it's clear something is modified too.

Unfortunately it might be clear when you are reading the function, but not when you are reading the call to the function.

Critic said...

This really is the same as universe[x][y][z][t] = universe[x][y][z][t] + 1 vs. universe[x][y][z][t] += 1.

Euphoria supports the += operator for a good reason IMHO.

IMO, the equivalent function call syntax would be something like

universe[x][y][z][t] = func($1) 

Where $1 means the first (or only) item being assigned on the LHS.

I believe PBR can be achieved by playing with reference counts. Consider the following code:

function notPBR(object x) 
    ... 
end function 
 
thing = notPBR(thing) 
 
object x 
procedure PBR() 
    ... 
end procedure 
x = thing 
thing = 0 
PBR() 
thing = x 
x = 0 

Clearly this is not an elegant way to actually code, but PBR() can modify x without COW overheads, whereas nonPBR() cannot. Perhaps you may need to write an example based on the above to prove the performance difference.

Then you need to think about how to get the compiler to safely mimic this code from some much simpler shorthand syntax, in particular allow a variable to be passed as a parameter and cleared or not ref-counted in one step.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu