section as parameter for procedure

Anything that doesn't fit elsewhere.
Post Reply
pfortier

section as parameter for procedure

Post 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
   mysection=$o1
}
objref cell
cell = new celltemplate() // template contains soma and dend[99]
access cell.soma
testsection(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?
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: section as parameter for procedure

Post 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)
Example--
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.
pfortier

Re: section as parameter for procedure

Post 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.

Thanks
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: section as parameter for procedure

Post 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.
Post Reply