Re: Euphoria v4.0; A couple of questions..

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

A routine is nested in another when it shares its private vars and operates within its context. That's how they work in Pascal anyway. You could write this:

procedure foo() 
integer n 
 
procedure bar() 
?n 
end procedure 
 
your_code_here() 
bar() 
end procedure 
end procedure 

Then you can share private vars of the main routine between various sub units. This is not pass by ref, obviously, but would work for some of its most frequent uses. You can do this with local vars just as well, leading to an inflation of variable names and accidental, improper reuse.

Note that tou don't always make a full copy of the sequence you pass and return, even though that's how the code looks. The backend is smarter. If there is only one reference on your sequence, ie it was not assigned anywhere else, then the backend does not copy and performs in place work, which is what you want to achieve. And if there are two references, in place processing would change some values behind the back of any variable that thought to know the value of your sequence. This is at best unsafe so better make a copy anyway.

Note that pass by ref means passing pointers. Sequence indexes are ids of fully managed pointers. If you can glob your data into a huge sequence and pass indexes into it to your processing routines, you have effectively got pass by ref, with most of the efficiency and more safety.

If you know C even superficially, you may want to look at Append() or similar in be_runtime.c, to see how copying sequences is avoided when it is safe to do so.

And if you want raw speed, you can store your data in RAM and call() machine code to process it. If you have a lot to do, he time overhead of call() will be more than offset.

Even though I would be very happy to help implementing pass by reference, have some old 2.5 code about it in my drawers and would use it a lot, there are some hairy technical issues. In particular, if using the multitasking primitives, how to handle private variables is currently quite straightforward - no one else will use them, so just save/restore them -, but having a reference to something into a sequence, and having it accessed by a different task between two runs of a task, would give some headaches.

CChris

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

Search



Quick Links

User menu

Not signed in.

Misc Menu