Re: Pass by Reference

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

I'm writing an application that has multiple digital filters. Calling the filter:

  • Calculates a filtered result, and
  • Updates the filter's history.

That is, two different things are being modified here - there's a result returned from the function call, and as a side-effect, a data structure gets updated.

Using the eumem.e library, one can emulate this less-than-safe programming practice. When using this library, you acquire a reference to some 'global' memory object and can pass that reference to routines.

include sys/eumem.e 
 
object aFilter = eumem:malloc({0,0}) -- Initialze new structure with a couple of zero values. 
 
 
function do_filter( object theFilter, atom theInput ) 
   atom theOutput = ram_space[theFilter][2] * ram_space[theFilter][1] * theInput 
   ram_space[theFilter][2] = ram_space[theFilter][1] 
   ram_space[theFilter][1] = theInput 
 
   return theOutput 
end function 
 
atom theResult = do_filter( aFilter, theInput ) 
dcuny said...

But it raises the question: why do I have to jump through these hoops at all? Why can't OpenEuphoria let me pass values by reference like just about any other language?

Because its more well behaved than other languages. smile

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

Search



Quick Links

User menu

Not signed in.

Misc Menu