Page 1 of 1

section as parameter for procedure

Posted: Fri Jan 07, 2011 4:10 pm
by pfortier
I want to create a procedure that will do some tests on a section. Here is fake code (it does nothing meaningful) with the least code to highlight the problem.

Code: Select all

proc testsection() { localobj mysection
objref cell
cell = new celltemplate() // template contains soma and dend[99]
access cell.soma
This returns an error because I'm sending cell.soma as an object. I would need to send only cell for it to work but that defeats the purpose of having my testsection() procedure. I thought I could have testsection() represent $o1 as cell.soma and then use this to have:

$o1 { +code to adjust properties of section+ }
$o1.v(0.5) // access section range

Is there a way to do this? If not as 1 parameter, can I send cell and soma as 2 seperate parameters and then "paste" them together as in the dot referencing?

Re: section as parameter for procedure

Posted: Sat Jan 08, 2011 5:18 pm
by ted
It is seldom necessary to pass a section as an argument to a procedure. Instead use "secton stack syntax" like so:
secname procname(other args)
soma someproc()
The statements in someproc() will be executed with soma as the currently accessed section.

On those very rare occasions when it seems truly necessary to pass a section as an argument, stop first and think about it to make sure this is what you absolutely must do. Then if you really have to, use a SectionRef object.

Re: section as parameter for procedure

Posted: Mon Jan 10, 2011 6:46 pm
by pfortier
I now see that your response is directly derived from the documentation. Most clearly for SectionRef. I have been using "sectionname { stmt }" or else "sectionname stmt" format but it didn't click in my mind that I could use my own procedure as a stmt such as "sectionname testsection()". I have to reread the documentation more often.


Re: section as parameter for procedure

Posted: Mon Jan 10, 2011 11:38 pm
by ted
It is a common, and humbling, observation that all implications of any given part of the Programmer's Reference (or even a section in a tutorial or in the NEURON Book, for that matter) are not immediately evident on the Nth reading, where N in some cases may be surprisingly large.