Hi,
I am trying to define a procedure in a hoc file that will take as a parameter section names. E.g. If I have a soma and an axon section I would like to have something like that:
foo() {
$1.L=10
...
}
foo(soma)
Is there a way to do that? I tried to do the above implementation, but the compiler returned errors.
Thanks
Passing strings as parameters in proc()
-
- Site Admin
- Posts: 6384
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Yes, but first ask whether that's really the best way to solve the larger
problem. It is difficult to imagine a circumstance in which passing section
names as strings would be the best solution for a problem.
If you only need to execute statements in the context of a section, then
is preferable. Example:
If you need to pass more than one section to a proc, use either a
SectionList or use SectionRefs, then pass the SectionList or SectionRefs.
If you absolutely _must_ pass a section name as a string, use sprint()
within the proc to create a command string, then use execute() to
execute the command. Example:
But I bet you a nickel that one of the three other approaches is far
superior to this.
problem. It is difficult to imagine a circumstance in which passing section
names as strings would be the best solution for a problem.
If you only need to execute statements in the context of a section, then
Code: Select all
proc foo() {
stmt1
stmt2
. . .
}
secname foo(arg1, arg2 . . .)
Code: Select all
proc setgeom() {
L = $1
diam = $2
nseg = $3
}
print "Before calling setgeom"
soma psection()
soma setgeom(1000, 1, 25)
print "After calling setgeom"
soma psection()
SectionList or use SectionRefs, then pass the SectionList or SectionRefs.
If you absolutely _must_ pass a section name as a string, use sprint()
within the proc to create a command string, then use execute() to
execute the command. Example:
Code: Select all
strdef cmdstr
proc setnseg() { // but why bother??
sprint(cmdstr,"%s nseg = %d", $s1, $2)
execute(cmdstr)
}
setnseg("soma", 5)
superior to this.